X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/093ec8103f8de58d890a77b458985ecf4293bfa7..0e8c21de2a464fc913e0dbb6f7f148a84db95d55:/lib/log.c?ds=sidebyside diff --git a/lib/log.c b/lib/log.c index 3f57073..00ec7cd 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; @@ -119,7 +123,15 @@ static void logfp(int pri, const char *msg, void *user) { * sanely */ const char *p; - if(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(progname) fprintf(fp, "%s: ", progname); if(pri <= LOG_ERR) fputs("ERROR: ", fp);