Oakfield API Documentation 1.0.0
Numerical core APIs
Loading...
Searching...
No Matches
async_logger.h File Reference

Lock-free asynchronous logging facilities for libsimcore runtime. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "field.h"
Include dependency graph for async_logger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SimAsyncLogRecord
 Log entry materialized when records are drained from the ring buffer. More...
 
struct  SimAsyncLogger
 Lock-free ring buffer logger supporting multiple producers and a single consumer. More...
 

Macros

#define SIM_ASYNC_LOGGER_MESSAGE_MAX   255U
 

Typedefs

typedef enum SimLogLevel SimLogLevel
 Severity levels emitted by the asynchronous logger.
 
typedef struct SimAsyncLogRecord SimAsyncLogRecord
 Log entry materialized when records are drained from the ring buffer.
 
typedef struct SimAsyncLogger SimAsyncLogger
 Lock-free ring buffer logger supporting multiple producers and a single consumer.
 

Enumerations

enum  SimLogLevel {
  SIM_LOG_LEVEL_TRACE = 0 , SIM_LOG_LEVEL_DEBUG , SIM_LOG_LEVEL_INFO , SIM_LOG_LEVEL_WARN ,
  SIM_LOG_LEVEL_ERROR , SIM_LOG_LEVEL_FATAL
}
 Severity levels emitted by the asynchronous logger. More...
 

Functions

SimResult sim_async_logger_init (SimAsyncLogger *logger, size_t capacity)
 Initialize the asynchronous logger with a ring buffer of at least capacity elements.
 
void sim_async_logger_destroy (SimAsyncLogger *logger)
 Destroy an asynchronous logger instance and release its storage.
 
SimResult sim_async_logger_log (SimAsyncLogger *logger, SimLogLevel level, const char *message)
 Attempt to append a log record without blocking.
 
bool sim_async_logger_pop (SimAsyncLogger *logger, SimAsyncLogRecord *out_record)
 Drain the next pending log record.
 
void sim_async_logger_clear (SimAsyncLogger *logger)
 Clear all pending log entries without releasing internal storage.
 

Detailed Description

Lock-free asynchronous logging facilities for libsimcore runtime.

Macro Definition Documentation

◆ SIM_ASYNC_LOGGER_MESSAGE_MAX

#define SIM_ASYNC_LOGGER_MESSAGE_MAX   255U

Maximum length, in bytes, of a log message (excluding the null terminator).

Enumeration Type Documentation

◆ SimLogLevel

Severity levels emitted by the asynchronous logger.

Enumerator
SIM_LOG_LEVEL_TRACE 

Verbose diagnostic information.

SIM_LOG_LEVEL_DEBUG 

Debug-level information.

SIM_LOG_LEVEL_INFO 

Informational message.

SIM_LOG_LEVEL_WARN 

Warning that does not halt execution.

SIM_LOG_LEVEL_ERROR 

Recoverable error.

SIM_LOG_LEVEL_FATAL 

Fatal error after which the system cannot continue.

Function Documentation

◆ sim_async_logger_clear()

void sim_async_logger_clear ( SimAsyncLogger logger)

Clear all pending log entries without releasing internal storage.

Parameters
loggerLogger instance.

◆ sim_async_logger_destroy()

void sim_async_logger_destroy ( SimAsyncLogger logger)

Destroy an asynchronous logger instance and release its storage.

Parameters
loggerLogger to destroy; may be NULL.

◆ sim_async_logger_init()

SimResult sim_async_logger_init ( SimAsyncLogger logger,
size_t  capacity 
)

Initialize the asynchronous logger with a ring buffer of at least capacity elements.

Parameters
[out]loggerLogger instance to initialize.
capacityRequested capacity; rounded up to the next power of two (minimum 64).
Returns
SIM_RESULT_OK on success or an error code on failure.

◆ sim_async_logger_log()

SimResult sim_async_logger_log ( SimAsyncLogger logger,
SimLogLevel  level,
const char *  message 
)

Attempt to append a log record without blocking.

When the ring buffer is full older messages are overwritten.

Parameters
loggerLogger instance.
levelMessage severity.
messageNull-terminated string to append.
Returns
SIM_RESULT_OK on success or an error code if the record could not be written.

◆ sim_async_logger_pop()

bool sim_async_logger_pop ( SimAsyncLogger logger,
SimAsyncLogRecord out_record 
)

Drain the next pending log record.

Parameters
loggerLogger instance.
[out]out_recordDestination for the oldest pending record.
Returns
true when a record was produced, false if no messages were available.