diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-25 17:02:36 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-01-25 17:02:36 -0500 |
commit | d08c44759ababc16e6ea53ca2477e73e7286e1b5 (patch) | |
tree | ba432a55963d2ec3bee18fc19ea661c460f99337 /src/shared/log.c | |
parent | 4e716cdeb5d3ec2082ad5b92fc691277a37b4639 (diff) |
log: add new log output mode, that prints to console, but
prefixes with syslog priority
This is useful when we execute our own programs, reading output from its
STDERR, and want to retain priority information.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/log.c')
-rw-r--r-- | src/shared/log.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/shared/log.c b/src/shared/log.c index 69f23fead0..d4df4dffd3 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -244,14 +244,19 @@ static int write_to_console( const char *object, const char *buffer) { - char location[64]; - struct iovec iovec[5] = {}; + char location[64], prefix[1 + DECIMAL_STR_MAX(int) + 2]; + struct iovec iovec[6] = {}; unsigned n = 0; bool highlight; if (console_fd < 0) return 0; + if (log_target == LOG_TARGET_CONSOLE_PREFIXED) { + sprintf(prefix, "<%i>", level); + IOVEC_SET_STRING(iovec[n++], prefix); + } + highlight = LOG_PRI(level) <= LOG_ERR && show_color; if (show_location) { @@ -540,6 +545,7 @@ int log_get_max_level(void) { } static const char *const log_target_table[] = { [LOG_TARGET_CONSOLE] = "console", + [LOG_TARGET_CONSOLE_PREFIXED] = "console-prefixed", [LOG_TARGET_KMSG] = "kmsg", [LOG_TARGET_SYSLOG] = "syslog", [LOG_TARGET_SYSLOG_OR_KMSG] = "syslog-or-kmsg", |