Log system multiplexer


Detailed Description

The log system multiplexer allows the caller to send log messages to multiple destinations; currently: syslog(3), file, stderr.

An application can only open one connection to the multiplexer during runtime. Another call to log_init() will replace the previous connection.

log_init() opens a connection to the multiplexer for a program. The options argument is a pointer to a log_options_t structure used for the multiplexer configuration.

See also:
log_options_t

syslog(3)


Data Structures

struct  log_options_t
 multiplexer configuration data More...

Defines

#define LOG_TRACEME
 simple trace helper

Functions

void log_init (log_options_t *options)
 initialize log message mutliplexer
void log_internal (int level, int strerr, const char *fmt, va_list ap)
int log_emerg (const char *fmt,...)
 send EMERG level message to the multiplexer
int log_alert (const char *fmt,...)
 send ALERT level message to the multiplexer
int log_crit (const char *fmt,...)
 send CRIT level message to the multiplexer
int log_error (const char *fmt,...)
 send ERR level message to the multiplexer
int log_warn (const char *fmt,...)
 send WARNING level message to the multiplexer
int log_notice (const char *fmt,...)
 send NOTICE level message to the multiplexer
int log_info (const char *fmt,...)
 send INFO level message to the multiplexer
int log_debug (const char *fmt,...)
 send DEBUG level message to the multiplexer
void log_emerg_and_die (const char *fmt,...)
 send EMERG level message to the multiplexer and exit(2)
void log_alert_and_die (const char *fmt,...)
 send ALERT level message to the multiplexer and exit(2)
void log_crit_and_die (const char *fmt,...)
 send CRIT level message to the multiplexer and exit(2)
void log_error_and_die (const char *fmt,...)
 send ERR level message to the multiplexer and exit(2)
int log_pemerg (const char *fmt,...)
 send EMERG level message to the multiplexer and append strerror(errno)
int log_palert (const char *fmt,...)
 send ALERT level message to the multiplexer and append strerror(errno)
int log_pcrit (const char *fmt,...)
 send CRIT level message to the multiplexer and append strerror(errno)
int log_perror (const char *fmt,...)
 send ERR level message to the multiplexer and append strerror(errno)
int log_pwarn (const char *fmt,...)
 send WARNING level message to the multiplexer and append strerror(errno)
int log_pnotice (const char *fmt,...)
 send NOTICE level message to the multiplexer and append strerror(errno)
int log_pinfo (const char *fmt,...)
 send INFO level message to the multiplexer and append strerror(errno)
int log_pdebug (const char *fmt,...)
 send DEBUG level message to the multiplexer and append strerror(errno)
void log_pemerg_and_die (const char *fmt,...)
 send EMERG level message to the multiplexer, append strerror(errno) and exit(2)
void log_palert_and_die (const char *fmt,...)
 send ALERT level message to the multiplexer, append strerror(errno) and exit(2)
void log_pcrit_and_die (const char *fmt,...)
 send CRIT level message to the multiplexer, append strerror(errno) and exit(2)
void log_perror_and_die (const char *fmt,...)
 send ERR level message to the multiplexer, append strerror(errno) and exit(2)
void log_close (void)
 close connection to logging system


Define Documentation

#define LOG_TRACEME

Value:

log_debug("[trace] %s (%s:%d)", \
                          __FUNCTION__, basename(__FILE__), __LINE__);
simple trace helper

Definition at line 87 of file log.h.


Function Documentation

void log_init ( log_options_t options  ) 

initialize log message mutliplexer

Parameters:
[in] options multiplexer configuration
See also:
log_options_t

Definition at line 28 of file log_init.c.

References _log_options, log_options_t::facility, log_options_t::fd, log_options_t::file, log_options_t::flags, log_options_t::ident, log_options_t::mask, log_options_t::stderr, str_cpyn(), str_len(), and log_options_t::syslog.

00029 {
00030         struct stat sb;
00031         
00032         if (options->file && (options->fd < 0 || fstat(options->fd, &sb) == -1))
00033                 options->file = false;
00034         
00035         if (options->stderr && fstat(STDERR_FILENO, &sb) == -1)
00036                 options->stderr = false;
00037         
00038         if (options->mask == 0)
00039                 options->mask = LOG_UPTO(LOG_INFO);
00040         
00041         if (!options->ident || str_len(options->ident) < 1)
00042                 options->ident = "(none)";
00043         
00044         options->flags &= ~LOG_PERROR;
00045         
00046         if (options->syslog) {
00047                 openlog(options->ident, options->flags, options->facility);
00048                 setlogmask(options->mask);
00049         }
00050         
00051         _log_options = (log_options_t *)malloc(sizeof(log_options_t));
00052         
00053         str_cpyn(_log_options, options, sizeof(log_options_t));
00054 }

