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 LOGD_SYSLOG   0x01
#define LOGD_FILE   0x02
#define LOGD_STDERR   0x04
#define LOGP_ALERT   0
#define LOGP_ERROR   1
#define LOGP_WARN   2
#define LOGP_NOTE   3
#define LOGP_INFO   4
#define LOGP_DEBUG   5
#define LOGP_TRACE   6
#define LOGO_PID   0x01
#define LOGO_TIME   0x02
#define LOGO_PRIO   0x04
#define LOGO_IDENT   0x08
#define LOG_TRACEME   log_traceme(__FILE__, __FUNCTION__, __LINE__);
 simple trace helper

Functions

void log_init (log_options_t *options)
 initialize log message mutliplexer
int log_alert (const char *fmt,...)
 send ALERT 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
int log_trace (const char *fmt,...)
 send TRACE level message to the multiplexer
int log_traceme (const char *file, const char *func, int line)
 send TRACE level message to the multiplexer
void log_alert_and_die (const char *fmt,...)
 send ALERT 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_palert (const char *fmt,...)
 send ALERT 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)
int log_ptrace (const char *fmt,...)
 send TRACE level message to the multiplexer and append strerror(errno)
void log_palert_and_die (const char *fmt,...)
 send ALERT 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 LOGD_SYSLOG   0x01

Log to syslog

Definition at line 42 of file log.h.

Referenced by log_close(), and log_init().

#define LOGD_FILE   0x02

Log to a file

Definition at line 43 of file log.h.

Referenced by log_close(), and log_init().

#define LOGD_STDERR   0x04

Log to STDERR

Definition at line 44 of file log.h.

Referenced by log_init().

#define LOGP_ALERT   0

action must be taken immediately

Definition at line 47 of file log.h.

#define LOGP_ERROR   1

error conditions

Definition at line 48 of file log.h.

#define LOGP_WARN   2

warning conditions

Definition at line 49 of file log.h.

#define LOGP_NOTE   3

normal but significant condition

Definition at line 50 of file log.h.

#define LOGP_INFO   4

informational

Definition at line 51 of file log.h.

Referenced by log_init().

#define LOGP_DEBUG   5

debug-level messages

Definition at line 52 of file log.h.

#define LOGP_TRACE   6

trace messages

Definition at line 53 of file log.h.

#define LOGO_PID   0x01

log the pid with each message

Definition at line 56 of file log.h.

Referenced by log_init().

#define LOGO_TIME   0x02

log the time with each message

Definition at line 57 of file log.h.

#define LOGO_PRIO   0x04

log the priority with each message

Definition at line 58 of file log.h.

#define LOGO_IDENT   0x08

log the ident string with each message

Definition at line 59 of file log.h.

#define LOG_TRACEME   log_traceme(__FILE__, __FUNCTION__, __LINE__);

simple trace helper

Definition at line 62 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 50 of file log_init.c.

References _log_options, log_options_t::log_dest, log_options_t::log_facility, log_options_t::log_fd, log_options_t::log_ident, log_options_t::log_mask, log_options_t::log_opts, LOGD_FILE, LOGD_STDERR, LOGD_SYSLOG, LOGO_PID, LOGP_INFO, mem_alloc(), mem_cpy(), and str_isempty.

00051 {
00052         struct stat sb;
00053 
00054         /* check file destination */
00055         if (options->log_dest & LOGD_FILE)
00056                 if (options->log_fd < 0 || fstat(options->log_fd, &sb) == -1)
00057                         options->log_dest &= ~LOGD_FILE;
00058 
00059         /* check if STDERR is available */
00060         if (options->log_dest & LOGD_STDERR)
00061                 if (fstat(STDERR_FILENO, &sb) == -1)
00062                         options->log_dest &= ~LOGD_STDERR;
00063 
00064         /* log up to LOGP_INFO if not specified */
00065         if (options->log_mask == 0)
00066                 options->log_mask = ((1 << ((LOGP_INFO) + 1)) - 1);
00067 
00068         /* sanitize ident string */
00069         if (str_isempty(options->log_ident))
00070                 options->log_ident = "(none)";
00071 
00072         if (options->log_dest & LOGD_SYSLOG) {
00073                 openlog(options->log_ident,
00074                                 options->log_opts & LOGO_PID ? LOG_PID : 0,
00075                                 options->log_facility);
00076                 setlogmask(mask_to_syslog(options->log_mask));
00077         }
00078 
00079         _log_options = (log_options_t *) mem_alloc(sizeof(log_options_t));
00080 
00081         mem_cpy(_log_options, options, sizeof(log_options_t));
00082 }

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_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

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

send TRACE 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

Referenced by log_traceme().

int log_traceme ( const char *  file,
const char *  func,
int  line 
)

send TRACE level message to the multiplexer

Parameters:
[in] file File name
[in] func Function name
[in] line Line number
Returns:
EXIT_SUCCESS
See also:
Formatted output conversion

Definition at line 117 of file log_internal.c.

References log_trace(), mem_free(), and str_path_basename().

00118 {
00119         char *base = str_path_basename(file);
00120 
00121         int rc = log_trace("@%s() in %s:%d", func, base, line);
00122 
00123         mem_free(base);
00124 
00125         return rc;
00126 }

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_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_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_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

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

send TRACE 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_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_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 25 of file log_close.c.

References _log_options, log_options_t::log_dest, log_options_t::log_fd, LOGD_FILE, LOGD_SYSLOG, and mem_free().

00026 {
00027         if (!_log_options)
00028                 return;
00029 
00030         if (_log_options->log_dest & LOGD_SYSLOG)
00031                 closelog();
00032 
00033         if (_log_options->log_dest & LOGD_FILE)
00034                 close(_log_options->log_fd);
00035 
00036         mem_free(_log_options);
00037 
00038         _log_options = 0;
00039 }


Generated on Tue Jun 19 20:38:45 2007 for lucid by  doxygen 1.5.2