From deb06d37292d9112d74bdf80cfebb92ab5151679 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 16 Jun 2010 17:38:15 +0100 Subject: [PATCH] Log paths now support "syslog" string. --HG-- branch : HEAD --- src/doveadm/doveadm-log.c | 27 ++++++++++------ src/lib-master/master-service-settings.c | 23 ++++++++++++-- src/lib-master/master-service.c | 40 +++++++++++++++++------- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/doveadm/doveadm-log.c b/src/doveadm/doveadm-log.c index 42e202ebd3..82c61fe3bd 100644 --- a/src/doveadm/doveadm-log.c +++ b/src/doveadm/doveadm-log.c @@ -218,23 +218,30 @@ static void cmd_log_find(int argc, char *argv[]) /* first get the paths that we know are used */ set = master_service_settings_get(master_service); log_file_path = set->log_path; - if (*log_file_path != '\0') { + if (*log_file_path != '\0' && strcmp(log_file_path, "syslog") != 0) { cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_WARNING); cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_ERROR); cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_FATAL); } - if (*set->info_log_path != '\0') - log_file_path = set->info_log_path; - if (*log_file_path != '\0') - cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_INFO); + if (strcmp(set->info_log_path, "syslog") != 0) { + if (*set->info_log_path != '\0') + log_file_path = set->info_log_path; + if (*log_file_path != '\0') + cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_INFO); + } - if (*set->debug_log_path != '\0') - log_file_path = set->debug_log_path; - if (*log_file_path != '\0') - cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_DEBUG); + if (strcmp(set->debug_log_path, "syslog") != 0) { + if (*set->debug_log_path != '\0') + log_file_path = set->debug_log_path; + if (*log_file_path != '\0') + cmd_log_find_add(&ctx, log_file_path, LOG_TYPE_DEBUG); + } - if (*set->log_path == '\0') { + if (*set->log_path == '\0' || + strcmp(set->log_path, "syslog") == 0 || + strcmp(set->info_log_path, "syslog") == 0 || + strcmp(set->debug_log_path, "syslog") == 0) { /* at least some logs were logged via syslog */ cmd_log_find_syslog(&ctx, argc, argv); } diff --git a/src/lib-master/master-service-settings.c b/src/lib-master/master-service-settings.c index 0f527d4ad8..ac1ab8c922 100644 --- a/src/lib-master/master-service-settings.c +++ b/src/lib-master/master-service-settings.c @@ -27,6 +27,9 @@ #define DEF(type, name) \ { type, #name, offsetof(struct master_service_settings, name), NULL } +static bool +master_service_settings_check(void *_set, pool_t pool, const char **error_r); + static const struct setting_define master_service_setting_defines[] = { DEF(SET_STR, log_path), DEF(SET_STR, info_log_path), @@ -41,7 +44,7 @@ static const struct setting_define master_service_setting_defines[] = { }; static const struct master_service_settings master_service_default_settings = { - .log_path = "", + .log_path = "syslog", .info_log_path = "", .debug_log_path = "", .log_timestamp = DEFAULT_FAILURE_STAMP_FORMAT, @@ -59,9 +62,25 @@ const struct setting_parser_info master_service_setting_parser_info = { .type_offset = (size_t)-1, .struct_size = sizeof(struct master_service_settings), - .parent_offset = (size_t)-1 + .parent_offset = (size_t)-1, + .check_func = master_service_settings_check }; +/* */ +static bool +master_service_settings_check(void *_set, pool_t pool ATTR_UNUSED, + const char **error_r ATTR_UNUSED) +{ + struct master_service_settings *set = _set; + + if (*set->log_path == '\0') { + /* default to syslog logging */ + set->log_path = "syslog"; + } + return TRUE; +} +/* */ + static void ATTR_NORETURN master_service_exec_config(struct master_service *service, const struct master_service_settings_input *input) diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index d23580a53f..e5f8bfc499 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -214,8 +214,16 @@ void master_service_init_log(struct master_service *service, return; } - if (*service->set->log_path == '\0') { - /* log to syslog */ + if (strcmp(service->set->log_path, "syslog") != 0) { + /* error logging goes to file or stderr */ + path = home_expand(service->set->log_path); + i_set_failure_file(path, prefix); + } + + if (strcmp(service->set->log_path, "syslog") == 0 || + strcmp(service->set->info_log_path, "syslog") == 0 || + strcmp(service->set->debug_log_path, "syslog") == 0) { + /* something gets logged to syslog */ int facility; if (!syslog_facility_find(service->set->syslog_facility, @@ -223,19 +231,27 @@ void master_service_init_log(struct master_service *service, facility = LOG_MAIL; i_set_failure_syslog("dovecot", LOG_NDELAY, facility); i_set_failure_prefix(prefix); - } else { - /* log to file or stderr */ - path = home_expand(service->set->log_path); - i_set_failure_file(path, prefix); + + if (strcmp(service->set->log_path, "syslog") != 0) { + /* set error handlers back to file */ + i_set_fatal_handler(NULL); + i_set_error_handler(NULL); + } } - path = home_expand(service->set->info_log_path); - if (*path != '\0') - i_set_info_file(path); + if (*service->set->info_log_path != '\0' && + strcmp(service->set->info_log_path, "syslog") != 0) { + path = home_expand(service->set->info_log_path); + if (*path != '\0') + i_set_info_file(path); + } - path = home_expand(service->set->debug_log_path); - if (*path != '\0') - i_set_debug_file(path); + if (*service->set->debug_log_path != '\0' && + strcmp(service->set->debug_log_path, "syslog") != 0) { + path = home_expand(service->set->debug_log_path); + if (*path != '\0') + i_set_debug_file(path); + } i_set_failure_timestamp_format(service->set->log_timestamp); } -- 2.47.3