2 * Sherlock Library -- Logging
4 * (c) 1997--2001 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
20 static char *log_progname, log_name_patt[64], log_name[64];
22 static int log_params;
31 log_switch(struct tm *tm)
36 if (!log_name_patt[0] ||
37 log_name[0] && !log_params)
39 strftime(name, sizeof(name), log_name_patt, tm);
40 if (!strcmp(name, log_name))
42 strcpy(log_name, name);
43 fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666);
45 die("Unable to open log file %s: %m", name);
52 vlog(unsigned int cat, const char *msg, va_list args)
54 time_t tim = time(NULL);
55 struct tm *tm = localtime(&tim);
59 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
60 fprintf(stderr, "%c %s ", cat, buf);
64 fprintf(stderr, "[%s (%d)] ", log_progname, log_pid);
66 fprintf(stderr, "[%s] ", log_progname);
71 fprintf(stderr, "[%d] ", log_pid);
73 vfprintf(stderr, msg, args);
79 log(unsigned int cat, const char *msg, ...)
94 vlog(L_FATAL, msg, args);
101 assert_failed(char *assertion, char *file, int line)
103 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
110 die("Internal error: Assertion failed.");
115 log_basename(byte *n)
126 log_init(byte *argv0)
129 log_progname = log_basename(argv0);
137 time_t tim = time(NULL);
138 struct tm *tm = localtime(&tim);
139 strcpy(log_name_patt, name);
140 log_params = !!strchr(name, '%');