From c1de7286d7c9fb23a2621d49380537b923d07d27 Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 30 Jul 2014 19:12:09 +1000 Subject: [PATCH] ckpool - add timestamps to screen log --- src/ckpool.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 935ab668..b4fbd941 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -42,6 +42,7 @@ void logmsg(int loglevel, const char *fmt, ...) { struct tm *tm; time_t now_t; va_list ap; + char stamp[128]; va_start(ap, fmt); VASPRINTF(&buf, fmt, ap); @@ -49,18 +50,18 @@ void logmsg(int loglevel, const char *fmt, ...) { now_t = time(NULL); tm = localtime(&now_t); - if (logfd) { - FILE *LOGFP = global_ckp->logfp; - - flock(logfd, LOCK_EX); - fprintf(LOGFP, "[%d-%02d-%02d %02d:%02d:%02d] %s", + sprintf(stamp, "[%d-%02d-%02d %02d:%02d:%02d]", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, - tm->tm_sec, - buf); + tm->tm_sec); + if (logfd) { + FILE *LOGFP = global_ckp->logfp; + + flock(logfd, LOCK_EX); + fprintf(LOGFP, "%s %s", stamp, buf); if (loglevel <= LOG_ERR && errno != 0) fprintf(LOGFP, " with errno %d: %s", errno, strerror(errno)); fprintf(LOGFP, "\n"); @@ -68,9 +69,9 @@ void logmsg(int loglevel, const char *fmt, ...) { } if (loglevel <= LOG_WARNING) {\ if (loglevel <= LOG_ERR && errno != 0) - fprintf(stderr, "%s with errno %d: %s\n", buf, errno, strerror(errno)); + fprintf(stderr, "%s %s with errno %d: %s\n", stamp, buf, errno, strerror(errno)); else - fprintf(stderr, "%s\n", buf); + fprintf(stderr, "%s %s\n", stamp, buf); fflush(stderr); } free(buf);