X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=log.c;h=ffca41c2702e45c4e4fe6ddd0561011d8af48bed;hb=004e33b632f34c9cd802347003563d566392678f;hp=da1c4f61e3575505d4e0b2e6de7582239d7e8312;hpb=16801e901e87f4ca0c83ea8c09df1ab3d344129e;p=elogind.git diff --git a/log.c b/log.c index da1c4f61e..ffca41c27 100644 --- a/log.c +++ b/log.c @@ -31,8 +31,6 @@ #include "util.h" #include "macro.h" -extern char * __progname; - #define SYSLOG_TIMEOUT_USEC (5*USEC_PER_SEC) #define LOG_BUFFER_MAX 1024 @@ -188,7 +186,7 @@ static int write_to_syslog( zero(iovec); IOVEC_SET_STRING(iovec[0], header_priority); IOVEC_SET_STRING(iovec[1], header_time); - IOVEC_SET_STRING(iovec[2], file_name_from_path(__progname)); + IOVEC_SET_STRING(iovec[2], __progname); IOVEC_SET_STRING(iovec[3], header_pid); IOVEC_SET_STRING(iovec[4], buffer); @@ -228,7 +226,7 @@ static int write_to_kmsg( zero(iovec); IOVEC_SET_STRING(iovec[0], header_priority); - IOVEC_SET_STRING(iovec[1], file_name_from_path(__progname)); + IOVEC_SET_STRING(iovec[1], __progname); IOVEC_SET_STRING(iovec[2], header_pid); IOVEC_SET_STRING(iovec[3], buffer); IOVEC_SET_STRING(iovec[4], (char*) "\n"); @@ -274,3 +272,43 @@ void log_meta( errno = saved_errno; } + +int log_set_target_from_string(const char *e) { + LogTarget t; + + if ((t = log_target_from_string(e)) < 0) + return -EINVAL; + + log_set_target(t); + return 0; +} + +int log_set_max_level_from_string(const char *e) { + int t; + + if ((t = log_level_from_string(e)) < 0) + return -EINVAL; + + log_set_max_level(t); + return 0; +} + +void log_parse_environment(void) { + const char *e; + + if ((e = getenv("SYSTEMD_LOG_TARGET"))) + if (log_set_target_from_string(e) < 0) + log_warning("Failed to parse log target %s. Ignoring.", e); + + if ((e = getenv("SYSTEMD_LOG_LEVEL"))) + if (log_set_max_level_from_string(e) < 0) + log_warning("Failed to parse log level %s. Ignoring.", e); +} + +static const char *const log_target_table[] = { + [LOG_TARGET_CONSOLE] = "console", + [LOG_TARGET_SYSLOG] = "syslog", + [LOG_TARGET_KMSG] = "kmsg", +}; + +DEFINE_STRING_TABLE_LOOKUP(log_target, LogTarget);