]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logs: when embedding catalog info in log output use a dash of color and unicode
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Jul 2020 09:25:18 +0000 (11:25 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Jul 2020 07:32:03 +0000 (09:32 +0200)
let's separate things out a bit, to make it easier to discern log output
and catalog data.

catalog data is now colored green (which is a color we don't use for log
data currently), and prefixed with a block shade.

src/shared/logs-show.c

index fee6ccdf2a1e3f7040b4dd7dbe4ca8ae9f8a7718..899e894ab7e9fad318710aef15bcdc893849acfb 100644 (file)
@@ -50,6 +50,7 @@
 
 static int print_catalog(FILE *f, sd_journal *j) {
         _cleanup_free_ char *t = NULL, *z = NULL;
+        const char *newline, *prefix;
         int r;
 
         assert(j);
@@ -60,13 +61,31 @@ static int print_catalog(FILE *f, sd_journal *j) {
         if (r < 0)
                 return log_error_errno(r, "Failed to find catalog entry: %m");
 
-        z = strreplace(strstrip(t), "\n", "\n-- ");
+        if (is_locale_utf8())
+                prefix = strjoina(special_glyph(SPECIAL_GLYPH_LIGHT_SHADE), special_glyph(SPECIAL_GLYPH_LIGHT_SHADE));
+        else
+                prefix = "--";
+
+        if (colors_enabled())
+                newline = strjoina(ANSI_NORMAL "\n" ANSI_GREY, prefix, ANSI_NORMAL " " ANSI_GREEN);
+        else
+                newline = strjoina("\n", prefix, " ");
+
+        z = strreplace(strstrip(t), "\n", newline);
         if (!z)
                 return log_oom();
 
-        fputs("-- ", f);
+        if (colors_enabled())
+                fprintf(f, ANSI_GREY "%s" ANSI_NORMAL " " ANSI_GREEN, prefix);
+        else
+                fprintf(f, "%s ", prefix);
+
         fputs(z, f);
-        fputc('\n', f);
+
+        if (colors_enabled())
+                fputs(ANSI_NORMAL "\n", f);
+        else
+                fputc('\n', f);
 
         return 1;
 }