From 8cd310d7638843f07f4c88adaf3aed9db7668073 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Tue, 16 May 2017 13:52:03 -0500 Subject: [PATCH] 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 --- doc/source/systemd.rst | 18 +++++++++++------- functions | 15 ++++++--------- stackrc | 2 -- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/doc/source/systemd.rst b/doc/source/systemd.rst index efe79e4b0c..60a7719262 100644 --- a/doc/source/systemd.rst +++ b/doc/source/systemd.rst @@ -109,6 +109,17 @@ Use higher precision time stamps:: journalctl -f -o short-precise --unit devstack@n-cpu.service +By default, journalctl strips out "unprintable" characters, including +ASCII color codes. To keep the color codes (which can be interpreted by +an appropriate terminal/pager - e.g. ``less``, the default):: + + journalctl -a --unit devstack@n-cpu.service + +When outputting to the terminal using the default pager, long lines +appear to be truncated, but horizontal scrolling is supported via the +left/right arrow keys. + +See ``man 1 journalctl`` for more. Known Issues ============ @@ -137,13 +148,6 @@ system units. Future Work =========== -log colorizing --------------- - -We lose log colorization through this process. We might want to build -a custom colorizer that we could run journalctl output through -optionally for people. - user units ---------- diff --git a/functions b/functions index f842f63038..9bb64cc3c4 100644 --- a/functions +++ b/functions @@ -616,21 +616,18 @@ function setup_systemd_logging { # request-id. However, there may be an eventlet interaction here, # so going off for now. USE_JOURNAL=$(trueorfalse USE_JOURNAL False) + local pidstr="" if [[ "$USE_JOURNAL" == "True" ]]; then iniset $conf_file $conf_section use_journal "True" # if we are using the journal directly, our process id is already correct - iniset $conf_file $conf_section logging_debug_format_suffix \ - "{{%(funcName)s %(pathname)s:%(lineno)d}}" else - iniset $conf_file $conf_section logging_debug_format_suffix \ - "{{(pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d}}" + pidstr="(pid=%(process)d) " fi + iniset $conf_file $conf_section logging_debug_format_suffix "{{${pidstr}%(funcName)s %(pathname)s:%(lineno)d}}" - iniset $conf_file $conf_section logging_context_format_string \ - "%(levelname)s %(name)s [%(request_id)s %(project_name)s %(user_name)s] %(instance)s%(message)s" - iniset $conf_file $conf_section logging_default_format_string \ - "%(levelname)s %(name)s [-] %(instance)s%(color)s%(message)s" - iniset $conf_file $conf_section logging_exception_prefix "ERROR %(name)s %(instance)s" + 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" + iniset $conf_file $conf_section logging_default_format_string "%(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s" + iniset $conf_file $conf_section logging_exception_prefix "ERROR %(name)s %(instance)s" } function setup_standard_logging_identity { diff --git a/stackrc b/stackrc index 35856ca73e..2a2007f581 100644 --- a/stackrc +++ b/stackrc @@ -100,11 +100,9 @@ USER_UNITS=$(trueorfalse False USER_UNITS) if [[ "$USER_UNITS" == "True" ]]; then SYSTEMD_DIR="$HOME/.local/share/systemd/user" SYSTEMCTL="systemctl --user" - JOURNALCTL_F="journalctl -f -o short-precise --user-unit" else SYSTEMD_DIR="/etc/systemd/system" SYSTEMCTL="sudo systemctl" - JOURNALCTL_F="journalctl -f -o short-precise --unit" fi