Browse code

Restore log colors under devstack/systemd

One of the pending issues with the conversion to systemd was the loss of
log coloring. It turns out that journalctl by default strips out
characters it considers "unprintable" - including the color codes
emitted by the old-style logging. However, journalctl can be made to
print them by adding the `-a` flag.

This change makes devstack's log formatter conf settings include color
codes like the old screen-based setup used to

We also remove stackrc's setting of JOURNALCTL_F, whose usage was
removed via I6af6d1857effaf662a9d72bd394864934eacbe70.

Change-Id: I2401e267913a24d18dae355aa933072dbbdab1d8

Eric Fried authored on 2017/05/17 03:52:03
Showing 3 changed files
... ...
@@ -109,6 +109,17 @@ Use higher precision time stamps::
109 109
 
110 110
   journalctl -f -o short-precise --unit devstack@n-cpu.service
111 111
 
112
+By default, journalctl strips out "unprintable" characters, including
113
+ASCII color codes. To keep the color codes (which can be interpreted by
114
+an appropriate terminal/pager - e.g. ``less``, the default)::
115
+
116
+  journalctl -a --unit devstack@n-cpu.service
117
+
118
+When outputting to the terminal using the default pager, long lines
119
+appear to be truncated, but horizontal scrolling is supported via the
120
+left/right arrow keys.
121
+
122
+See ``man 1 journalctl`` for more.
112 123
 
113 124
 Known Issues
114 125
 ============
... ...
@@ -137,13 +148,6 @@ system units.
137 137
 Future Work
138 138
 ===========
139 139
 
140
-log colorizing
141
-
142
-We lose log colorization through this process. We might want to build
143
-a custom colorizer that we could run journalctl output through
144
-optionally for people.
145
-
146 140
 user units
147 141
 ----------
148 142
 
... ...
@@ -616,21 +616,18 @@ function setup_systemd_logging {
616 616
     # request-id. However, there may be an eventlet interaction here,
617 617
     # so going off for now.
618 618
     USE_JOURNAL=$(trueorfalse USE_JOURNAL False)
619
+    local pidstr=""
619 620
     if [[ "$USE_JOURNAL" == "True" ]]; then
620 621
         iniset $conf_file $conf_section use_journal "True"
621 622
         # if we are using the journal directly, our process id is already correct
622
-        iniset $conf_file $conf_section logging_debug_format_suffix \
623
-               "{{%(funcName)s %(pathname)s:%(lineno)d}}"
624 623
     else
625
-        iniset $conf_file $conf_section logging_debug_format_suffix \
626
-               "{{(pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d}}"
624
+        pidstr="(pid=%(process)d) "
627 625
     fi
626
+    iniset $conf_file $conf_section logging_debug_format_suffix "{{${pidstr}%(funcName)s %(pathname)s:%(lineno)d}}"
628 627
 
629
-    iniset $conf_file $conf_section logging_context_format_string \
630
-           "%(levelname)s %(name)s [%(request_id)s %(project_name)s %(user_name)s] %(instance)s%(message)s"
631
-    iniset $conf_file $conf_section logging_default_format_string \
632
-           "%(levelname)s %(name)s [-] %(instance)s%(color)s%(message)s"
633
-    iniset $conf_file $conf_section logging_exception_prefix "ERROR %(name)s %(instance)s"
628
+    iniset $conf_file $conf_section logging_context_format_string "%(color)s%(levelname)s %(name)s [%(request_id)s %(project_name)s %(user_name)s%(color)s] %(instance)s%(color)s%(message)s"
629
+    iniset $conf_file $conf_section logging_default_format_string "%(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s"
630
+    iniset $conf_file $conf_section logging_exception_prefix "ERROR %(name)s %(instance)s"
634 631
 }
635 632
 
636 633
 function setup_standard_logging_identity {
... ...
@@ -100,11 +100,9 @@ USER_UNITS=$(trueorfalse False USER_UNITS)
100 100
 if [[ "$USER_UNITS" == "True" ]]; then
101 101
     SYSTEMD_DIR="$HOME/.local/share/systemd/user"
102 102
     SYSTEMCTL="systemctl --user"
103
-    JOURNALCTL_F="journalctl -f -o short-precise --user-unit"
104 103
 else
105 104
     SYSTEMD_DIR="/etc/systemd/system"
106 105
     SYSTEMCTL="sudo systemctl"
107
-    JOURNALCTL_F="journalctl -f -o short-precise --unit"
108 106
 fi
109 107
 
110 108