version 1.24.2.1, 2003/04/01 00:12:13 |
version 1.24.2.2, 2003/09/16 21:20:26 |
|
|
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
#include <syslog.h> |
#include <syslog.h> |
|
#include <vis.h> |
|
|
static LogLevel log_level = SYSLOG_LEVEL_INFO; |
static LogLevel log_level = SYSLOG_LEVEL_INFO; |
static int log_on_stderr = 1; |
static int log_on_stderr = 1; |
|
|
/* Log this message (information that usually should go to the log). */ |
/* Log this message (information that usually should go to the log). */ |
|
|
void |
void |
log(const char *fmt,...) |
logit(const char *fmt,...) |
{ |
{ |
va_list args; |
va_list args; |
|
|
|
|
void |
void |
do_log(LogLevel level, const char *fmt, va_list args) |
do_log(LogLevel level, const char *fmt, va_list args) |
{ |
{ |
|
struct syslog_data sdata = SYSLOG_DATA_INIT; |
char msgbuf[MSGBUFSIZ]; |
char msgbuf[MSGBUFSIZ]; |
char fmtbuf[MSGBUFSIZ]; |
char fmtbuf[MSGBUFSIZ]; |
char *txt = NULL; |
char *txt = NULL; |
|
|
} else { |
} else { |
vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); |
vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); |
} |
} |
|
strnvis(fmtbuf, msgbuf, sizeof(fmtbuf), VIS_SAFE|VIS_OCTAL); |
if (log_on_stderr) { |
if (log_on_stderr) { |
fprintf(stderr, "%s\r\n", msgbuf); |
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); |
|
write(STDERR_FILENO, msgbuf, strlen(msgbuf)); |
} else { |
} else { |
openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility); |
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata); |
syslog(pri, "%.500s", msgbuf); |
syslog_r(pri, &sdata, "%.500s", fmtbuf); |
closelog(); |
closelog_r(&sdata); |
} |
} |
} |
} |