diff options
-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 |