diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-07-01 09:21:52 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-07-01 09:21:52 +0200 |
commit | fde09c92954697fb960767c7606a4a209886c28c (patch) | |
tree | 3a013fad79f8e0ce377eabd86df77c9405b23cc1 | |
parent | 2b6318e14e36b75e85d356e8d50c02c198b465a7 (diff) |
Fix systemd diagnostics
-rw-r--r-- | bbot/diagnostics.cxx | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/bbot/diagnostics.cxx b/bbot/diagnostics.cxx index e5f5747..12c8438 100644 --- a/bbot/diagnostics.cxx +++ b/bbot/diagnostics.cxx @@ -78,14 +78,15 @@ namespace bbot static void systemd_writer (const diag_record& dr) { - const string& s (dr.os.str ()); + const string& m (dr.os.str ()); + const char* s (m.c_str ()); - // Map "<N>..." prefix to priority. + // Map "<N>..." prefix to priority. Absent is info. // - int p (-1); - if (s.size () > 2 && s[0] == '<' && s[2] == '>') + int p (LOG_INFO); + if (m.size () > 2 && m[0] == '<' && m[2] == '>') { - char c (s[1]); + char c (m[1]); p = (c == '0' ? LOG_EMERG : c == '1' ? LOG_ALERT : c == '2' ? LOG_CRIT : @@ -93,16 +94,36 @@ namespace bbot c == '4' ? LOG_WARNING : c == '5' ? LOG_NOTICE : c == '6' ? LOG_INFO : - c == '7' ? LOG_DEBUG : p); + c == '7' ? LOG_DEBUG : LOG_ALERT); + s += 3; } - if (p == -1 || sd_journal_print (p, "%s", s.c_str () + 3) != 0) + if (sd_journal_print (p, "%s", s) != 0) default_writer (dr); } void systemd_diagnostics (bool with_critical) { + trace_indent = + fail.indent_ = + error.indent_ = + warn.indent_ = + info.indent_ = + text.indent_ = systemd_indent; + + // We don't always see colorized output so keep 'error: ', etc. + // + // Note that lucky for us the default level is info (<6>) and so we can + // omit it. Failed that, we would see the '<6>' prefixes in "followup" + // entries (unless we clean them up in systemd_writer() or some such). + // + fail.type_ = with_critical ? "<2>fatal: " : "<3>error: "; + error.type_ = "<3>error: "; + warn.type_ = "<4>warning: "; + info.type_ = nullptr; + trace_type = "<7>"; + // Using sd_journal_print() allows us to print multi-line records nicely. // However, requiring libsystemd-dev (or equivalent) is a bit of a schlep // so we use the dynamic loading trick. @@ -126,21 +147,6 @@ namespace bbot default_writer = diag_record::writer; diag_record::writer = &systemd_writer; - - trace_indent = - fail.indent_ = - error.indent_ = - warn.indent_ = - info.indent_ = - text.indent_ = systemd_indent; - - // We don't always see colorized output so keep 'error: ', etc. - // - fail.type_ = with_critical ? "<2>fatal: " : "<3>error: "; - error.type_ = "<3>error: "; - warn.type_ = "<4>warning: "; - info.type_ = "<6>"; - trace_type = "<7>"; } #endif |