From 70360c5c0759ab7b4a3a9d7194fa21094c5a47be Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 28 Jul 2016 22:15:14 -0400 Subject: Add timestamp to log messages --- common/log.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common/log.c') diff --git a/common/log.c b/common/log.c index 6f9fb07e..1da2ba2f 100644 --- a/common/log.c +++ b/common/log.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,20 @@ void sway_abort(const char *format, ...) { void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { if (verbosity <= v) { + // prefix the time to the log message + static struct tm result; + static time_t t; + static struct tm *tm_info; + char buffer[26]; + + // get current time + t = time(NULL); + // convert time to local time (determined by the locale) + tm_info = localtime_r(&t, &result); + // generate time prefix + strftime(buffer, sizeof(buffer), "%x %X - ", tm_info); + fprintf(stderr, "%s", buffer); + unsigned int c = verbosity; if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; -- cgit v1.2.3