summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-22 03:47:46 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-22 04:02:07 +0100
commitaca83a53ee1dd01beafcd07c55c4cd6c3efb4224 (patch)
treec81270c1d0bfb7e607445ff512846d3187b81350 /src
parent07e10d1a7c7535bd3938b09a11bf29b94a9dae77 (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.
Diffstat (limited to 'src')
-rw-r--r--src/shared/log.c13
-rw-r--r--src/shared/log.h1
2 files changed, 11 insertions, 3 deletions
diff --git a/src/shared/log.c b/src/shared/log.c
index af1a932c86..f8c16de777 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -314,14 +314,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) {
@@ -1016,7 +1021,8 @@ int log_show_location_from_string(const char *e) {
}
bool log_on_console(void) {
- if (log_target == LOG_TARGET_CONSOLE)
+ if (log_target == LOG_TARGET_CONSOLE ||
+ log_target == LOG_TARGET_CONSOLE_PREFIXED)
return true;
return syslog_fd < 0 && kmsg_fd < 0 && journal_fd < 0;
@@ -1024,6 +1030,7 @@ bool log_on_console(void) {
static const char *const log_target_table[_LOG_TARGET_MAX] = {
[LOG_TARGET_CONSOLE] = "console",
+ [LOG_TARGET_CONSOLE_PREFIXED] = "console-prefixed",
[LOG_TARGET_KMSG] = "kmsg",
[LOG_TARGET_JOURNAL] = "journal",
[LOG_TARGET_JOURNAL_OR_KMSG] = "journal-or-kmsg",
diff --git a/src/shared/log.h b/src/shared/log.h
index d15d7c8f92..2889e1e77f 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -34,6 +34,7 @@
typedef enum LogTarget{
LOG_TARGET_CONSOLE,
+ LOG_TARGET_CONSOLE_PREFIXED,
LOG_TARGET_KMSG,
LOG_TARGET_JOURNAL,
LOG_TARGET_JOURNAL_OR_KMSG,