4 * Lars Fenneberg <lf@elemental.net>
6 * This software is Copyright 1996,1997 by the above mentioned author(s),
9 * The license which is distributed with this software in the file
10 * COPYRIGHT applies to this software. If your distribution is missing
11 * this file, you may request it from <pekkas@netcore.fi>.
19 static int log_method
= L_NONE
;
20 static char *log_ident
;
21 static char *log_file
;
22 static FILE *log_file_fd
;
23 static int log_facility
;
24 static int debug_level
= 0;
27 log_open(int method
, char *ident
, char *log
, int facility
)
40 log_facility
= LOG_DAEMON
;
42 log_facility
= facility
;
44 openlog(log_ident
, LOG_PID
, log_facility
);
49 fprintf(stderr
, "%s: no logfile specified\n", log_ident
);
53 if ((log_file_fd
= fopen(log_file
, "a")) == NULL
)
55 fprintf(stderr
, "%s: can't open %s: %s\n", log_ident
, log_file
, strerror(errno
));
60 fprintf(stderr
, "%s: unknown logging method: %d\n", log_ident
, log_method
);
67 /* note: [dfv]log() is also called from root context */
69 vlog(int prio
, char *format
, va_list ap
)
71 char tstamp
[64], buff
[1024];
75 vsnprintf(buff
, sizeof(buff
), format
, ap
);
81 syslog(prio
, "%s", buff
);
84 syslog(prio
, "%s", buff
);
85 if (prio
> LOG_ERR
) /* fall through for messages with high priority */
89 tm
= localtime(¤t
);
90 (void) strftime(tstamp
, sizeof(tstamp
), LOG_TIME_FORMAT
, tm
);
92 fprintf(stderr
, "[%s] %s: %s\n", tstamp
, log_ident
, buff
);
97 tm
= localtime(¤t
);
98 (void) strftime(tstamp
, sizeof(tstamp
), LOG_TIME_FORMAT
, tm
);
100 fprintf(log_file_fd
, "[%s] %s: %s\n", tstamp
, log_ident
, buff
);
104 fprintf(stderr
, "%s: unknown logging method: %d\n", log_ident
, log_method
);
112 dlog(int prio
, int level
, char *format
, ...)
116 if (debug_level
< level
)
119 va_start(ap
, format
);
120 vlog(prio
, format
, ap
);
125 flog(int prio
, char *format
, ...)
129 va_start(ap
, format
);
130 vlog(prio
, format
, ap
);
137 switch (log_method
) {
141 case L_STDERR_SYSLOG
:
149 fprintf(stderr
, "%s: unknown logging method: %d\n", log_ident
, log_method
);
157 set_debuglevel(int level
)