diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-11-20 18:43:31 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-11-20 18:43:31 +0000 |
| commit | 55a23a5b290140816a7f7c215ef90c8af1cb82ef (patch) | |
| tree | a72735324af8eadb10f78b7cf7e3f79f457ae282 | |
| parent | main: mention why we initialize a font set (diff) | |
log: set syslog facility to LOG_DAEMON when run in server mode
| -rw-r--r-- | log.c | 15 | ||||
| -rw-r--r-- | log.h | 4 | ||||
| -rw-r--r-- | main.c | 3 |
3 files changed, 17 insertions, 5 deletions
@@ -13,16 +13,21 @@ static bool colorize = false; -static void __attribute__((constructor)) -init(void) +void +log_init(enum log_facility syslog_facility) { + static const int facility_map[] = { + [LOG_FACILITY_USER] = LOG_USER, + [LOG_FACILITY_DAEMON] = LOG_DAEMON, + }; + colorize = isatty(STDOUT_FILENO); - openlog(NULL, /*LOG_PID*/0, LOG_USER); + openlog(NULL, /*LOG_PID*/0, facility_map[syslog_facility]); setlogmask(LOG_UPTO(LOG_WARNING)); } -static void __attribute__((destructor)) -fini(void) +void +log_deinit(void) { closelog(); } @@ -1,7 +1,11 @@ #pragma once +enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON }; enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_DEBUG }; +void log_init(enum log_facility syslog_facility); +void log_deinit(void); + void log_msg(enum log_class log_class, const char *module, const char *file, int lineno, const char *fmt, ...) __attribute__((format (printf, 5, 6))); @@ -190,6 +190,8 @@ main(int argc, char *const *argv) struct server *server = NULL; struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE}; + log_init(as_server ? LOG_FACILITY_DAEMON : LOG_FACILITY_USER); + /* This ensures we keep a set of fonts in the cache */ if (!initialize_fonts(&conf, fonts)) goto out; @@ -241,5 +243,6 @@ out: font_destroy(fonts[i]); config_free(conf); + log_deinit(); return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret; } |
