]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log.c
Introduced obuck_get_pos(), converted gatherd limits to use it.
[libucw.git] / lib / log.c
index 97b46713b86845e20fd89ca0ecb1fee9659e1656..16fe4e227f2ef574111953b836075df70fe858f7 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
 #include <stdarg.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <sys/time.h>
+#include <time.h>
 
-static byte *log_progname;
+static char *log_progname;
 static pid_t log_pid;
 
+void
+log_fork(void)
+{
+  log_pid = getpid();
+}
+
 static void
-vlog(unsigned int cat, byte *msg, va_list args)
+vlog(unsigned int cat, const char *msg, va_list args)
 {
   time_t tim = time(NULL);
   struct tm *tm = localtime(&tim);
   char buf[32];
 
-  if (!log_pid)
-    log_pid = getpid();
   strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
   fprintf(stderr, "%c %s ", cat, buf);
   if (log_progname)
-    fprintf(stderr, "[%s (%d)] ", log_progname, log_pid);
+    {
+      if (log_pid)
+       fprintf(stderr, "[%s (%d)] ", log_progname, log_pid);
+      else
+       fprintf(stderr, "[%s] ", log_progname);
+    }
+  else
+    {
+      if (log_pid)
+       fprintf(stderr, "[%d] ", log_pid);
+    }
   vfprintf(stderr, msg, args);
   fputc('\n', stderr);
   fflush(stderr);
 }
 
 void
-log(unsigned int cat, byte *msg, ...)
+log(unsigned int cat, const char *msg, ...)
 {
   va_list args;