chiark / gitweb /
journalctl: highlight MESSAGE= in verbose output
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 26 Jun 2013 23:48:24 +0000 (19:48 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 26 Jun 2013 23:52:00 +0000 (19:52 -0400)
When looking at verbose output, additional "work" is required to
pick out the interesting MESSAGE= lines from all the fields.

Also, show long fields in full in verbose output mode when
OUTPUT_FULL_WIDTH is specified.

src/shared/logs-show.c

index 91b2bec..8dc11bb 100644 (file)
@@ -357,6 +357,8 @@ static int output_verbose(
         JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
                 const char *c;
                 int fieldlen;
+                const char *on = "", *off = "";
+
                 c = memchr(data, '=', length);
                 if (!c) {
                         log_error("Invalid field.");
@@ -364,16 +366,25 @@ static int output_verbose(
                 }
                 fieldlen = c - (const char*) data;
 
-                if ((flags & OUTPUT_SHOW_ALL) || (length < PRINT_THRESHOLD && utf8_is_printable(data, length))) {
-                        fprintf(f, "    %.*s=", fieldlen, (const char*)data);
+                if (flags & OUTPUT_COLOR && startswith(data, "MESSAGE=")) {
+                        on = ANSI_HIGHLIGHT_ON;
+                        off = ANSI_HIGHLIGHT_OFF;
+                }
+
+                if (flags & OUTPUT_SHOW_ALL ||
+                    (((length < PRINT_THRESHOLD) || flags & OUTPUT_FULL_WIDTH) && utf8_is_printable(data, length))) {
+                        fprintf(f, "    %s%.*s=", on, fieldlen, (const char*)data);
                         print_multiline(f, 4 + fieldlen + 1, 0, OUTPUT_FULL_WIDTH, 0, c + 1, length - fieldlen - 1);
+                        fputs(off, f);
                 } else {
                         char bytes[FORMAT_BYTES_MAX];
 
-                        fprintf(f, "    %.*s=[%s blob data]\n",
+                        fprintf(f, "    %s%.*s=[%s blob data]%s\n",
+                                on,
                                 (int) (c - (const char*) data),
                                 (const char*) data,
-                                format_bytes(bytes, sizeof(bytes), length - (c - (const char *) data) - 1));
+                                format_bytes(bytes, sizeof(bytes), length - (c - (const char *) data) - 1),
+                                off);
                 }
         }