wimax-tools 1.4.4
Defines | Functions | Variables

Set of simple log helpers

Log messages to stdout/stderr, with simple log level management. More...

Defines

#define w_error(fmt...)   w_msg(W_ERROR, __FILE__, __LINE__, "E: " fmt)
 Log a printf-like error message to stderr.
#define w_warn(fmt...)   w_msg(W_WARN, __FILE__, __LINE__, "W: " fmt)
 Log a printf-like warning message to stderr.
#define w_info(fmt...)   w_msg(W_INFO, __FILE__, __LINE__, "I: " fmt)
 Log a printf-like error message to stderr.
#define w_print(fmt...)   w_msg(W_PRINT, __FILE__, __LINE__, fmt)
 Log a printf-like error message to stdout.
#define w_d0(fmt...)   wimaxll_lmsg(W_D0, W_VERBOSITY, __func__, __LINE__, NULL, "D0: " fmt)
 Log a printf-like debug message (level 0)
#define w_d1(fmt...)   w_msg(W_D1, __FILE__, __LINE__, "D1: " fmt)
 Log a printf-like debug message (level 1)
#define w_d2(fmt...)   w_msg(W_D2, __FILE__, __LINE__, "D2: " fmt)
 Log a printf-like debug message (level 2)
#define w_d3(fmt...)   w_msg(W_D3, __FILE__, __LINE__, "D3: " fmt)
 Log a printf-like debug message (level 3)
#define w_d4(fmt...)   wimaxll_lmsg(W_D4, W_VERBOSITY, __func__, __LINE__, NULL, "D4: " fmt)
 Log a printf-like debug message (level 4)
#define w_d5(fmt...)   wimaxll_lmsg(W_D5, W_VERBOSITY, __func__, __LINE__, NULL, "D5: " fmt)
 Log a printf-like debug message (level 5)
#define w_d6(fmt...)   wimaxll_lmsg(W_D6, W_VERBOSITY, __func__, __LINE__, NULL, "D6: " fmt)
 Log a printf-like debug message (level 6)
#define w_d7(fmt...)   wimaxll_lmsg(W_D7, W_VERBOSITY, __func__, __LINE__, NULL, "D7: " fmt)
 Log a printf-like debug message (level 7)

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.
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.
void wimaxll_msg (struct wimaxll_handle *wmx, const char *fmt,...)
 Prints library diagnostic messages with a predefined format [frontend].
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.
void w_abort (int result, const char *fmt,...)
 Log an error message to stderr and abort.

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].
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].

Detailed Description

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:

 #define W_VERBOSITY W_INFO (or myglobalstruct.verbosity)
 #include <wimaxll/log.h>

 somefunc()
 {
        ...
        w_d1("debug message\n");
        ...
 }

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.


Define Documentation

w_d0 (   fmt...)    wimaxll_lmsg(W_D0, W_VERBOSITY, __func__, __LINE__, NULL, "D0: " fmt)

Log a printf-like debug message (level 0)

w_d1 (   fmt...)    w_msg(W_D1, __FILE__, __LINE__, "D1: " fmt)

Log a printf-like debug message (level 1)

w_d2 (   fmt...)    w_msg(W_D2, __FILE__, __LINE__, "D2: " fmt)

Log a printf-like debug message (level 2)

w_d3 (   fmt...)    w_msg(W_D3, __FILE__, __LINE__, "D3: " fmt)

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)

w_error (   fmt...)    w_msg(W_ERROR, __FILE__, __LINE__, "E: " fmt)

Log a printf-like error message to stderr.

Referenced by main().

w_info (   fmt...)    w_msg(W_INFO, __FILE__, __LINE__, "I: " fmt)

Log a printf-like error message to stderr.

w_print (   fmt...)    w_msg(W_PRINT, __FILE__, __LINE__, fmt)

Log a printf-like error message to stdout.

w_warn (   fmt...)    w_msg(W_WARN, __FILE__, __LINE__, "W: " fmt)

Log a printf-like warning message to stderr.


Function Documentation

void w_abort ( int  result,
const char *  fmt,
  ... 
)

Log an error message to stderr and abort.

Parameters:
resultexit 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.

Parameters:
levellevel of the messagve
current_levelcurrent logging level
origin_strOrigin of the message (used for a source file name or function name).
origin_lineOrigin of the message (used for a line in a source file or function).
wmxWiMAX handle; if NULL, no device header will be presented.
fmtprintf-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].

Parameters:
wmxWiMAX handle; if NULL, no device header will be presented.
fmtprintf-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.

Parameters:
wmxWiMAX handle this message is related to
levelMessage level
headerHeader for the message; the implementation must decide if it has to be printed or not.
fmtprintf-like format
vargsvariable-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.


Variable Documentation

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)
Initial value:

Create a header for library diagnostic messages [backend].

Parameters:
bufBuffer where to place the header
buf_lenSize of the buffer
wmxWiMAX handle the message is being generated for (can be NULL or invalid).
levelLevel of the log message this header is being generated for.
origin_strOrigin of the message (used for a source file name or function name). If NULL, the origin information should not be considered.
origin_lineOrigin 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:

 ...
 static
 void my_wimaxll_msg_hdr(char *buf, size_t len, struct
                         wimaxll_handle *wmx)
 {
         snprintf(buf, len, "my prefix: ");
 }
 ...
 wimaxll_msg_hdr = my_wimaxll_msg_hdr;
 ...
 wimaxll_open(BLAH);
void(* wimaxll_vlmsg_cb)(struct wimaxll_handle *wmx, unsigned level, const char *header, const char *fmt, va_list vargs)
Initial value:

Print library diagnostics messages [backend].

Parameters:
wmxWiMAX handle this message is related to
levelMessage level
headerHeader to print for the message (the implementation must decide if to print it or not).
fmtprintf-like format
vargsvariable-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.

Note:
This function pointer must be set before calling any other libwimaxll function.

By default, diagnostics are printed with wimaxll_vlmsg_default() to stderr or stdout based on the level.

For example, to deliver diagnostics to syslog:

 #include <syslog.h>
 ...
 static
 void wimaxll_vlmsg_syslog(....const char *fmt, va_list vargs)
 {
         syslog(LOG_MAKEPRI(LOG_USER, LOG_INFO), header);
         vsyslog(LOG_MAKEPRI(LOG_USER, LOG_INFO), fmt, vargs);
 }
 ...
 wimaxll_vlmsg = wimaxll_vlmsg_syslog();
 ...
 wimaxll_open(BLAH);

The internal function wimaxll_msg() and wimaxll_lmsg() are used as as a frontend to this function.