forked from lix-project/lix
Support systemd log severity prefixes
This is mostly useful for hydra-queue-runner.
This commit is contained in:
parent
b3491c781c
commit
db55940d9e
|
@ -90,6 +90,7 @@ static void setLogType(string lt)
|
||||||
if (lt == "pretty") logType = ltPretty;
|
if (lt == "pretty") logType = ltPretty;
|
||||||
else if (lt == "escapes") logType = ltEscapes;
|
else if (lt == "escapes") logType = ltEscapes;
|
||||||
else if (lt == "flat") logType = ltFlat;
|
else if (lt == "flat") logType = ltFlat;
|
||||||
|
else if (lt == "systemd") logType = ltSystemd;
|
||||||
else throw UsageError("unknown log type");
|
else throw UsageError("unknown log type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +117,9 @@ void initNix()
|
||||||
|
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
|
|
||||||
|
if (getEnv("IN_SYSTEMD") == "1")
|
||||||
|
logType = ltSystemd;
|
||||||
|
|
||||||
settings.processEnvironment();
|
settings.processEnvironment();
|
||||||
settings.loadConfFile();
|
settings.loadConfFile();
|
||||||
|
|
||||||
|
|
|
@ -477,12 +477,24 @@ void printMsg_(Verbosity level, const FormatOrString & fs)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
if (level > verbosity) return;
|
if (level > verbosity) return;
|
||||||
|
|
||||||
string prefix;
|
string prefix;
|
||||||
if (logType == ltPretty)
|
if (logType == ltPretty)
|
||||||
for (int i = 0; i < nestingLevel; i++)
|
for (int i = 0; i < nestingLevel; i++)
|
||||||
prefix += "| ";
|
prefix += "| ";
|
||||||
else if (logType == ltEscapes && level != lvlInfo)
|
else if (logType == ltEscapes && level != lvlInfo)
|
||||||
prefix = "\033[" + escVerbosity(level) + "s";
|
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();
|
string s = (format("%1%%2%\n") % prefix % fs.s).str();
|
||||||
if (!isatty(STDERR_FILENO)) s = filterANSIEscapes(s);
|
if (!isatty(STDERR_FILENO)) s = filterANSIEscapes(s);
|
||||||
writeToStderr(s);
|
writeToStderr(s);
|
||||||
|
|
|
@ -122,7 +122,8 @@ T singleton(const A & a)
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ltPretty, /* nice, nested output */
|
ltPretty, /* nice, nested output */
|
||||||
ltEscapes, /* nesting indicated using escape codes (for log2xml) */
|
ltEscapes, /* nesting indicated using escape codes (for log2xml) */
|
||||||
ltFlat /* no nesting */
|
ltFlat, /* no nesting */
|
||||||
|
ltSystemd, /* use systemd severity prefixes */
|
||||||
} LogType;
|
} LogType;
|
||||||
|
|
||||||
extern LogType logType;
|
extern LogType logType;
|
||||||
|
|
Loading…
Reference in a new issue