version 1.43, 2012/09/06 04:37:39 |
version 1.44, 2013/04/07 02:10:33 |
|
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
#include <fcntl.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.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; |
|
static int log_stderr_fd = STDERR_FILENO; |
static int log_facility = LOG_AUTH; |
static int log_facility = LOG_AUTH; |
static char *argv0; |
static char *argv0; |
static log_handler_fn *log_handler; |
static log_handler_fn *log_handler; |
|
|
return log_on_stderr; |
return log_on_stderr; |
} |
} |
|
|
|
/* redirect what would usually get written to stderr to specified file */ |
|
void |
|
log_redirect_stderr_to(const char *logfile) |
|
{ |
|
int fd; |
|
|
|
if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) { |
|
fprintf(stderr, "Couldn't open logfile %s: %s\n", logfile, |
|
strerror(errno)); |
|
exit(1); |
|
} |
|
log_stderr_fd = fd; |
|
} |
|
|
#define MSGBUFSIZ 1024 |
#define MSGBUFSIZ 1024 |
|
|
void |
void |
|
|
log_handler = tmp_handler; |
log_handler = tmp_handler; |
} else if (log_on_stderr) { |
} else if (log_on_stderr) { |
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); |
snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); |
write(STDERR_FILENO, msgbuf, strlen(msgbuf)); |
write(log_stderr_fd, msgbuf, strlen(msgbuf)); |
} else { |
} else { |
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata); |
openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata); |
syslog_r(pri, &sdata, "%.500s", fmtbuf); |
syslog_r(pri, &sdata, "%.500s", fmtbuf); |