2 * Sherlock Library -- Logging
4 * (c) 1997--2004 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[32];
24 void (*log_die_hook)(void);
25 void (*log_switch_hook)(struct tm *tm);
28 vlog_msg(unsigned int cat, const char *msg, va_list args)
30 time_t tim = time(NULL);
31 struct tm *tm = localtime(&tim);
40 p = buf = alloca(buflen);
42 p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm);
46 p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
48 p += sprintf(p, "[%s] ", log_title);
53 p += sprintf(p, "[%d] ", log_pid);
57 l = vsnprintf(p, r, msg, args);
64 if (*p < 0x20 && *p != '\t')
69 write(2, buf, l + l0);
77 log_msg(unsigned int cat, const char *msg, ...)
82 vlog_msg(cat, msg, args);
92 vlog_msg(L_FATAL, msg, args);
96 #ifdef DEBUG_DIE_BY_ABORT
105 assert_failed(char *assertion, char *file, int line)
107 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
114 die("Internal error: Assertion failed.");
119 log_basename(byte *n)
130 log_init(byte *argv0)
134 strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
135 log_progname[sizeof(log_progname)-1] = 0;
136 log_title = log_progname;