dteventlogger
Fixed-size event logging with timestamped items.
This group of functions provides fixed-size event logging for in-memory event streams. It is intended for lightweight diagnostics and inspection in embedded or low-level runtime contexts. It is designed to . The implementation accumulates recent events without dynamic growth resulting in deterministic memory usage.
Mini-guide
- Initialize the logger with a fixed item size and count.
- Append events sequentially, overflow will overwrite the oldest entries.
- Clone the logger state for inspection by isolating concurrent writes.
Example
dteventlogger_t logger;
dteventlogger_item1_t item;
dteventlogger_init(&logger, 16, sizeof(item));
item.timestamp = 1000;
item.value1 = 42;
item.value2 = 7;
dteventlogger_append(&logger, &item);
dteventlogger_log_item1("APP", &logger, "events", "v1", "v2");
dteventlogger_dispose(&logger);
Data structures
dteventlogger_item0_t
Represents a minimal event item containing only a timestamp.
Members:
uint64_t timestampTimestamp of the event.
dteventlogger_item1_t
Represents an event item with a timestamp and two associated values.
Members:
uint64_t timestampTimestamp of the event.
int32_t value1First value associated with the event.
int32_t value2Second value associated with the event.
dteventlogger_t
Tracks the state of a fixed-size event logger and its backing buffer.
Members:
int32_t item_countMaximum number of items retained.
int32_t item_lengthSize in bytes of each item.
uint32_t buffer_sizeSize of the backing buffer in bytes.
dtbuffer_t* bufferBuffer that holds the raw event data.
volatile uint32_t write_indexMonotonic index of the next write position.
Functions
dteventlogger_append
Appends a single item to the logger buffer.
Params:
dteventlogger_t* selfEvent logger instance.
const void* itemPointer to the item data to append.
Return: dterr_t* Error object on failure, otherwise NULL.
dteventlogger_clone
Creates a snapshot copy of the logger state and buffer.
Params:
dteventlogger_t* selfSource event logger instance.
dteventlogger_t* cloneDestination logger to initialize and populate.
Return: dterr_t* Error object on failure, otherwise NULL.
dteventlogger_dispose
Releases resources associated with the logger.
Params:
dteventlogger_t* selfEvent logger instance.
Return: void No return value.
dteventlogger_get_item
Retrieves an item by index from the logger buffer.
Params:
dteventlogger_t* selfEvent logger instance.
int32_t indexZero-based index relative to the oldest retained item.
void** itemOutput pointer to the item data or NULL.
Return: dterr_t* Error object on failure, otherwise NULL.
dteventlogger_init
Initializes an event logger with fixed item sizing.
Params:
dteventlogger_t* selfEvent logger instance to initialize.
int32_t item_countNumber of items to retain.
int32_t item_lengthSize in bytes of each item.
Return: dterr_t* Error object on failure, otherwise NULL.
dteventlogger_log_item1
Logs formatted item1 events using the logging facility.
Params:
const char* tagLogging tag to associate with the output.
dteventlogger_t* eventloggerEvent logger instance.
const char* logger_labelLabel for the logger output.
const char* value1_labelLabel for the first value column.
const char* value2_labelLabel for the second value column.
Return: dterr_t* Error object on failure, otherwise NULL.
dteventlogger_printf_item1
Formats item1 events into a newly allocated string.
Params:
dteventlogger_t* eventloggerEvent logger instance.
const char* logger_labelLabel for the logger output.
const char* value1_labelLabel for the first value column.
const char* value2_labelLabel for the second value column.
char** out_stringOutput pointer receiving the allocated string.
Return: dterr_t* Error object on failure, otherwise NULL.