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);
36 if (!localtime_r(&tim, &tm))
37 bzero(&tm, sizeof(tm));
43 p = buf = alloca(buflen);
45 p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", &tm);
49 p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
51 p += sprintf(p, "[%s] ", log_title);
56 p += sprintf(p, "[%d] ", log_pid);
61 l = vsnprintf(p, r, msg, args2);
69 if (*p < 0x20 && *p != '\t')
74 write(2, buf, l + l0);
82 log_msg(unsigned int cat, const char *msg, ...)
87 vlog_msg(cat, msg, args);
92 die(const char *msg, ...)
97 vlog_msg(L_FATAL, msg, args);
101 #ifdef DEBUG_DIE_BY_ABORT
109 assert_failed(char *assertion, char *file, int line)
111 log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
116 assert_failed_noinfo(void)
118 die("Internal error: Assertion failed.");
122 log_basename(byte *n)
133 log_init(byte *argv0)
137 strncpy(log_progname, log_basename(argv0), sizeof(log_progname)-1);
138 log_progname[sizeof(log_progname)-1] = 0;
139 log_title = log_progname;