diff -burN asterisk.orig/configs/logger.conf.sample asterisk/configs/logger.conf.sample --- asterisk.orig/configs/logger.conf.sample 2003-02-12 14:59:15.000000000 +0100 +++ asterisk/configs/logger.conf.sample 2003-04-03 11:48:49.000000000 +0200 @@ -14,3 +14,7 @@ ;debug => debug console => notice,warning,error messages => notice,warning,error +; +; Filename "syslog" enables logging to syslog +; +syslog => notice,warning,error diff -burN asterisk.orig/include/asterisk/syslog.h asterisk/include/asterisk/syslog.h --- asterisk.orig/include/asterisk/syslog.h 1970-01-01 01:00:00.000000000 +0100 +++ asterisk/include/asterisk/syslog.h 2003-04-03 11:48:13.000000000 +0200 @@ -0,0 +1,193 @@ +/* + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H +#define _SYS_SYSLOG_H 1 + +#include +#define __need___va_list +#include + + +#define _PATH_LOG "/dev/log" + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define SYS_LOG_EMERG 0 /* system is unusable */ +#define SYS_LOG_ALERT 1 /* action must be taken immediately */ +#define SYS_LOG_CRIT 2 /* critical conditions */ +#define SYS_LOG_ERR 3 /* error conditions */ +#define SYS_LOG_WARNING 4 /* warning conditions */ +#define SYS_LOG_NOTICE 5 /* normal but significant condition */ +#define SYS_LOG_INFO 6 /* informational */ +#define SYS_LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = + { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 } + }; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = + { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 } + }; +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +__BEGIN_DECLS + +/* Close desriptor used to write to system logger. */ +extern void closelog (void) __THROW; + +/* Open connection to system logger. */ +extern void openlog (__const char *__ident, int __option, int __facility) + __THROW; + +/* Set the log mask level. */ +extern int setlogmask (int __mask) __THROW; + +/* Generate a log message using FMT string and option arguments. */ +extern void syslog (int __pri, __const char *__fmt, ...) __THROW + __attribute__ ((__format__(__printf__, 2, 3))); + +#ifdef __USE_BSD +/* Generate a log message using FMT and using arguments pointed to by AP. */ +extern void vsyslog (int __pri, __const char *__fmt, __gnuc_va_list __ap) + __THROW __attribute__ ((__format__(__printf__, 2, 0))); +#endif + +__END_DECLS + +#endif /* sys/syslog.h */ diff -burN asterisk.orig/logger.c asterisk/logger.c --- asterisk.orig/logger.c 2003-03-31 05:19:34.000000000 +0200 +++ asterisk/logger.c 2003-04-03 11:47:03.000000000 +0200 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,10 @@ f->f = NULL; } else if (!strcasecmp(fn, "console")) { f->f = stdout; + } else if (!strcasecmp(fn, "syslog")) { + f->f = NULL; + openlog("asterisk", LOG_ODELAY, LOG_USER); + syslog(SYS_LOG_INFO, "Opened asterisk syslog"); } else { if (fn[0] == '/') strncpy(tmp, fn, sizeof(tmp) - 1); @@ -227,8 +232,9 @@ char tmp3[80]; char tmp4[80]; char linestr[80]; + char logstr[255]; time_t t; - struct tm tm; + struct tm *tm; struct logfile *f; va_list ap; @@ -238,10 +244,10 @@ ast_pthread_mutex_lock(&loglock); if (level == 1 /* Event */) { time(&t); - localtime_r(&t,&tm); - if (&tm) { + tm = localtime(&t); + if (tm) { /* Log events into the event log file, with a different format */ - strftime(date, sizeof(date), "%b %e %T", &tm); + strftime(date, sizeof(date), "%b %e %T", tm); fprintf(eventlog, "%s asterisk[%d]: ", date, getpid()); va_start(ap, fmt); vfprintf(eventlog, fmt, ap); @@ -258,8 +264,8 @@ if (f->logflags & (1 << level) && f->f) { if ((f->f != stdout) && (f->f != stderr)) { time(&t); - localtime_r(&t,&tm); - strftime(date, sizeof(date), "%b %e %T", &tm); + tm = localtime(&t); + strftime(date, sizeof(date), "%b %e %T", tm); fprintf(f->f, "%s %s[%ld]: File %s, Line %d (%s): ", date, levels[level], pthread_self(), file, line, function); } else { sprintf(linestr, "%d", line); @@ -274,6 +280,32 @@ vfprintf(f->f, fmt, ap); va_end(ap); fflush(f->f); + } else { /* log to syslog */ + if ((f->logflags & ( 1 << level)) && !strcasecmp(f->fn, "syslog")) { + va_start(ap, fmt); + vsprintf(logstr, fmt, ap); + va_end(ap); + switch(level) { + case 0: + syslog(SYS_LOG_DEBUG, "%s[%ld]: File %s, Line %d (%s): %s", levels[level], pthread_self(), file, line, function, logstr); + break; + case 1: + syslog(SYS_LOG_INFO, "%s[%ld]: File %s, Line %d (%s): %s", + levels[level], pthread_self(), file, line, function, logstr); + break; + case 2: + syslog(SYS_LOG_NOTICE, "%s[%ld]: File %s, Line %d (%s): %s", + levels[level], pthread_self(), file, line, function, logstr); + break; + case 3: + syslog(SYS_LOG_WARNING, "%s[%ld]: File %s, Line %d (%s): %s", + levels[level], pthread_self(), file, line, function, logstr); + case 4: + syslog(SYS_LOG_ERR, "%s[%ld]: File %s, Line %d (%s): %s", + levels[level], pthread_self(), file, line, function, logstr); + break; + } + } } f = f->next; }