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 /* We cannot use strftime() here, because it's not re-entrant */
49 p += sprintf(p, " %4d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
50 tm.tm_hour, tm.tm_min, tm.tm_sec);
51 if (log_precise_timings)
52 p += sprintf(p, ".%06d", (int)tv.tv_usec);
57 p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
59 p += sprintf(p, "[%s] ", log_title);
64 p += sprintf(p, "[%d] ", log_pid);
69 l = vsnprintf(p, r, msg, args2);
77 if (*p < 0x20 && *p != '\t')
82 write(2, buf, l + l0);
90 log_msg(unsigned int cat, const char *msg, ...)
95 vlog_msg(cat, msg, args);
100 die(const char *msg, ...)
105 vlog_msg(L_FATAL, msg, args);
109 #ifdef DEBUG_DIE_BY_ABORT
117 assert_failed(char *assertion, char *file, int line)
119 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
124 assert_failed_noinfo(void)
126 die("Internal error: Assertion failed.");
130 log_basename(byte *n)
141 log_init(byte *argv0)
145 strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
146 log_progname[sizeof(log_progname)-1] = 0;
147 log_title = log_progname;