diff --git a/src/conffile.c b/src/conffile.c index 00088293..b67d9e65 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -206,6 +206,19 @@ uid_t runas_uid; gid_t runas_gid; +static void +logger_confuse(cfg_t *cfg, const char *format, va_list args) +{ + char fmt[80]; + + if (cfg && cfg->name && cfg->line) + snprintf(fmt, sizeof(fmt), "[%s:%d] %s\n", cfg->name, cfg->line, format); + else + snprintf(fmt, sizeof(fmt), "%s\n", format); + + DVPRINTF(E_LOG, L_CONF, fmt, args); +} + static int cb_loglevel(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result) { @@ -355,6 +368,8 @@ conffile_load(char *file) cfg = cfg_init(toplvl_cfg, CFGF_NONE); + cfg_set_error_function(cfg, logger_confuse); + ret = cfg_parse(cfg, file); if (ret == CFG_FILE_ERROR) diff --git a/src/logger.c b/src/logger.c index 34e47db1..e72bad99 100644 --- a/src/logger.c +++ b/src/logger.c @@ -174,6 +174,17 @@ DPRINTF(int severity, int domain, const char *fmt, ...) va_end(ap); } +void +DVPRINTF(int severity, int domain, const char *fmt, va_list ap) +{ + // If domain and severity do not match the current log configuration, return early to + // safe some unnecessary code execution (tiny performance gain) + if (logger_initialized && (!((1 << domain) & logdomains) || (severity > threshold))) + return; + + vlogger(severity, domain, fmt, ap); +} + void logger_ffmpeg(void *ptr, int level, const char *fmt, va_list ap) { diff --git a/src/logger.h b/src/logger.h index 0f94190d..2d7bd86d 100644 --- a/src/logger.h +++ b/src/logger.h @@ -52,6 +52,9 @@ void DPRINTF(int severity, int domain, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +void +DVPRINTF(int severity, int domain, const char *fmt, va_list ap); + void logger_ffmpeg(void *ptr, int level, const char *fmt, va_list ap);