X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/d3676ebc9f29f52b68eb1beb794cf710e04dcad6..9d7a61297cb7263160d85a12d445fc1897fbfa80:/lib/log.c diff --git a/lib/log.c b/lib/log.c index 3f57073..95a89a1 100644 --- a/lib/log.c +++ b/lib/log.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "log.h" #include "disorder.h" @@ -66,6 +67,9 @@ const char *progname; /** @brief Filename for debug messages */ const char *debug_filename; +/** @brief Set to include timestamps in log messages */ +int logdate; + /** @brief Line number for debug messages */ int debug_lineno; @@ -121,6 +125,14 @@ static void logfp(int pri, const char *msg, void *user) { if(progname) fprintf(fp, "%s: ", progname); + if(logdate) { + char timebuf[64]; + struct tm *tm; + gettimeofday(&tv, 0); + tm = localtime(&tv.tv_sec); + strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S %Z", tm); + fprintf(fp, "%s: ", timebuf); + } if(pri <= LOG_ERR) fputs("ERROR: ", fp); else if(pri < LOG_DEBUG)