|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | LogMembufData |
Typedefs | |
| typedef struct LogMembufData | LogMembufData |
Functions | |
| LogDest * | logmembufRegister (int maxlevel, strref chanfilter, uint32 size, LogSerializer *ser) |
| LogMembufData * | logmembufData (LogDest *dest) |
| LogMembufData * | logmembufCreate (uint32 size, LogSerializer *ser) |
| void | logmembufMsgFunc (const LogRecord *rec, void *userdata) |
| void | logmembufCloseFunc (void *userdata) |
Memory buffer logging destination that writes log messages to a fixed-size circular buffer in memory. Useful for debugging, testing, and capturing logs in memory-constrained environments. When the buffer fills, new messages wrap around and overwrite the oldest entries.
Basic Usage:
| typedef struct LogMembufData LogMembufData |
Memory buffer log destination state
Contains the circular buffer and current write position. When cur reaches size, new messages wrap to the beginning. The buffer is null-terminated when possible.
| void logmembufCloseFunc | ( | void * | userdata | ) |
Cleanup callback for memory buffer destinations
Frees the buffer and releases resources.
| userdata | LogMembufData pointer from logmembufCreate() |
| LogMembufData * logmembufCreate | ( | uint32 | size, |
| LogSerializer * | ser | ||
| ) |
Create a memory buffer log destination
Only needed to register the buffer by hand with logRegisterDest() – logmembufRegister() does this and the registration together. The returned handle belongs to exactly one destination: it is freed by logmembufCloseFunc() and cannot be registered twice.
| size | Buffer size in bytes |
| ser | Serializer to render records with; ownership transfers. NULL gets a compact text serializer: short levels, bracketed channels, second-resolution timestamps. |
| LogMembufData * logmembufData | ( | LogDest * | dest | ) |
Get the buffer behind a memory buffer destination
The returned struct is owned by the destination and lives exactly as long as it does: logUnregisterDest() frees the buffer, so nothing may read it afterwards.
Reading cur races with the drain thread, which may be appending while this runs. Read it once into a local and use that for both the length and any copy – reading it twice lets it grow in between.
| dest | Destination handle from logmembufRegister() |
| void logmembufMsgFunc | ( | const LogRecord * | rec, |
| void * | userdata | ||
| ) |
Log message callback for memory buffer destinations
Serializes a log record and appends it to the circular buffer, newline-terminated.
| rec | Log record to write |
| userdata | LogMembufData pointer from logmembufCreate() |
| LogDest * logmembufRegister | ( | int | maxlevel, |
| strref | chanfilter, | ||
| uint32 | size, | ||
| LogSerializer * | ser | ||
| ) |
Register a memory buffer log destination
Allocates a fixed-size circular buffer and registers it with the logging system in one step. Records are serialized and written to the buffer; messages longer than the buffer size are dropped, and when the buffer fills, writing wraps back to the beginning. The buffer is freed when logUnregisterDest() retires the returned handle.
Use logmembufData() to reach the buffer contents.
| maxlevel | Maximum log level to write to the buffer |
| chanfilter | Channel path pattern, or NULL for every unrestricted channel |
| size | Buffer size in bytes |
| ser | Serializer to render records with; ownership transfers, including if this call fails. NULL gets a compact text serializer: short levels, bracketed channels, second-resolution timestamps. |