From 1f7cb7570a1ababe5a32bda3f5c1c120e1333648 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 21 Oct 2011 16:35:36 -0700 Subject: [PATCH] config: separate --log-to-stderr and --err-to-stderr Instead of having magic values (1 == errors only to stderr, 2 = everything), have two booleans. Signed-off-by: Sage Weil --- src/common/DoutStreambuf.cc | 45 ++++++++++++++++--------------------- src/common/DoutStreambuf.h | 4 ++-- src/common/common_init.cc | 3 ++- src/common/config.cc | 3 ++- src/common/config_opts.h | 3 ++- src/rgw/librgw.cc | 3 ++- src/scratchtool.c | 4 ++-- src/scratchtoolpp.cc | 4 ++-- 8 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index 3b82955e04fd7..cbda8caf8cf7d 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -241,15 +241,14 @@ DoutStreambuf::overflow(DoutStreambuf::int_type c) syslog(LOG_USER | dout_prio_to_syslog_prio(prio), "%s", obuf + TIME_FMT_SZ + 1); } - if (flags & DOUTSB_FLAG_STDERR) { - if ((flags & DOUTSB_FLAG_STDERR_ALL) || (prio == -1)) { - // Just write directly out to the stderr fileno. There's no point in - // using something like fputs to write to a temporary buffer, - // because we would just have to flush that temporary buffer - // immediately. - if (safe_write(STDERR_FILENO, obuf, len)) - flags &= ~DOUTSB_FLAG_STDERR; - } + if ((prio == -1 && (flags & DOUTSB_FLAG_STDERR_ERR)) || + (prio != -1 && (flags & DOUTSB_FLAG_STDERR_LOG))) { + // Just write directly out to the stderr fileno. There's no point in + // using something like fputs to write to a temporary buffer, + // because we would just have to flush that temporary buffer + // immediately. + if (safe_write(STDERR_FILENO, obuf, len)) + flags &= ~DOUTSB_FLAG_STDERR; } if (flags & DOUTSB_FLAG_OFILE) { if (safe_write(ofd, obuf, len)) @@ -277,7 +276,7 @@ get_tracked_conf_keys() const { static const char *KEYS[] = { "log_file", "log_sym_dir", - "log_sym_history", "log_to_stderr", + "log_sym_history", "log_to_stderr", "err_to_stderr", "log_to_syslog", "log_per_instance", NULL }; return KEYS; } @@ -305,22 +304,16 @@ handle_conf_change(const md_config_t *conf, const std::set &change flags |= DOUTSB_FLAG_SYSLOG; } - if ((conf->log_to_stderr != LOG_TO_STDERR_NONE) && - fd_is_open(STDERR_FILENO)) { - switch (conf->log_to_stderr) { - case LOG_TO_STDERR_SOME: - flags |= DOUTSB_FLAG_STDERR_SOME; - break; - case LOG_TO_STDERR_ALL: - flags |= DOUTSB_FLAG_STDERR_ALL; - break; - default: - ostringstream oss; - oss << "DoutStreambuf::handle_conf_change: can't understand " - << "conf->log_to_stderr = " << conf->log_to_stderr << "\n"; - dout_emergency(oss.str()); - break; - } + if (fd_is_open(STDERR_FILENO)) { + if (conf->log_to_stderr) + flags |= DOUTSB_FLAG_STDERR_LOG; + else + flags &= ~DOUTSB_FLAG_STDERR_LOG; + + if (conf->err_to_stderr) + flags |= DOUTSB_FLAG_STDERR_ERR; + else + flags &= ~DOUTSB_FLAG_STDERR_ERR; } if (_read_ofile_config(conf) == 0) { diff --git a/src/common/DoutStreambuf.h b/src/common/DoutStreambuf.h index 52279edf6aa64..bda0a91fbbdab 100644 --- a/src/common/DoutStreambuf.h +++ b/src/common/DoutStreambuf.h @@ -43,8 +43,8 @@ class DoutStreambuf : public std::basic_streambuf, public: enum dout_streambuf_flags_t { DOUTSB_FLAG_SYSLOG = 0x01, - DOUTSB_FLAG_STDERR_SOME = 0x04, - DOUTSB_FLAG_STDERR_ALL = 0x08, + DOUTSB_FLAG_STDERR_LOG = 0x04, + DOUTSB_FLAG_STDERR_ERR = 0x08, DOUTSB_FLAG_STDERR = 0x0c, DOUTSB_FLAG_OFILE = 0x10, }; diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 8b19e129a223f..d883be9d31069 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -55,7 +55,8 @@ CephContext *common_preinit(const CephInitParameters &iparams, conf->set_val_or_die("admin_socket", "/var/run/ceph/$name.asok"); conf->set_val_or_die("log_file", "/var/log/ceph/$name.log"); } - conf->set_val_or_die("log_to_stderr", STRINGIFY(LOG_TO_STDERR_SOME)); + conf->set_val_or_die("log_to_stderr", "false"); + conf->set_val_or_die("err_to_stderr", "true"); break; default: conf->set_val_or_die("daemonize", "false"); diff --git a/src/common/config.cc b/src/common/config.cc index 804d18144ddc0..20d432818e40c 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -272,7 +272,8 @@ parse_argv(std::vector& args) set_val_or_die("pid_file", ""); set_val_or_die("log_sym_dir", ""); set_val_or_die("log_sym_history", "0"); - set_val_or_die("log_to_stderr", STRINGIFY(LOG_TO_STDERR_ALL)); + set_val_or_die("log_to_stderr", "true"); + set_val_or_die("err_to_stderr", "true"); set_val_or_die("log_to_syslog", "false"); set_val_or_die("log_per_instance", "false"); } diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 14d52b5aae172..250cdb44e4850 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -24,7 +24,8 @@ OPTION(admin_socket, OPT_STR, "") OPTION(log_file, OPT_STR, "") OPTION(log_sym_dir, OPT_STR, "") OPTION(log_sym_history, OPT_INT, 10) -OPTION(log_to_stderr, OPT_INT, LOG_TO_STDERR_ALL) +OPTION(log_to_stderr, OPT_BOOL, true) +OPTION(err_to_stderr, OPT_BOOL, true) OPTION(log_to_syslog, OPT_BOOL, false) OPTION(log_per_instance, OPT_BOOL, false) OPTION(clog_to_monitors, OPT_BOOL, true) diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc index 8fd3e20ad60c0..19e42396d9755 100644 --- a/src/rgw/librgw.cc +++ b/src/rgw/librgw.cc @@ -34,7 +34,8 @@ int librgw_create(librgw_t *rgw, const char * const id) iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id); } CephContext *cct = common_preinit(iparams, CODE_ENVIRONMENT_LIBRARY, 0); - cct->_conf->set_val("log_to_stderr", "1"); // quiet by default + cct->_conf->set_val("log_to_stderr", "false"); // quiet by default + cct->_conf->set_val("err_to_stderr", "true"); // quiet by default cct->_conf->parse_env(); // environment variables override cct->_conf->apply_changes(NULL); diff --git a/src/scratchtool.c b/src/scratchtool.c index acaa9a75a4f00..6022d1e1b015a 100644 --- a/src/scratchtool.c +++ b/src/scratchtool.c @@ -131,7 +131,7 @@ static int testrados(void) } // Can we change it? - if (rados_conf_set(cl, "log to stderr", "2")) { + if (rados_conf_set(cl, "log to stderr", "true")) { printf("error: error setting log_to_stderr\n"); return 1; } @@ -139,7 +139,7 @@ static int testrados(void) printf("error: failed to read log_to_stderr from config\n"); return 1; } - if (tmp[0] != '2') { + if (tmp == "true") { printf("error: new setting for log_to_stderr failed to take effect.\n"); return 1; } diff --git a/src/scratchtoolpp.cc b/src/scratchtoolpp.cc index 1a8aa2f81c837..98bfd2a1c21a2 100644 --- a/src/scratchtoolpp.cc +++ b/src/scratchtoolpp.cc @@ -64,7 +64,7 @@ int main(int argc, const char **argv) printf("error: succeeded in setting nonexistent config option\n"); exit(1); } - if (rados.conf_set("log to stderr", "2")) { + if (rados.conf_set("log to stderr", "true")) { printf("error: error setting log_to_stderr\n"); exit(1); } @@ -73,7 +73,7 @@ int main(int argc, const char **argv) printf("error: failed to read log_to_stderr from config\n"); exit(1); } - if (tmp[0] != '2') { + if (tmp == "true") { printf("error: new setting for log_to_stderr failed to take effect.\n"); exit(1); } -- 2.39.5