2 * UCW Library -- Logging
4 * (c) 1997--2005 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.
19 static char log_progname[32];
23 void (*log_die_hook)(void);
24 void (*log_switch_hook)(struct tm *tm);
27 vlog_msg(unsigned int cat, const char *msg, va_list args)
29 time_t tim = time(NULL);
30 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);
58 l = vsnprintf(p, r, msg, args2);
66 if (*p < 0x20 && *p != '\t')
71 write(2, buf, l + l0);
79 log_msg(unsigned int cat, const char *msg, ...)
84 vlog_msg(cat, msg, args);
89 die(const char *msg, ...)
94 vlog_msg(L_FATAL, msg, args);
98 #ifdef DEBUG_DIE_BY_ABORT
106 assert_failed(char *assertion, char *file, int line)
108 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
113 assert_failed_noinfo(void)
115 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;