2 * UCW Library -- Logging
4 * (c) 1997--2006 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 int log_precise_timings;
25 void (*log_die_hook)(void);
26 void (*log_switch_hook)(struct tm *tm);
29 vlog_msg(unsigned int cat, const char *msg, va_list args)
38 gettimeofday(&tv, NULL);
39 if (!localtime_r(&tv.tv_sec, &tm))
40 bzero(&tm, sizeof(tm));
46 p = buf = alloca(buflen);
48 p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S", &tm);
49 if (log_precise_timings)
50 p += sprintf(p, ".%06d", (int)tv.tv_usec);
55 p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
57 p += sprintf(p, "[%s] ", log_title);
62 p += sprintf(p, "[%d] ", log_pid);
67 l = vsnprintf(p, r, msg, args2);
75 if (*p < 0x20 && *p != '\t')
80 write(2, buf, l + l0);
88 log_msg(unsigned int cat, const char *msg, ...)
93 vlog_msg(cat, msg, args);
98 die(const char *msg, ...)
103 vlog_msg(L_FATAL, msg, args);
107 #ifdef DEBUG_DIE_BY_ABORT
115 assert_failed(char *assertion, char *file, int line)
117 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
122 assert_failed_noinfo(void)
124 die("Internal error: Assertion failed.");
128 log_basename(byte *n)
139 log_init(byte *argv0)
143 strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
144 log_progname[sizeof(log_progname)-1] = 0;
145 log_title = log_progname;