From db55940d9e9fd502b17522d011dfd941e3f69c5d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 20 Jul 2015 01:39:48 +0200 Subject: Support systemd log severity prefixes This is mostly useful for hydra-queue-runner. --- src/libutil/util.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libutil/util.cc') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index f54fd5fb623f..7959b76f868d 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -477,12 +477,24 @@ void printMsg_(Verbosity level, const FormatOrString & fs) { checkInterrupt(); if (level > verbosity) return; + string prefix; if (logType == ltPretty) for (int i = 0; i < nestingLevel; i++) prefix += "| "; else if (logType == ltEscapes && level != lvlInfo) prefix = "\033[" + escVerbosity(level) + "s"; + else if (logType == ltSystemd) { + char c; + switch (level) { + case lvlError: c = '3'; break; + case lvlInfo: c = '5'; break; + case lvlTalkative: case lvlChatty: c = '6'; break; + default: c = '7'; + } + prefix = string("<") + c + ">"; + } + string s = (format("%1%%2%\n") % prefix % fs.s).str(); if (!isatty(STDERR_FILENO)) s = filterANSIEscapes(s); writeToStderr(s); -- cgit 1.4.1