Logging utilities.
More...
|
#define | CSNIP_LOG_PRIO_DEBUGV 0 |
| Verbose debugging priority. More...
|
|
#define | CSNIP_LOG_PRIO_DEBUG 10 |
| Debugging priority. More...
|
|
#define | CSNIP_LOG_PRIO_INFO 20 |
| Informational priority.
|
|
#define | CSNIP_LOG_PRIO_NOTICE 30 |
| Notice.
|
|
#define | CSNIP_LOG_PRIO_WARN 40 |
| Warnings.
|
|
#define | CSNIP_LOG_PRIO_ERR 50 |
| Errors.
|
|
#define | CSNIP_LOG_PRIO_MIN 0 |
| Minimum compiled-in prioriy. More...
|
|
#define | csnip_log_Mesg(prio, ...) csnip_log_MesgForComp(CSNIP_LOG_COMPONENT, prio, __VA_ARGS__) |
| Log a message. More...
|
|
#define | csnip_log_MesgForComp(comp, prio, ...) |
| Log a message for a specified component. More...
|
|
#define | csnip_log_Perror(prio, ...) csnip_log_PerrorForComp(CSNIP_LOG_COMPONENT, prio, __VA_ARGS__) |
| Log an errno error. More...
|
|
#define | csnip_log_PerrorForComp(comp, prio, ...) |
| Log an errno error for a specified component. More...
|
|
This library provides a simple interface for logging. Each log message is associated a priority as well as with context including the source file name and line number, but in particular a component name. The component name is the expansion of the macro CSNIP_LOG_COMPONENT where csnip_log_Mesg() is expanded.
Log output can be filtered based on priority and regular expressions matching the component name, see csnip_log_config0() for details.
◆ csnip_log_Mesg
Logs a message; this requires the CSNIP_LOG_COMPONENT macro to be defined. The CSNIP_LOG_PRIO_MIN macro can be used to filter out lower priority messages at compile time for performance reasons.
See the documentation of csnip_log_config0() on what messages are printed by default and how the logger can be configured.
The CSNIP_LOG_COMPONENT must be a string with static lifetime, ideally a string literal.
- Parameters
-
prio | logging priority. |
... | printf-style format and arguments. |
◆ csnip_log_MesgForComp
#define csnip_log_MesgForComp |
( |
|
comp, |
|
|
|
prio, |
|
|
|
... |
|
) |
| |
Variant of csnip_log_Mesg() with the logging component specified as an argument. Does not require CSNIP_LOG_COMPONENT to be defined.
- Parameters
-
comp | the component, must be a string literal. |
prio | logging priority. |
... | printf-style format and arguments. |
◆ csnip_log_Perror
This is the logging module's variant of perror(3). It prints the log message as given here, and then, separated by a colon, the error message corresponding to the errno value.
- Parameters
-
prio | loggin priority. |
... | printf-style format and arguments. |
◆ csnip_log_PerrorForComp
#define csnip_log_PerrorForComp |
( |
|
comp, |
|
|
|
prio, |
|
|
|
... |
|
) |
| |
Variant of csnip_log_Perror() with the logging component specified as an argument. Does not require CSNIP_LOG_COMPONENT to be defined.
- Parameters
-
comp | the component, must be a string literal. |
prio | loggin priority. |
... | printf-style format and arguments. |
◆ CSNIP_LOG_PRIO_DEBUG
#define CSNIP_LOG_PRIO_DEBUG 10 |
These debug levels are suitable for general messages useful when debugging.
◆ CSNIP_LOG_PRIO_DEBUGV
#define CSNIP_LOG_PRIO_DEBUGV 0 |
DEBUGV can be very detailed; possibly too detailed to run entire programs or larger modules with this debug level.
◆ CSNIP_LOG_PRIO_MIN
#define CSNIP_LOG_PRIO_MIN 0 |
This macro is only defined if not already predefined; the intent is the user can set it as desired.
Log messages with lower priorities will not be compiled in. Compiler optimizations, if enabled, will typically cause the string constants such as the components and file names, as well as the log message itself to be absent from binaries in those cases.
◆ csnip_log_config0()
void csnip_log_config0 |
( |
const char * |
filters_expr, |
|
|
FILE * |
log_out |
|
) |
| |
By default all messages of priority CSNIP_LOG_PRIO_NOTICE or higher will be logged. This function provides a simple interface to configure the logger.
- Parameters
-
filters_expr | Filter expressions string. The string is colon-separated string of expressions of the form RE~PRIO, where RE is a POSIX extended regular expression that is matched against the component string, and PRIO minimum priority value for a message to be printed. If a message satisfies any of the filter expression constraints, it will be printed. If RE is omitted, all messages are matched, if ~PRIO or PRIO is omitted, the priority is taken to be CSNIP_LOG_PRIO_NOTICE . If filter_expr is NULL, messages of priorities at least the notice priority will be printed. |
log_out | output file. |