|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | LogConsoleConfig |
Typedefs | |
| typedef struct LogConsoleConfig | LogConsoleConfig |
| typedef struct LogConsoleData | LogConsoleData |
| Opaque handle for console logging state. | |
Enumerations | |
| enum | LOGCON_COLOR_MODE { LOGCON_ColorAuto = 0 , LOGCON_ColorOn , LOGCON_ColorOff } |
| Color decision for a console destination. More... | |
Functions | |
| LogDest * | logconsoleRegister (int maxlevel, strref chanfilter, ConStream *out, ConStream *err, const LogConsoleConfig *config, LogSerializer *ser) |
| LogConsoleData * | logconsoleCreate (ConStream *out, ConStream *err, const LogConsoleConfig *config, LogSerializer *ser) |
| void | logconsoleMsgFunc (const LogRecord *rec, void *userdata) |
| void | logconsoleBatchFunc (uint32 batchid, void *userdata) |
| void | logconsoleCloseFunc (void *userdata) |
Console-based logging destination that writes formatted, level-colored log lines to conOut()/conErr() (see Console).
The console is a transport and takes a serializer like any other (see Log Serializers), so a line looks the same whether it ends up in a file or on a terminal. What the console destination adds is routing between stdout/stderr by severity and a per-level ConStyle, both automatically downgraded (or dropped entirely) by the destination stream's own capabilities – a line sent to a redirected-to-a-file stdout gets no escape codes even though the identical line to a real terminal would be colored.
Basic Usage:
| typedef struct LogConsoleConfig LogConsoleConfig |
Configuration for console-based logging
Controls stdout/stderr routing and per-level coloring. Output formatting belongs to the serializer the console is created with, not here.
| enum LOGCON_COLOR_MODE |
Color decision for a console destination.
| Enumerator | |
|---|---|
| LOGCON_ColorAuto | Style only when the destination stream reports color support. |
| LOGCON_ColorOn | Always apply per-level style, letting ConStyle's own downgrade ladder decide what the stream can actually render |
| LOGCON_ColorOff | Never apply style; plain text only. |
Definition at line 49 of file logconsole.h.
| void logconsoleBatchFunc | ( | uint32 | batchid, |
| void * | userdata | ||
| ) |
Batch completion callback for console destinations
Flushes both conOut() and conErr() so batch messages reach the terminal together.
| batchid | Completed batch identifier |
| userdata | LogConsoleData pointer from logconsoleCreate() |
| void logconsoleCloseFunc | ( | void * | userdata | ) |
Cleanup callback for console destinations
Releases the console logging handle. Never closes conOut()/conErr() themselves – they are process singletons.
| userdata | LogConsoleData pointer from logconsoleCreate() |
| LogConsoleData * logconsoleCreate | ( | ConStream * | out, |
| ConStream * | err, | ||
| const LogConsoleConfig * | config, | ||
| LogSerializer * | ser | ||
| ) |
Create a console logging destination
Only needed to register the console by hand with logRegisterDest() – logconsoleRegister() does this and the registration together. The returned handle belongs to exactly one destination: it is freed by logconsoleCloseFunc() and cannot be registered twice.
| out | Stream for messages less severe than stderrLevel; NULL uses conOut(). Not acquired or owned – must outlive the returned handle. |
| err | Stream for messages at or more severe than stderrLevel; NULL uses conErr(). Not acquired or owned – must outlive the returned handle. |
| config | Console configuration (copied, caller retains ownership) |
| ser | Serializer to render records with; ownership transfers. NULL gets a default text serializer. |
| void logconsoleMsgFunc | ( | const LogRecord * | rec, |
| void * | userdata | ||
| ) |
Log message callback for console destinations
Renders a log record and writes it to conOut() or conErr(), styled per level according to the destination's configuration and the destination stream's capabilities.
| rec | Log record to write |
| userdata | LogConsoleData pointer from logconsoleCreate() |
| LogDest * logconsoleRegister | ( | int | maxlevel, |
| strref | chanfilter, | ||
| ConStream * | out, | ||
| ConStream * | err, | ||
| const LogConsoleConfig * | config, | ||
| LogSerializer * | ser | ||
| ) |
Register a console logging destination
Builds the console destination and registers it with the logging system in one step. It is closed and released when logUnregisterDest() retires the returned handle.
| maxlevel | Maximum log level to write to the console |
| chanfilter | Channel path pattern, or NULL for every unrestricted channel |
| out | Stream for messages less severe than stderrLevel; NULL uses conOut(). Not acquired or owned – must outlive the destination. |
| err | Stream for messages at or more severe than stderrLevel; NULL uses conErr(). Not acquired or owned – must outlive the destination. |
| config | Console configuration (copied, caller retains ownership) |
| ser | Serializer to render records with; ownership transfers, including if this call fails. NULL gets a default text serializer. |