aboutsummaryrefslogtreecommitdiffstats
path: root/common/log.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2016-07-28 22:15:14 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2016-07-28 22:15:14 -0400
commit70360c5c0759ab7b4a3a9d7194fa21094c5a47be (patch)
treecefdc717973d9b9b939f977d791528310ac51886 /common/log.c
parentMerge pull request #800 from zandrmartin/fix-swaybar-take-3 (diff)
downloadsway-70360c5c0759ab7b4a3a9d7194fa21094c5a47be.tar.gz
sway-70360c5c0759ab7b4a3a9d7194fa21094c5a47be.tar.zst
sway-70360c5c0759ab7b4a3a9d7194fa21094c5a47be.zip
Add timestamp to log messages
Diffstat (limited to 'common/log.c')
-rw-r--r--common/log.c15
1 files changed, 15 insertions, 0 deletions
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 @@
8#include <fcntl.h> 8#include <fcntl.h>
9#include <unistd.h> 9#include <unistd.h>
10#include <signal.h> 10#include <signal.h>
11#include <time.h>
11#include <errno.h> 12#include <errno.h>
12#include <string.h> 13#include <string.h>
13#include <stringop.h> 14#include <stringop.h>
@@ -65,6 +66,20 @@ void sway_abort(const char *format, ...) {
65 66
66void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { 67void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
67 if (verbosity <= v) { 68 if (verbosity <= v) {
69 // prefix the time to the log message
70 static struct tm result;
71 static time_t t;
72 static struct tm *tm_info;
73 char buffer[26];
74
75 // get current time
76 t = time(NULL);
77 // convert time to local time (determined by the locale)
78 tm_info = localtime_r(&t, &result);
79 // generate time prefix
80 strftime(buffer, sizeof(buffer), "%x %X - ", tm_info);
81 fprintf(stderr, "%s", buffer);
82
68 unsigned int c = verbosity; 83 unsigned int c = verbosity;
69 if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) { 84 if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
70 c = sizeof(verbosity_colors) / sizeof(char *) - 1; 85 c = sizeof(verbosity_colors) / sizeof(char *) - 1;