2 * UCW 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.
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);
39 p = buf = alloca(buflen);
41 p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm);
45 p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
47 p += sprintf(p, "[%s] ", log_title);
52 p += sprintf(p, "[%d] ", log_pid);
56 l = vsnprintf(p, r, msg, args);
63 if (*p < 0x20 && *p != '\t')
68 write(2, buf, l + l0);
76 log_msg(unsigned int cat, const char *msg, ...)
81 vlog_msg(cat, msg, args);
91 vlog_msg(L_FATAL, msg, args);
95 #ifdef DEBUG_DIE_BY_ABORT
103 assert_failed(char *assertion, char *file, int line)
105 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
110 assert_failed_noinfo(void)
112 die("Internal error: Assertion failed.");
116 log_basename(byte *n)
127 log_init(byte *argv0)
131 strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
132 log_progname[sizeof(log_progname)-1] = 0;
133 log_title = log_progname;