]> mj.ucw.cz Git - libucw.git/blobdiff - lib/log.c
Yet another bug in the pattern matcher fixed.
[libucw.git] / lib / log.c
index 267270aa5c783f64c6209c87fc540d9c3348f4e1..f17b8d9be616edb32066d49e489bb33ef478e22b 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
 
@@ -24,7 +25,7 @@ logit(int level, byte *msg, va_list args)
 
   tim = time(NULL);
   tm = localtime(&tim);
-  strftime(buf, sizeof(buf), "%d-%m-%y %H-%M-%S", tm);
+  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);
@@ -72,6 +73,21 @@ basename(byte *n)
 void
 initlog(byte *argv0)
 {
-  progname = basename(argv0);
+  if (argv0)
+    progname = basename(argv0);
   pid = getpid();
 }
+
+void
+open_log_file(byte *name)
+{
+  if (name)
+    {
+      int fd = open(name, O_WRONLY | O_CREAT | O_APPEND, 0666);
+      if (fd < 0)
+       die("Unable to open log file");
+      close(2);
+      dup(fd);
+      close(fd);
+    }
+}