Logging


Overview

Logging levels

All standard syslog(3) levels:

NOTE
All functions that not contain the [facility] parameter reference a variable named "facility" that must be defined somewhere and must be in scope.
Common parameters

Defines

#define u_log_die(ecode, facility, flags, err,...)
 log an error message and die
#define u_log_emerg(facility, flags, err,...)   u_log_write(facility, LOG_EMERG, flags, err, __VA_ARGS__)
 log an emerg message
#define u_log_alert(facility, flags, err,...)   u_log_write(facility, LOG_ALERT, flags, err, __VA_ARGS__)
 log an alert message
#define u_log_critical(facility, flags, err,...)   u_log_write(facility, LOG_CRIT, flags, err, __VA_ARGS__)
 log a critical message
#define u_log_error(facility, flags, err,...)   u_log_write(facility, LOG_ERR, flags, err, __VA_ARGS__)
 log an error message
#define u_log_warning(facility, flags, err,...)   u_log_write(facility, LOG_WARNING, flags, err, __VA_ARGS__)
 log a warning message
#define u_log_notice(facility, flags, err,...)   u_log_write(facility, LOG_NOTICE, flags, err, __VA_ARGS__)
 log a notice message
#define u_log_info(facility, flags, err,...)   u_log_write(facility, LOG_INFO, flags, err, __VA_ARGS__)
 log an informational message
#define u_log_debug(facility, flags, err,...)   u_log_write(facility, LOG_DEBUG, flags, err, __VA_ARGS__)
 log a debug message
#define die(ecode,...)   u_log_die(ecode, facility, 1, 0, __VA_ARGS__)
 same as u_log_die but using the facility global variable
#define die_if(expr)   if(expr) die(EXIT_FAILURE, #expr)
 calls die() if expr is true
#define emerg_(err,...)   u_log_emerg(facility, 1, err, __VA_ARGS__)
 same as u_log_emerg but using the facility global variable
#define alert_(err,...)   u_log_alert(facility, 1, err, __VA_ARGS__)
 same as u_log_alert but using the facility global variable
#define crit_(err,...)   u_log_critical(facility, 1, err, __VA_ARGS__)
 same as u_log_critical but using the facility global variable
#define err_(err,...)   u_log_error(facility, 1, err, __VA_ARGS__)
 same as u_log_error but using the facility global variable
#define warn_(err,...)   u_log_warning(facility, 1, err, __VA_ARGS__)
 same as u_log_warning but using the facility global variable
#define notice_(err,...)   u_log_notice(facility, 1, err, __VA_ARGS__)
 same as u_log_info but using the facility global variable
#define info_(err,...)   u_log_info(facility, 0, err, __VA_ARGS__)
 same as u_log_info but using the facility global variable
#define dbg_(err,...)   u_log_debug(facility, 1, err, __VA_ARGS__)
 same as u_log_debug but using the facility global variable
#define con_(err,...)   u_console_write( err, __VA_ARGS__)
 write a log message to stderr

Typedefs

typedef int(* u_log_hook_t )(void *arg, int level, const char *str)
 log hook typedef
typedef int(* u_log_lock_t )(void *arg)
 thread lock callback typedef
typedef int(* u_log_unlock_t )(void *arg)
 thread unlock callback typedef

Functions

int u_log_set_lock (u_log_lock_t f, void *arg)
 set the lock function callback
int u_log_set_unlock (u_log_unlock_t f, void *arg)
 set the unlock function callback
int u_log_set_hook (u_log_hook_t hook, void *arg, u_log_hook_t *old, void **parg)
 set a log hook to redirect log messages
int u_strerror_r (int err, char *buf, size_t size)
 Return, in the given buffer, a string describing the error code.

Variables

int facility
 per-process facility variable.

Define Documentation

#define u_log_alert ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_ALERT, flags, err, __VA_ARGS__)

Write an alert log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 170 of file log.h.

#define u_log_critical ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_CRIT, flags, err, __VA_ARGS__)

Write a critical log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 182 of file log.h.

#define u_log_debug ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_DEBUG, flags, err, __VA_ARGS__)

Write a debug log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 242 of file log.h.

#define u_log_die ( ecode,
facility,
flags,
err,
...   ) 
Value:
do {                                                        \
        u_log_write(facility, LOG_CRIT, flags, err, __VA_ARGS__); \
        exit(ecode);                                            \
    } while(0)

Write an error log message and die.

Parameters:
ecode exit code
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 143 of file log.h.

#define u_log_emerg ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_EMERG, flags, err, __VA_ARGS__)

Write an emerg log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 158 of file log.h.

#define u_log_error ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_ERR, flags, err, __VA_ARGS__)

Write an error log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 194 of file log.h.

#define u_log_info ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_INFO, flags, err, __VA_ARGS__)

Write an informational log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 230 of file log.h.

#define u_log_notice ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_NOTICE, flags, err, __VA_ARGS__)

Write a notice log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 218 of file log.h.

#define u_log_warning ( facility,
flags,
err,
...   )     u_log_write(facility, LOG_WARNING, flags, err, __VA_ARGS__)

Write a warning log message.

Parameters:
facility facility
flags OR-ed LOG_WRITE_FLAG_* flags
err if set append strerror(err) to the message
... printf-style variable length arguments list

Definition at line 206 of file log.h.


Function Documentation

int u_log_set_hook ( u_log_hook_t  hook,
void *  arg,
u_log_hook_t old,
void **  parg 
)

Force the log subsystem to use user-provided function to write log messages.

The provided function will be called for each dbg_, warn_ or info_ calls.

Parameters:
hook function that will be called to write log messages set this param to NULL to set the default syslog-logging
arg an opaque argument that will be passed to the hook function
old [out] will get the previously set hook or NULL if no hook has been set
parg [out] will get the previously set hook argument
Returns:
0 on success, not zero on error

Definition at line 128 of file log.c.

int u_log_set_lock ( u_log_lock_t  f,
void *  arg 
)

Set the lock function used by the log subsystem to work properly in multi-thread environments (you must also set the unlock function).

The lock primitive must allow recursive locking i.e. the thread that owns the lock can call the lock function more times without blocking (it must call the unlock function the same number of times).

Parameters:
f function that will be called to get the lock
arg an opaque argument that will be passed to the lock function
Returns:
0 on success, not zero on error

Definition at line 44 of file log.c.

int u_log_set_unlock ( u_log_unlock_t  f,
void *  arg 
)

Set the unlock function used by the log subsystem to work properly in multi-thread environments (you must also set the lock function);

Parameters:
f function that will be called to release the lock
arg an opaque argument that will be passed to the lock function
Returns:
0 on success, not zero on error

Definition at line 52 of file log.c.

int u_strerror_r ( int  err,
char *  buf,
size_t  size 
)

Return in 'msg' a string describing the error code. Works equally with POSIX-style C libs and with glibc (that use a different prototype for strerror_r).

If strerror_r doesn't exist in the system strerror() is used instead.

Parameters:
err the error code
buf the buffer that will get the error message
size size of buf
Returns:
0 on success, ~0 on error

Definition at line 231 of file log.c.


Variable Documentation

int facility

all processes that use the libu must define a "facility" variable somewhere to satisfy this external linkage reference.

Such variable will be used as the syslog(3) facility argument.

Definition at line 1 of file facility.c.


←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved