From b9224d81c936a564f8a8adb612691eee71aa9a35 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 2 Mar 2011 04:22:20 -0800 Subject: [PATCH] logging: default to foreground logging At global constructor time: default to logging everything to stderr. During common_init: set appropriate logging defaults based on the type or program (daemon or other). Signed-off-by: Colin McCabe --- src/common/common_init.cc | 12 ++++++++++++ src/common/common_init.h | 1 - src/common/config.cc | 8 ++++---- src/crushtool.cc | 2 -- src/monmaptool.cc | 1 - 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 9bd3cb96e9c4f..90f55242661d3 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -111,6 +111,12 @@ static void keyring_init(const char *filesearch) } } +static void set_cv(const char ** key, const char * const val) +{ + free((void*)*key); + *key = strdup(val); +} + void common_init(std::vector& args, const char *module_type, int flags) { bool force_fg_logging = false; @@ -128,7 +134,13 @@ void common_init(std::vector& args, const char *module_type, int fl << "and is only suitable for **" << TEXT_NORMAL << std::endl; cout << TEXT_YELLOW << " ** testing and review. Do not trust it " << "with important data. **" << TEXT_NORMAL << std::endl; + + // some daemon-specific defaults g_conf.daemonize = true; + g_conf.log_to_stderr = LOG_TO_STDERR_SOME; + g_conf.log_to_file = true; + set_cv(&g_conf.log_dir, "/var/log/ceph"); + set_cv(&g_conf.pid_file, "/var/run/ceph/$type.$id.pid"); } else { g_conf.pid_file = 0; diff --git a/src/common/common_init.h b/src/common/common_init.h index d94b53a9f5d27..913b02394db20 100644 --- a/src/common/common_init.h +++ b/src/common/common_init.h @@ -13,6 +13,5 @@ enum { void common_init(std::vector& args, const char *module_type, int flags); -void set_foreground_logging(); #endif diff --git a/src/common/config.cc b/src/common/config.cc index 8a17c46fbe2c1..dfec1aef0adc5 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -105,16 +105,16 @@ struct config_option config_optionsp[] = { OPTION(profiling_logger_subdir, 0, OPT_STR, 0), OPTION(profiling_logger_dir, 0, OPT_STR, "/var/log/ceph/stat"), OPTION(log_file, 0, OPT_STR, 0), - OPTION(log_dir, 0, OPT_STR, "/var/log/ceph"), + OPTION(log_dir, 0, OPT_STR, ""), OPTION(log_sym_dir, 0, OPT_STR, 0), OPTION(log_sym_history, 0, OPT_INT, 10), - OPTION(log_to_stderr, 0, OPT_INT, LOG_TO_STDERR_SOME), + OPTION(log_to_stderr, 0, OPT_INT, LOG_TO_STDERR_ALL), OPTION(log_to_syslog, 0, OPT_BOOL, false), OPTION(log_per_instance, 0, OPT_BOOL, false), - OPTION(log_to_file, 0, OPT_BOOL, true), + OPTION(log_to_file, 0, OPT_BOOL, false), OPTION(clog_to_monitors, 0, OPT_BOOL, true), OPTION(clog_to_syslog, 0, OPT_BOOL, false), - OPTION(pid_file, 0, OPT_STR, "/var/run/ceph/$type.$id.pid"), + OPTION(pid_file, 0, OPT_STR, ""), OPTION(conf, 'c', OPT_STR, "/etc/ceph/ceph.conf, ~/.ceph/config, ceph.conf"), OPTION(chdir, 0, OPT_STR, "/"), OPTION(kill_after, 0, OPT_INT, 0), diff --git a/src/crushtool.cc b/src/crushtool.cc index 05e4829fd3798..fd27eb87b9b08 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -775,8 +775,6 @@ struct layer_t { int main(int argc, const char **argv) { - set_foreground_logging(); - vector args; argv_to_vec(argc, argv, args); diff --git a/src/monmaptool.cc b/src/monmaptool.cc index 65dceb0dc6209..e88b606bb898b 100644 --- a/src/monmaptool.cc +++ b/src/monmaptool.cc @@ -38,7 +38,6 @@ int main(int argc, const char **argv) vector args; argv_to_vec(argc, argv, args); DEFINE_CONF_VARS(usage); - set_foreground_logging(); const char *me = argv[0]; -- 2.39.5