CMX logging functions. More...
#include <stdio.h>
#include <stdarg.h>
Logging macros | |
Logging Compile-time configuration:
| |
#define | _LOG_LOG(level,...) cmx_log_printf(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) |
internal log macro | |
#define | LOG_AUDIT_IF(...) _LOG_LOG(LOG_LEVEL_AUDIT, __VA_ARGS__) |
Audit Log entry. | |
#define | LOG_ERROR_IF(...) _LOG_LOG(LOG_LEVEL_ERROR, __VA_ARGS__) |
Error Log entry. | |
#define | LOG_WARN_IF(...) _LOG_LOG(LOG_LEVEL_WARN, __VA_ARGS__) |
Warn Log entry. | |
#define | LOG_INFO_IF(...) _LOG_LOG(LOG_LEVEL_INFO, __VA_ARGS__) |
Info Log entry. | |
#define | LOG_DEBUG_IF(...) _LOG_LOG(LOG_LEVEL_DEBUG, __VA_ARGS__) |
Debug Log entry. | |
#define | LOG_TRACE_IF(...) _LOG_LOG(LOG_LEVEL_TRACE, __VA_ARGS__) |
Trace Log entry. | |
enum | log_levels { LOG_LEVEL_AUDIT = 0, LOG_LEVEL_ERROR = 1, LOG_LEVEL_WARN = 2, LOG_LEVEL_INFO = 3, LOG_LEVEL_DEBUG = 4, LOG_LEVEL_TRACE = 5 } |
Enumeration of all valid logging levels. More... | |
typedef void(* | cmx_log_adapter_t )(enum log_levels, const char *, int, const char *, const char *, va_list) |
Type of a log adapter function. | |
void | cmx_log_set_adapter (cmx_log_adapter_t log_adapter_func) |
Set a external logging function. | |
Logging control functions | |
| |
#define | LOG_SET_LEVEL(l) |
Change log level for a code-block. | |
int | cmx_log_current_level |
the current logging level. | |
enum log_levels | cmx_log_level_from_env () |
Read the log_level from environment variable LOG_LEVEL. | |
enum log_levels | cmx_log_from_string (const char *level) |
Parse a string to log-level. | |
const char * | cmx_log_level_name (enum log_levels level) |
convert a log level to string like "INFO". | |
void | cmx_log_vprintf (enum log_levels level, const char *file, const int line, const char *function, const char *fmt, va_list ap) |
Logging implementation. | |
void | cmx_log_printf (enum log_levels level, const char *file, const int line, const char *function, const char *fmt,...) __attribute__((format(printf |
redirects to cmx_log_vprintf() |
CMX logging functions.
#define LOG_SET_LEVEL | ( | l | ) |
for (int _loop=1, _old_log_level = cmx_log_current_level; \ _loop == 1 && ((cmx_log_current_level = l) || 1) ; \ cmx_log_current_level = _old_log_level, _loop=0)
Change log level for a code-block.
This macro changes the logging level for the following code-block and restores the previous logging level afterwards.
The newly introduced local variables _loop and _old_log_level must remain unmodified by the caller.
typedef void(* cmx_log_adapter_t)(enum log_levels, const char *, int, const char *, const char *, va_list) |
Type of a log adapter function.
The internal stdout-logger can be replaced with a function of this type.
enum log_levels |
Enumeration of all valid logging levels.
LOG_LEVEL_AUDIT |
highest logging level |
LOG_LEVEL_ERROR |
|
LOG_LEVEL_WARN |
|
LOG_LEVEL_INFO |
|
LOG_LEVEL_DEBUG |
|
LOG_LEVEL_TRACE |
lowest, most detailed logging level |
enum log_levels cmx_log_from_string | ( | const char * | level | ) |
Parse a string to log-level.
On parse error: return default log-level INFO.
enum log_levels cmx_log_level_from_env | ( | ) |
Read the log_level from environment variable LOG_LEVEL.
const char* cmx_log_level_name | ( | enum log_levels | level | ) |
convert a log level to string like "INFO".
A unknown log level is returned as empty string.
void cmx_log_set_adapter | ( | cmx_log_adapter_t | log_adapter_func | ) |
Set a external logging function.
The type of the function is defined as cmx_log_adapter_t.
void cmx_log_vprintf | ( | enum log_levels | level, | |
const char * | file, | |||
const int | line, | |||
const char * | function, | |||
const char * | fmt, | |||
va_list | ap | |||
) |
Logging implementation.
If a logadapter is set all logging is dispatched to the log_adapter function. If not a logging message is printed to stdout if cmx_log_current_level >= 'level'.
the current logging level.
This variable can but should usually not be manipulated directly. The valid values are defined in log_levels.