diff options
author | 2016-07-28 22:21:01 -0400 | |
---|---|---|
committer | 2016-07-28 22:21:01 -0400 | |
commit | ddb44984c5f3aede3eea45403659e5614a7b752f (patch) | |
tree | cefdc717973d9b9b939f977d791528310ac51886 /common/log.c | |
parent | Merge pull request #800 from zandrmartin/fix-swaybar-take-3 (diff) | |
parent | Add timestamp to log messages (diff) | |
download | sway-ddb44984c5f3aede3eea45403659e5614a7b752f.tar.gz sway-ddb44984c5f3aede3eea45403659e5614a7b752f.tar.zst sway-ddb44984c5f3aede3eea45403659e5614a7b752f.zip |
Merge pull request #802 from acrisci/feature/timestamp-log-messages
Add timestamp to log messages
Diffstat (limited to 'common/log.c')
-rw-r--r-- | common/log.c | 15 |
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 | ||
66 | void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { | 67 | void _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; |