4 * This module handles the logging of requests.
6 * TODO: Merge the two "XXX_log() calls.
8 * Authors: Donald J. Becker, <becker@super.org>
9 * Rick Sladkey, <jrs@world.std.com>
10 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
11 * Olaf Kirch, <okir@monad.swb.de>
13 * This software maybe be used for any purpose provided
14 * the above copyright notice is retained. It is supplied
15 * as is, with no warranty expressed or implied.
34 static int log_stderr = 1;
35 static int log_syslog = 1;
36 static int logging = 0; /* enable/disable DEBUG logs */
37 static int logmask = 0; /* What will be logged */
38 static char log_name[256]; /* name of this program */
39 static int log_pid = -1; /* PID of this program */
41 static void xlog_toggle(int sig);
42 static struct xlog_debugfac debugnames[] = {
43 { "general", D_GENERAL, },
46 { "parse", D_PARSE, },
52 xlog_open(char *progname)
54 openlog(progname, LOG_PID, LOG_DAEMON);
56 strncpy(log_name, progname, sizeof (log_name) - 1);
57 log_name [sizeof (log_name) - 1] = '\0';
60 signal(SIGUSR1, xlog_toggle);
61 signal(SIGUSR2, xlog_toggle);
82 if ((logmask & D_ALL) && !logging) {
83 xlog(D_GENERAL, "turned on logging");
88 logmask |= ((logmask & D_ALL) << 1) | D_GENERAL;
89 for (i = -1, tmp &= logmask; tmp; tmp >>= 1, i++)
92 "turned on logging level %d", i);
94 xlog(D_GENERAL, "turned off logging");
97 signal(sig, xlog_toggle);
101 xlog_config(int fac, int on)
112 xlog_sconfig(char *kind, int on)
114 struct xlog_debugfac *tbl = debugnames;
116 while (tbl->df_name != NULL && strcasecmp(tbl->df_name, kind))
119 xlog (L_WARNING, "Invalid debug facility: %s\n", kind);
122 xlog_config(tbl->df_fac, on);
126 xlog_enabled(int fac)
128 return (logging && (fac & logmask));
132 /* Write something to the system logfile and/or stderr */
134 xlog_backend(int kind, const char *fmt, va_list args)
138 if (!(kind & (L_ALL)) && !(logging && (kind & logmask)))
142 va_copy(args2, args);
147 vsyslog(LOG_ERR, fmt, args);
150 vsyslog(LOG_ERR, fmt, args);
153 vsyslog(LOG_WARNING, fmt, args);
156 vsyslog(LOG_NOTICE, fmt, args);
160 vsyslog(LOG_INFO, fmt, args);
166 #ifdef VERBOSE_PRINTF
171 tm = localtime(&now);
172 fprintf(stderr, "%s[%d] %04d-%02d-%02d %02d:%02d:%02d ",
174 tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday,
175 tm->tm_hour, tm->tm_min, tm->tm_sec);
177 fprintf(stderr, "%s: ", log_name);
179 vfprintf(stderr, fmt, args2);
180 fprintf(stderr, "\n");
189 xlog(int kind, const char* fmt, ...)
194 xlog_backend(kind, fmt, args);
199 xlog_warn(const char* fmt, ...)
204 xlog_backend(L_WARNING, fmt, args);
210 xlog_err(const char* fmt, ...)
215 xlog_backend(L_FATAL, fmt, args);