wimax-tools
1.4.4
|
Log messages to stdout/stderr, with simple log level management. More...
Macros | |
#define | w_error(fmt...) w_msg(W_ERROR, __FILE__, __LINE__, "E: " fmt) |
Log a printf-like error message to stderr. More... | |
#define | w_warn(fmt...) w_msg(W_WARN, __FILE__, __LINE__, "W: " fmt) |
Log a printf-like warning message to stderr. More... | |
#define | w_info(fmt...) w_msg(W_INFO, __FILE__, __LINE__, "I: " fmt) |
Log a printf-like error message to stderr. More... | |
#define | w_print(fmt...) w_msg(W_PRINT, __FILE__, __LINE__, fmt) |
Log a printf-like error message to stdout. More... | |
#define | w_d0(fmt...) wimaxll_lmsg(W_D0, W_VERBOSITY, __func__, __LINE__, NULL, "D0: " fmt) |
Log a printf-like debug message (level 0) More... | |
#define | w_d1(fmt...) w_msg(W_D1, __FILE__, __LINE__, "D1: " fmt) |
Log a printf-like debug message (level 1) More... | |
#define | w_d2(fmt...) w_msg(W_D2, __FILE__, __LINE__, "D2: " fmt) |
Log a printf-like debug message (level 2) More... | |
#define | w_d3(fmt...) w_msg(W_D3, __FILE__, __LINE__, "D3: " fmt) |
Log a printf-like debug message (level 3) More... | |
#define | w_d4(fmt...) wimaxll_lmsg(W_D4, W_VERBOSITY, __func__, __LINE__, NULL, "D4: " fmt) |
Log a printf-like debug message (level 4) More... | |
#define | w_d5(fmt...) wimaxll_lmsg(W_D5, W_VERBOSITY, __func__, __LINE__, NULL, "D5: " fmt) |
Log a printf-like debug message (level 5) More... | |
#define | w_d6(fmt...) wimaxll_lmsg(W_D6, W_VERBOSITY, __func__, __LINE__, NULL, "D6: " fmt) |
Log a printf-like debug message (level 6) More... | |
#define | w_d7(fmt...) wimaxll_lmsg(W_D7, W_VERBOSITY, __func__, __LINE__, NULL, "D7: " fmt) |
Log a printf-like debug message (level 7) More... | |
Functions | |
void | wimaxll_vlmsg_default (struct wimaxll_handle *wmx, unsigned level, const char *header, const char *fmt, va_list vargs) |
Deliver libwimaxll diagnostics messages to stderr or stdout. More... | |
void | wimaxll_msg_hdr_default (char *buf, size_t buf_len, struct wimaxll_handle *wmx, enum w_levels level, const char *origin_str, unsigned origin_line) |
Default header for diagnostic messages. More... | |
void | wimaxll_msg (struct wimaxll_handle *wmx, const char *fmt,...) |
Prints library diagnostic messages with a predefined format [frontend]. More... | |
void | wimaxll_lmsg (unsigned level, unsigned current_level, const char *origin_str, unsigned origin_line, struct wimaxll_handle *wmx, const char *fmt,...) |
Prints library diagnostic messages with a predefined format [frontend] and log level control. More... | |
void | w_abort (int result, const char *fmt,...) |
Log an error message to stderr and abort. More... | |
Variables | |
void(* | wimaxll_vlmsg_cb )(struct wimaxll_handle *wmx, unsigned level, const char *header, const char *fmt, va_list vargs) |
Print library diagnostics messages [backend]. More... | |
void(* | wimaxll_msg_hdr_cb )(char *buf, size_t buf_len, struct wimaxll_handle *wmx, enum w_levels level, const char *origin_str, unsigned origin_line) |
Create a header for library diagnostic messages [backend]. More... | |
Log messages to stdout/stderr, with simple log level management.
If the log level is W_PRINT, we assume is a normal message that the user wants to see and send it to stdout. If it is any other, evaluate if it should be printed based on the current level and then print it to stderr.
Before including, W_VERBOSITY must be defined to something that yields a numeric value out of of { enum w_levels }. When any of the w_*() functions/macros is called, if the level it is called with is less or equal than the current level defied by W_VERBOSITY, it'll be ran, if not, it'll be ignored:
To control where the log/progress messages go and how they are formatted, the client can set a couple of function pointers wimaxll_msg_hdr_cb() (which controls how a header/prefix for the message is created) and wimaxll_vlmsg_cb(), which takes the message and delivers it to whichever destination.
The default implementations are wimaxll_msg_hdr_default() and wimaxll_vlmsg_default(), which add a "libwimall[DEVICENAME]:" header (with an optional "(@ FUNCTION:LINE)") and deliver the message to stdout if it is a normal message (W_PRINT) or else if it is an error, warning, info or debug message, it is sent to stderr.
w_d0 | ( | fmt... | ) | wimaxll_lmsg(W_D0, W_VERBOSITY, __func__, __LINE__, NULL, "D0: " fmt) |
Log a printf-like debug message (level 0)
Log a printf-like debug message (level 1)
Log a printf-like debug message (level 2)
Log a printf-like debug message (level 3)
Referenced by main().
w_d4 | ( | fmt... | ) | wimaxll_lmsg(W_D4, W_VERBOSITY, __func__, __LINE__, NULL, "D4: " fmt) |
Log a printf-like debug message (level 4)
w_d5 | ( | fmt... | ) | wimaxll_lmsg(W_D5, W_VERBOSITY, __func__, __LINE__, NULL, "D5: " fmt) |
Log a printf-like debug message (level 5)
w_d6 | ( | fmt... | ) | wimaxll_lmsg(W_D6, W_VERBOSITY, __func__, __LINE__, NULL, "D6: " fmt) |
Log a printf-like debug message (level 6)
w_d7 | ( | fmt... | ) | wimaxll_lmsg(W_D7, W_VERBOSITY, __func__, __LINE__, NULL, "D7: " fmt) |
Log a printf-like debug message (level 7)
Log a printf-like error message to stderr.
Referenced by main().
Log a printf-like error message to stderr.
Log a printf-like error message to stdout.
Log a printf-like warning message to stderr.
void w_abort | ( | int | result, |
const char * | fmt, | ||
... | |||
) |
Log an error message to stderr and abort.
result | exit code to abort with |
fmt,: | printf-like format string and its arguments |
:
void wimaxll_lmsg | ( | unsigned | level, |
unsigned | current_level, | ||
const char * | origin_str, | ||
unsigned | origin_line, | ||
struct wimaxll_handle * | wmx, | ||
const char * | fmt, | ||
... | |||
) |
Prints library diagnostic messages with a predefined format [frontend] and log level control.
level | level of the messagve |
current_level | current logging level |
origin_str | Origin of the message (used for a source file name or function name). |
origin_line | Origin of the message (used for a line in a source file or function). |
wmx | WiMAX handle; if NULL, no device header will be presented. |
fmt | printf-like format followed by any arguments |
Called by the library functions to print status/error messages if the current log level allows it. By default these are sent over to stderr.
However, library users can change this default behaviour by setting wimaxll_vmsg() as documented in that function pointer's documentation.
void wimaxll_msg | ( | struct wimaxll_handle * | wmx, |
const char * | fmt, | ||
... | |||
) |
Prints library diagnostic messages with a predefined format [frontend].
wmx | WiMAX handle; if NULL, no device header will be presented. |
fmt | printf-like format followed by any arguments |
Called by the library functions to print status/error messages. By default these are sent over to stderr.
However, library users can change this default behaviour by setting wimaxll_vmsg() as documented in that function pointer's documentation.
void wimaxll_msg_hdr_default | ( | char * | buf, |
size_t | buf_len, | ||
struct wimaxll_handle * | wmx, | ||
enum w_levels | level, | ||
const char * | origin_str, | ||
unsigned | origin_line | ||
) |
Default header for diagnostic messages.
If there is no handle, prints just "libwimaxll", otherwise "libwimaxll[device]"; if the message is debug, also adds a "(@ FUNCTION:LINE)" origin tag.
void wimaxll_vlmsg_default | ( | struct wimaxll_handle * | wmx, |
unsigned | level, | ||
const char * | header, | ||
const char * | fmt, | ||
va_list | vargs | ||
) |
Deliver libwimaxll diagnostics messages to stderr or stdout.
wmx | WiMAX handle this message is related to |
level | Message level |
header | Header for the message; the implementation must decide if it has to be printed or not. |
fmt | printf-like format |
vargs | variable-argument list as created by stdargs.h:va_list() that will be formatted according to fmt. |
Default diagnostics printing function. If the log level is "W_PRINT", we put it on stdout without a header, otherwise in stderr with header.
void(* wimaxll_msg_hdr_cb)(char *buf, size_t buf_len, struct wimaxll_handle *wmx, enum w_levels level, const char *origin_str, unsigned origin_line) |
Create a header for library diagnostic messages [backend].
buf | Buffer where to place the header |
buf_len | Size of the buffer |
wmx | WiMAX handle the message is being generated for (can be NULL or invalid). |
level | Level of the log message this header is being generated for. |
origin_str | Origin of the message (used for a source file name or function name). If NULL, the origin information should not be considered. |
origin_line | Origin of the message (used for a line in a source file or function). |
Creates a header to prefix to ever message printed with wimaxll_msg().
By default, diagnostics are printed with wimaxll_msg_hdr_default() is used, which creates a "libwimaxll[DEVICENAME]" prefix.
To change it:
void(* wimaxll_vlmsg_cb)(struct wimaxll_handle *wmx, unsigned level, const char *header, const char *fmt, va_list vargs) |
Print library diagnostics messages [backend].
wmx | WiMAX handle this message is related to |
level | Message level |
header | Header to print for the message (the implementation must decide if to print it or not). |
fmt | printf-like format |
vargs | variable-argument list as created by stdargs.h:va_list() that will be formatted according to fmt. |
Prints/writes the libwimaxll's diagnostics messages to a destination as selected by the user of the library.
By default, diagnostics are printed with wimaxll_vlmsg_default() to stderr or stdout based on the level.
For example, to deliver diagnostics to syslog:
The internal function wimaxll_msg() and wimaxll_lmsg() are used as as a frontend to this function.