aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2020-12-10 09:26:02 +0100
committerLibravatar Simon Ser <contact@emersion.fr>2020-12-10 09:26:02 +0100
commit1dbb6990360ad45d7189d267e1c288b8cf38b4d1 (patch)
tree10b9310806803195a22b66b1f44f241dbf8689d3
parentRoute wlroots logs into Sway logging infrastructure (diff)
downloadsway-1dbb6990360ad45d7189d267e1c288b8cf38b4d1.tar.gz
sway-1dbb6990360ad45d7189d267e1c288b8cf38b4d1.tar.zst
sway-1dbb6990360ad45d7189d267e1c288b8cf38b4d1.zip
common/log: write log importance
When colors aren't used, write the log importance to stderr. This makes it easier to grep for errors and avoids mistaking error messages for debug messages. This is [1] ported to Sway. [1]: https://github.com/swaywm/wlroots/pull/2149
-rw-r--r--common/log.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/common/log.c b/common/log.c
index 2acf2e57..483420e7 100644
--- a/common/log.c
+++ b/common/log.c
@@ -45,6 +45,13 @@ static const char *verbosity_colors[] = {
45 [SWAY_DEBUG ] = "\x1B[1;90m", 45 [SWAY_DEBUG ] = "\x1B[1;90m",
46}; 46};
47 47
48static const char *verbosity_headers[] = {
49 [SWAY_SILENT] = "",
50 [SWAY_ERROR] = "[ERROR]",
51 [SWAY_INFO] = "[INFO]",
52 [SWAY_DEBUG] = "[DEBUG]",
53};
54
48static void timespec_sub(struct timespec *r, const struct timespec *a, 55static void timespec_sub(struct timespec *r, const struct timespec *a,
49 const struct timespec *b) { 56 const struct timespec *b) {
50 const long NSEC_PER_SEC = 1000000000; 57 const long NSEC_PER_SEC = 1000000000;
@@ -84,6 +91,8 @@ static void sway_log_stderr(sway_log_importance_t verbosity, const char *fmt,
84 91
85 if (colored && isatty(STDERR_FILENO)) { 92 if (colored && isatty(STDERR_FILENO)) {
86 fprintf(stderr, "%s", verbosity_colors[c]); 93 fprintf(stderr, "%s", verbosity_colors[c]);
94 } else {
95 fprintf(stderr, "%s ", verbosity_headers[c]);
87 } 96 }
88 97
89 vfprintf(stderr, fmt, args); 98 vfprintf(stderr, fmt, args);