]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Prefix each log row with a timestamp
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 20:02:59 +0000 (22:02 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 10 May 2010 20:02:59 +0000 (22:02 +0200)
ccache.c
configure.ac
util.c

index a4f0c3e8da3af5589fc8f2b110ec38c6f263fffa..3c6c9449d53c0bac4d3991737e4eca298680b378 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1607,9 +1607,6 @@ static void process_args(int argc, char **argv, ARGS **preprocessor_args,
 /* the main ccache driver function */
 static void ccache(int argc, char *argv[])
 {
-       char now[64];
-       time_t t;
-       struct tm *tm;
        int put_object_in_manifest = 0;
        struct file_hash *object_hash;
        struct file_hash *object_hash_from_manifest = NULL;
@@ -1624,19 +1621,7 @@ static void ccache(int argc, char *argv[])
        /* Arguments to send to the real compiler. */
        ARGS *compiler_args;
 
-       t = time(NULL);
-       tm = localtime(&t);
-       if (!tm) {
-               cc_log("localtime failed");
-               failed();
-       }
-
-       if (strftime(now, sizeof(now), "%Y-%m-%d %H:%M:%S", tm) == 0) {
-               cc_log("strftime failed");
-               failed();
-       }
-
-       cc_log("=== %s ===", now);
+       cc_log("=== CCACHE STARTED =========================================");
 
        if (base_dir) {
                cc_log("Base directory: %s", base_dir);
index aea882258a022cecaf925af0e9c7cab43bba71dc..585ba46f7102994e5a251cbb4bf2c0e4c5d566ac 100644 (file)
@@ -47,6 +47,7 @@ AC_CHECK_HEADERS(ctype.h pwd.h stdlib.h string.h strings.h sys/time.h)
 AC_CHECK_FUNCS(asprintf)
 AC_CHECK_FUNCS(gethostname)
 AC_CHECK_FUNCS(getpwuid)
+AC_CHECK_FUNCS(gettimeofday)
 AC_CHECK_FUNCS(mkstemp)
 AC_CHECK_FUNCS(realpath)
 AC_CHECK_FUNCS(snprintf)
diff --git a/util.c b/util.c
index f184ecc9e3f766ce434bbabe109aa9c4bd4eda01..2330d0a809d16cad9ac71451d50c6cd09e293287 100644 (file)
--- a/util.c
+++ b/util.c
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <zlib.h>
 
 #ifdef HAVE_PWD_H
@@ -62,7 +63,18 @@ static int init_log(void)
 
 static void log_prefix(void)
 {
+#ifdef HAVE_GETTIMEOFDAY
+       char timestamp[100];
+       struct timeval tv;
+       struct tm *tm;
+
+       gettimeofday(&tv, NULL);
+       tm = localtime(&tv.tv_sec);
+       strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm);
+       fprintf(logfile, "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, getpid());
+#else
        fprintf(logfile, "[%-5d] ", getpid());
+#endif
 }
 
 /*