|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | LogFileConfig |
Typedefs | |
| typedef struct LogFileConfig | LogFileConfig |
| typedef struct LogFileData | LogFileData |
| Opaque handle for file logging state. | |
Enumerations | |
| enum | LOG_DATE_FORMATS { LOG_DateISO , LOG_DateISOCompact , LOG_DateNCSA , LOG_DateSyslog , LOG_DateISOCompactMsec } |
| Timestamp format options for log file output. More... | |
| enum | LOG_FLAGS { LOG_LocalTime = 0x0001 , LOG_OmitLevel = 0x0002 , LOG_ShortLevel = 0x0004 , LOG_BracketLevel = 0x0008 , LOG_JustifyLevel = 0x0010 , LOG_IncludeCategory = 0x0020 , LOG_BracketCategory = 0x0040 , LOG_AddColon = 0x0080 , LOG_CategoryFirst = 0x0100 } |
| Formatting flags for log file output. More... | |
| enum | LOG_ROTATE_MODE { LOG_RotateSize = 1 , LOG_RotateTime } |
| Log rotation mode. More... | |
Functions | |
| LogFileData * | logfileCreate (VFS *vfs, strref filename, LogFileConfig *config) |
| LogDest * | logfileRegister (int maxlevel, LogCategory *catfilter, LogFileData *logfile) |
| LogDest * | logfileRegisterWithDefer (int maxlevel, LogCategory *catfilter, LogFileData *logfile, LogDest *deferdest) |
| void | logfileMsgFunc (int level, LogCategory *cat, int64 timestamp, strref msg, uint32 batchid, void *userdata) |
| void | logfileBatchFunc (uint32 batchid, void *userdata) |
| void | logfileCloseFunc (void *userdata) |
File-based logging destination with support for automatic log rotation, flexible formatting, and customizable output options. Files can be rotated based on size or time, with configurable retention policies.
Basic Usage:
| typedef struct LogFileConfig LogFileConfig |
Configuration for file-based logging
Controls output formatting, rotation behavior, and retention policies.
| enum LOG_DATE_FORMATS |
Timestamp format options for log file output.
| enum LOG_FLAGS |
Formatting flags for log file output.
| enum LOG_ROTATE_MODE |
| void logfileBatchFunc | ( | uint32 | batchid, |
| void * | userdata | ||
| ) |
Batch completion callback for file destinations
Flushes the file buffer to ensure batch messages are written together.
| batchid | Completed batch identifier |
| userdata | LogFileData pointer from logfileCreate() |
| void logfileCloseFunc | ( | void * | userdata | ) |
Cleanup callback for file destinations
Closes the log file and releases resources.
| userdata | LogFileData pointer from logfileCreate() |
| LogFileData * logfileCreate | ( | VFS * | vfs, |
| strref | filename, | ||
| LogFileConfig * | config | ||
| ) |
Create a file logging destination
Initializes a file-based log destination with the specified configuration. The file is opened immediately and created if it doesn't exist. If rotation is enabled, existing rotated log files are scanned to enforce retention policies.
| vfs | Virtual filesystem to use for file operations |
| filename | Path to the log file |
| config | Logging configuration (copied, caller retains ownership) |
| void logfileMsgFunc | ( | int | level, |
| LogCategory * | cat, | ||
| int64 | timestamp, | ||
| strref | msg, | ||
| uint32 | batchid, | ||
| void * | userdata | ||
| ) |
Log message callback for file destinations
Formats and writes a log message to the file. Checks for rotation after each write.
| level | Log severity level |
| cat | Category, or NULL for default |
| timestamp | Wall clock timestamp |
| msg | Log message text |
| batchid | Batch identifier for grouping |
| userdata | LogFileData pointer from logfileCreate() |
| LogDest * logfileRegister | ( | int | maxlevel, |
| LogCategory * | catfilter, | ||
| LogFileData * | logfile | ||
| ) |
Register a file destination with the logging system
Registers the file as a log destination. Messages will be formatted according to the configuration and written to the file. The file destination will be automatically cleaned up when unregistered.
| maxlevel | Maximum log level to write to file |
| catfilter | Category filter, or NULL for all non-private categories |
| logfile | File logging handle from logfileCreate() |
| LogDest * logfileRegisterWithDefer | ( | int | maxlevel, |
| LogCategory * | catfilter, | ||
| LogFileData * | logfile, | ||
| LogDest * | deferdest | ||
| ) |
Register a file destination and flush deferred logs
Atomically registers a file destination while flushing previously deferred logs to it. This ensures all logs from application startup are captured even if the log file couldn't be opened immediately.
| maxlevel | Maximum log level to write to file |
| catfilter | Category filter, or NULL for all non-private categories |
| logfile | File logging handle from logfileCreate() |
| deferdest | Deferred destination to flush (destroyed during this call) |