From: Joel Rosdahl Date: Mon, 10 May 2010 20:02:59 +0000 (+0200) Subject: Prefix each log row with a timestamp X-Git-Tag: v3.0pre1~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a79364bca7e84dd077c696efb10504b5296c376;p=thirdparty%2Fccache.git Prefix each log row with a timestamp --- diff --git a/ccache.c b/ccache.c index a4f0c3e8d..3c6c9449d 100644 --- 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); diff --git a/configure.ac b/configure.ac index aea882258..585ba46f7 100644 --- a/configure.ac +++ b/configure.ac @@ -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 f184ecc9e..2330d0a80 100644 --- a/util.c +++ b/util.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #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 } /*