Webcom C SDK
|
Macros | |
#define | W_LOG(_facility, _level, _fmt, ...) |
#define | WL_LOG(_level, _fmt, ...) W_LOG(LOCAL_LOG_FACILITY, (_level), _fmt, ## __VA_ARGS__) |
#define | APP_LOG(_level, _fmt, ...) W_LOG(WC_LOG_APPLICATION, (_level), _fmt, ## __VA_ARGS__) |
Typedefs | |
typedef void(* | wc_log_f) (const char *f, const char *l, const char *file, const char *func, int line, const char *message) |
Functions | |
void | wc_set_log_level (enum wc_log_facility f, enum wc_log_level l) |
void | wc_log_use_syslog (const char *ident, int option, int facility) |
void | wc_log_use_journald (void) |
void | wc_log_use_stderr (void) |
void | wc_log_use_custom (wc_log_f f) |
void | wc_log (enum wc_log_facility f, enum wc_log_level l, const char *file, const char *func, int line, const char *fmt,...) __attribute__((format(printf |
#define APP_LOG | ( | _level, | |
_fmt, | |||
... | |||
) | W_LOG(WC_LOG_APPLICATION, (_level), _fmt, ## __VA_ARGS__) |
Logs a formatted message in the application's facility
This macro should be used by the application code using the SDK. All messages written with this macro will be routed to the WC_LOG_APPLICATION facility.
APP_EXDBG(_fmt, ...)
APP_DBG(_fmt, ...)
APP_INFO(_fmt, ...)
APP_NOT(_fmt, ...)
APP_WARN(_fmt, ...)
APP_ERR(_fmt, ...)
APP_CRIT(_fmt, ...)
APP_ALRT(_fmt, ...)
APP_EMRG(_fmt, ...)
_level | the log level |
_fmt | a literal format string (a newline will automatically be appended), the following arguments are the format string arguments |
#define W_LOG | ( | _facility, | |
_level, | |||
_fmt, | |||
... | |||
) |
Logs a formatted message
This macro sends a message to the previously chosen log backend, and automatically sets the source file, line and function to the local value.
W_EXDBG(_facility, _fmt, ...)
W_DBG(_facility, _fmt, ...)
W_INFO(_facility, _fmt, ...)
W_NOT(_facility, _fmt, ...)
W_WARN(_facility, _fmt, ...)
W_ERR(_facility, _fmt, ...)
W_CRIT(_facility, _fmt, ...)
W_ALRT(_facility, _fmt, ...)
W_EMRG(_facility, _fmt, ...)
_facility | the facility |
_level | the log level |
_fmt | a literal format string (a newline will automatically be appended), the following arguments are the format string arguments |
#define WL_LOG | ( | _level, | |
_fmt, | |||
... | |||
) | W_LOG(LOCAL_LOG_FACILITY, (_level), _fmt, ## __VA_ARGS__) |
Logs a formatted message in the local facility
Helper macro to avoid manually mentioning the log facility in a compilation unit, useful if almost every log message in this unit goes to the same faciliy.
You must define the LOCAL_LOG_FACILITY macro to the desired enum wc_log_facility value before including webcom-log.h to set the local facility, otherwise WC_LOG_GENERAL will be used.
Example:
WL_EXDBG(_fmt, ...)
WL_DBG(_fmt, ...)
WL_INFO(_fmt, ...)
WL_NOT(_fmt, ...)
WL_WARN(_fmt, ...)
WL_ERR(_fmt, ...)
WL_CRIT(_fmt, ...)
WL_ALRT(_fmt, ...)
WL_EMRG(_fmt, ...)
_level | the log level |
_fmt | a literal format string (a newline will automatically be appended), the following arguments are the format string arguments |
typedef void(* wc_log_f) (const char *f, const char *l, const char *file, const char *func, int line, const char *message) |
enum wc_log_facility |
The SDK defines several facilities ("channels") in which logs can be written. This enum allows to specify to which facility a log message is targeted.
enum wc_log_level |
This emum defines the different possible priorities for a log message. They mimic those found in syslog.h, plus two other special values
Enumerator | |
---|---|
WC_LOG_EMERG | see syslog.h's LOG_EMERG |
WC_LOG_ALERT | see syslog.h's LOG_ALERT |
WC_LOG_CRIT | see syslog.h's LOG_CRIT |
WC_LOG_ERR | see syslog.h's LOG_ERR |
WC_LOG_WARNING | see syslog.h's LOG_WARNING |
WC_LOG_NOTICE | see syslog.h's LOG_NOTICE |
WC_LOG_INFO | see syslog.h's LOG_INFO |
WC_LOG_DEBUG | see syslog.h's LOG_DEBUG |
WC_LOG_EXTRADEBUG | this extra debug level is for those extremely verbose and frequent messages that tend to make the logs almost unreadable |
WC_LOG_DISABLED | use this priority in wc_set_log_level() to completely disable logging in a facility |
void wc_log | ( | enum wc_log_facility | f, |
enum wc_log_level | l, | ||
const char * | file, | ||
const char * | func, | ||
int | line, | ||
const char * | fmt, | ||
... | |||
) |
Send a formatted message to the log backend
This function sends a message to the previously chosen log backend (default stderror). It is not meant to be used directly, but through the various W_LOG() macros and its derivatives, that automatically populates the source file, line and function arguments.
f | the facility |
l | the log level |
file | the source code file name this log comes from |
func | the function name |
line | the line number in the source file |
fmt | a printf-like format string for the log message, the following arguments are the format string arguments |
void wc_log_use_custom | ( | wc_log_f | f | ) |
Use a custom C function as log backend
f | the custom log function |
void wc_log_use_journald | ( | void | ) |
Use journald as the log backend
After calling this functions, every log message produces by the SDK will be sent to journald using the native journald interface. The journal entries will have some additional custom properties set, when the log macros are being used, to help with filtering and diagnostic:
void wc_log_use_stderr | ( | void | ) |
Use stderror as the log backend (default)
void wc_log_use_syslog | ( | const char * | ident, |
int | option, | ||
int | facility | ||
) |
Use syslog as the log backend
After calling this functions, every log message produces by the SDK will be sent to syslog. The parameters are the same as those from openlog(3).
man 3 openlog
. ident | The string pointed to by ident is prepended to every message, and is typically set to the program name. If ident is NULL, the program name is used. |
option | The option argument specifies flags which control the operation of openlog() and subsequent calls to syslog(). |
facility | The facility argument establishes a default to be used if none is specified in subsequent calls to syslog(). |
void wc_set_log_level | ( | enum wc_log_facility | f, |
enum wc_log_level | l | ||
) |
Sets the log verbosity for a facility
This function allows to filter the log messages being written to a facility based on their priority (see enum wc_log_level
).
All the messages whose priority is higher or equal to the one given as parameter are being logged, the other ones are being discarded. Using the special priority WC_LOG_DISABLED will discard all the logs for the facility.
Example:
After this statement is executed
only the log messages with priority WC_LOG_EMERG, WC_LOG_ALERT, WC_LOG_CRIT and WC_LOG_ERR are going to show up in the logs for the WC_LOG_PARSER facility.
f | the facility |
l | the log level (priority) |