void log_internal ( int  level,
int  strerr,
const char *  fmt,
va_list  ap 
)

Definition at line 69 of file log_internal.c.

References _log_options, _lucid_asprintf(), _lucid_vasprintf(), log_options_t::facility, log_options_t::fd, log_options_t::file, log_options_t::stderr, and log_options_t::syslog.

00070 {
00071         char *buf, *msg;
00072         
00073         if (!_log_options)
00074                 return;
00075         
00076         _lucid_vasprintf(&msg, fmt, ap);
00077         
00078         if (strerr) {
00079                 buf = msg;
00080                 _lucid_asprintf(&msg, "%s: %s", buf, strerror(errno_orig));
00081                 free(buf);
00082         }
00083         
00084         if (_log_options->syslog)
00085                 syslog(_log_options->facility|level, "%s", msg);
00086         
00087         if (_log_options->stderr)
00088                 log_fd(STDERR_FILENO, level, msg);
00089         
00090         if (_log_options->file)
00091                 log_fd(_log_options->fd, level, msg);
00092         
00093         free(msg);
00094 }

int log_emerg ( const char *  fmt,
  ... 
)

send EMERG level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_alert ( const char *  fmt,
  ... 
)

send ALERT level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_crit ( const char *  fmt,
  ... 
)

send CRIT level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_error ( const char *  fmt,
  ... 
)

send ERR level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_warn ( const char *  fmt,
  ... 
)

send WARNING level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_notice ( const char *  fmt,
  ... 
)

send NOTICE level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_info ( const char *  fmt,
  ... 
)

send INFO level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_debug ( const char *  fmt,
  ... 
)

send DEBUG level message to the multiplexer

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

void log_emerg_and_die ( const char *  fmt,
  ... 
)

send EMERG level message to the multiplexer and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_alert_and_die ( const char *  fmt,
  ... 
)

send ALERT level message to the multiplexer and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_crit_and_die ( const char *  fmt,
  ... 
)

send CRIT level message to the multiplexer and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_error_and_die ( const char *  fmt,
  ... 
)

send ERR level message to the multiplexer and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

int log_pemerg ( const char *  fmt,
  ... 
)

send EMERG level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_palert ( const char *  fmt,
  ... 
)

send ALERT level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_pcrit ( const char *  fmt,
  ... 
)

send CRIT level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_perror ( const char *  fmt,
  ... 
)

send ERR level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_FAILURE
See also:
Formatted output conversion

int log_pwarn ( const char *  fmt,
  ... 
)

send WARNING level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_pnotice ( const char *  fmt,
  ... 
)

send NOTICE level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_pinfo ( const char *  fmt,
  ... 
)

send INFO level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

int log_pdebug ( const char *  fmt,
  ... 
)

send DEBUG level message to the multiplexer and append strerror(errno)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

void log_pemerg_and_die ( const char *  fmt,
  ... 
)

send EMERG level message to the multiplexer, append strerror(errno) and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_palert_and_die ( const char *  fmt,
  ... 
)

send ALERT level message to the multiplexer, append strerror(errno) and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_pcrit_and_die ( const char *  fmt,
  ... 
)

send CRIT level message to the multiplexer, append strerror(errno) and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_perror_and_die ( const char *  fmt,
  ... 
)

send ERR level message to the multiplexer, append strerror(errno) and exit(2)

Parameters:
[in] fmt format string passed to printf
[in] ... variable number of arguments according to fmt
See also:
Formatted output conversion

exit(2)

void log_close ( void   ) 

close connection to logging system

Definition at line 26 of file log_close.c.

References _log_options, log_options_t::fd, log_options_t::file, and log_options_t::syslog.

00027 {
00028         if (!_log_options)
00029                 return;
00030         
00031         if (_log_options->syslog)
00032                 closelog();
00033         
00034         if (_log_options->file)
00035                 close(_log_options->fd);
00036         
00037         free(_log_options);
00038 }


Generated on Sun Dec 3 17:46:16 2006 for lucid by  doxygen 1.5.1