diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-07-26 16:50:35 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-07-26 16:56:21 +0200 |
commit | 498261871dfa2a930ec84b13a176e3bdc43aa212 (patch) | |
tree | 842bc005ca763ddc075ded82b0b74ec80f35d05e /src/shared | |
parent | 46b0d922256b62bc8291951d9868c243ced80c9a (diff) |
journalctl: hightlight log lines by priority
warn/notice = bright white
< error = red
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/logs-show.c | 33 | ||||
-rw-r--r-- | src/shared/logs-show.h | 9 |
2 files changed, 32 insertions, 10 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 375ca543c1..c72ebc11f5 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -82,13 +82,21 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns, const void *data; size_t length; size_t n = 0; - char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL; - size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0; + char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *fake_pid = NULL, *message = NULL, *realtime = NULL, *monotonic = NULL, *priority = NULL; + size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, fake_pid_len = 0, message_len = 0, realtime_len = 0, monotonic_len = 0, priority_len = 0; + int p = LOG_INFO; + const char *color_on = "", *color_off = ""; assert(j); SD_JOURNAL_FOREACH_DATA(j, data, length) { + r = parse_field(data, length, "PRIORITY=", &priority, &priority_len); + if (r < 0) + goto finish; + else if (r > 0) + continue; + r = parse_field(data, length, "_HOSTNAME=", &hostname, &hostname_len); if (r < 0) goto finish; @@ -141,6 +149,9 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns, goto finish; } + if (priority_len == 1 && *priority >= '0' && *priority <= '7') + p = *priority - '0'; + if (flags & OUTPUT_MONOTONIC_MODE) { uint64_t t; sd_id128_t boot_id; @@ -219,23 +230,33 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns, n += fake_pid_len + 2; } + if (flags & OUTPUT_COLOR) { + if (p <= LOG_ERR) { + color_on = ANSI_HIGHLIGHT_RED_ON; + color_off = ANSI_HIGHLIGHT_OFF; + } else if (p <= LOG_NOTICE) { + color_on = ANSI_HIGHLIGHT_ON; + color_off = ANSI_HIGHLIGHT_OFF; + } + } + if (flags & OUTPUT_SHOW_ALL) - printf(": %.*s\n", (int) message_len, message); + printf(": %s%.*s%s\n", color_on, (int) message_len, message, color_off); else if (!utf8_is_printable_n(message, message_len)) { char bytes[FORMAT_BYTES_MAX]; printf(": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len)); } else if ((flags & OUTPUT_FULL_WIDTH) || (message_len + n < n_columns)) - printf(": %.*s\n", (int) message_len, message); + printf(": %s%.*s%s\n", color_on, (int) message_len, message, color_off); else if (n < n_columns && n_columns - n - 2 >= 3) { char *e; e = ellipsize_mem(message, message_len, n_columns - n - 2, 90); if (!e) - printf(": %.*s\n", (int) message_len, message); + printf(": %s%.*s%s\n", color_on, (int) message_len, message, color_off); else - printf(": %s\n", e); + printf(": %s%s%s\n", color_on, e, color_off); free(e); } else diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 4e6743254b..58ff9e5760 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -39,11 +39,12 @@ typedef enum OutputMode { } OutputMode; typedef enum OutputFlags { - OUTPUT_SHOW_ALL = 1 << 0, + OUTPUT_SHOW_ALL = 1 << 0, OUTPUT_MONOTONIC_MODE = 1 << 1, - OUTPUT_FOLLOW = 1 << 2, - OUTPUT_WARN_CUTOFF = 1 << 3, - OUTPUT_FULL_WIDTH = 1 << 4, + OUTPUT_FOLLOW = 1 << 2, + OUTPUT_WARN_CUTOFF = 1 << 3, + OUTPUT_FULL_WIDTH = 1 << 4, + OUTPUT_COLOR = 1 << 5 } OutputFlags; int output_journal(sd_journal *j, OutputMode mode, unsigned line, |