- tim = time(NULL);
- tm = localtime(&tim);
- strftime(buf, sizeof(buf), "%d-%m-%y %H:%M:%S", tm);
- fprintf(stderr, "%s %s [%d] <%d> ", buf, progname, pid, level);
- vfprintf(stderr, msg, args);
- fputc('\n', stderr);
- fflush(stderr);
+ if (log_switch_hook)
+ log_switch_hook(tm);
+ while (1)
+ {
+ p = buf = alloca(buflen);
+ *p++ = cat;
+ p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S ", tm);
+ if (log_title)
+ {
+ if (log_pid)
+ p += sprintf(p, "[%s (%d)] ", log_title, log_pid);
+ else
+ p += sprintf(p, "[%s] ", log_title);
+ }
+ else
+ {
+ if (log_pid)
+ p += sprintf(p, "[%d] ", log_pid);
+ }
+ l0 = p - buf + 1;
+ r = buflen - l0;
+ l = vsnprintf(p, r, msg, args);
+ if (l < 0)
+ l = r;
+ else if (l < r)
+ {
+ while (*p)
+ {
+ if (*p < 0x20 && *p != '\t')
+ *p = 0x7f;
+ p++;
+ }
+ *p = '\n';
+ write(2, buf, l + l0);
+ return;
+ }
+ buflen = l + l0 + 1;
+ }