aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-01 16:21:57 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-01 16:45:57 +0200
commit904312a0b27bf51cb636ec3d5caae85b062017a2 (patch)
tree3b4d48f688437a1b34128a8964563afc118892a7
parent044a9f28d681408d805a8bcc02ec47050cb1eb85 (diff)
util/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.
-rw-r--r--util/log.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/util/log.c b/util/log.c
index a7bab356..7f27b5eb 100644
--- a/util/log.c
+++ b/util/log.c
@@ -15,9 +15,16 @@ static struct timespec start_time = {-1};
static const char *verbosity_colors[] = {
[WLR_SILENT] = "",
- [WLR_ERROR ] = "\x1B[1;31m",
- [WLR_INFO ] = "\x1B[1;34m",
- [WLR_DEBUG ] = "\x1B[1;30m",
+ [WLR_ERROR] = "\x1B[1;31m",
+ [WLR_INFO] = "\x1B[1;34m",
+ [WLR_DEBUG] = "\x1B[1;30m",
+};
+
+static const char *verbosity_headers[] = {
+ [WLR_SILENT] = "",
+ [WLR_ERROR] = "[ERROR]",
+ [WLR_INFO] = "[INFO]",
+ [WLR_DEBUG] = "[DEBUG]",
};
static void timespec_sub(struct timespec *r, const struct timespec *a,
@@ -58,6 +65,8 @@ static void log_stderr(enum wlr_log_importance 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);