aboutsummaryrefslogtreecommitdiff
path: root/common/log.c
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2020-12-10 09:26:02 +0100
committerFurkan Sahin <furkan-dev@proton.me>2020-12-10 09:26:02 +0100
commit11f5b3be367b564677370d08c7fd6401072cdab2 (patch)
tree10b9310806803195a22b66b1f44f241dbf8689d3 /common/log.c
parent75862ceca5ef46ca7d7ab8a0f372071e89bf6601 (diff)
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
Diffstat (limited to 'common/log.c')
-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[] = {
[SWAY_DEBUG ] = "\x1B[1;90m",
};
+static const char *verbosity_headers[] = {
+ [SWAY_SILENT] = "",
+ [SWAY_ERROR] = "[ERROR]",
+ [SWAY_INFO] = "[INFO]",
+ [SWAY_DEBUG] = "[DEBUG]",
+};
+
static void timespec_sub(struct timespec *r, const struct timespec *a,
const struct timespec *b) {
const long NSEC_PER_SEC = 1000000000;
@@ -84,6 +91,8 @@ static void sway_log_stderr(sway_log_importance_t verbosity, const char *fmt,
if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "%s", verbosity_colors[c]);
+ } else {
+ fprintf(stderr, "%s ", verbosity_headers[c]);
}
vfprintf(stderr, fmt, args);