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.
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 LOGD_SYSLOG 0x01 |
#define LOGD_FILE 0x02 |
#define LOGD_STDERR 0x04 |
#define LOGP_INFO 4 |
#define LOGO_PID 0x01 |
#define LOG_TRACEME log_traceme(__FILE__, __FUNCTION__, __LINE__); |
void log_init | ( | log_options_t * | options | ) |
initialize log message mutliplexer
[in] | options | multiplexer configuration |
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
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_error | ( | const char * | fmt, | |
... | ||||
) |
send ERR level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_warn | ( | const char * | fmt, | |
... | ||||
) |
send WARNING level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_notice | ( | const char * | fmt, | |
... | ||||
) |
send NOTICE level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_info | ( | const char * | fmt, | |
... | ||||
) |
send INFO level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_debug | ( | const char * | fmt, | |
... | ||||
) |
send DEBUG level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_trace | ( | const char * | fmt, | |
... | ||||
) |
send TRACE level message to the multiplexer
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
Referenced by log_traceme().
int log_traceme | ( | const char * | file, | |
const char * | func, | |||
int | line | |||
) |
send TRACE level message to the multiplexer
[in] | file | File name |
[in] | func | Function name |
[in] | line | Line number |
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)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
exit(2)
void log_error_and_die | ( | const char * | fmt, | |
... | ||||
) |
send ERR level message to the multiplexer and exit(2)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
exit(2)
int log_palert | ( | const char * | fmt, | |
... | ||||
) |
send ALERT level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_perror | ( | const char * | fmt, | |
... | ||||
) |
send ERR level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_pwarn | ( | const char * | fmt, | |
... | ||||
) |
send WARNING level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_pnotice | ( | const char * | fmt, | |
... | ||||
) |
send NOTICE level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_pinfo | ( | const char * | fmt, | |
... | ||||
) |
send INFO level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_pdebug | ( | const char * | fmt, | |
... | ||||
) |
send DEBUG level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
int log_ptrace | ( | const char * | fmt, | |
... | ||||
) |
send TRACE level message to the multiplexer and append strerror(errno)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
void log_palert_and_die | ( | const char * | fmt, | |
... | ||||
) |
send ALERT level message to the multiplexer, append strerror(errno) and exit(2)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
exit(2)
void log_perror_and_die | ( | const char * | fmt, | |
... | ||||
) |
send ERR level message to the multiplexer, append strerror(errno) and exit(2)
[in] | fmt | format string passed to printf |
[in] | ... | variable number of arguments according to fmt |
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 }