]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
config: separate --log-to-stderr and --err-to-stderr
authorSage Weil <sage@newdream.net>
Fri, 21 Oct 2011 23:35:36 +0000 (16:35 -0700)
committerSage Weil <sage@newdream.net>
Fri, 21 Oct 2011 23:35:36 +0000 (16:35 -0700)
Instead of having magic values (1 == errors only to stderr, 2 =
everything), have two booleans.

Signed-off-by: Sage Weil <sage@newdream.net>
src/common/DoutStreambuf.cc
src/common/DoutStreambuf.h
src/common/common_init.cc
src/common/config.cc
src/common/config_opts.h
src/rgw/librgw.cc
src/scratchtool.c
src/scratchtoolpp.cc

index 3b82955e04fd757b425999cfbb0988a418bdf5a7..cbda8caf8cf7dace035ee9af3f6732b2ab9414a1 100644 (file)
@@ -241,15 +241,14 @@ DoutStreambuf<charT, traits>::overflow(DoutStreambuf<charT, traits>::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 <std::string> &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) {
index 52279edf6aa649c7a98dfcaf29bef8960c57fbb7..bda0a91fbbdabd148f04073bd84107108df99dd5 100644 (file)
@@ -43,8 +43,8 @@ class DoutStreambuf : public std::basic_streambuf<charT, traits>,
 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,
   };
index 8b19e129a223fa85625246efc8cbc08553ddc808..d883be9d31069a335447fff8e5b99a72bcca6ab0 100644 (file)
@@ -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");
index 804d18144ddc07b90c406747db0779c4e6a55e18..20d432818e40c17e7cf1bc115dd2f321fb81e8d5 100644 (file)
@@ -272,7 +272,8 @@ parse_argv(std::vector<const char*>& 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");
     }
index 14d52b5aae172c14ba3f5d11da36e312246de1f5..250cdb44e4850c7232b52503debaa55aabfa769a 100644 (file)
@@ -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)
index 8fd3e20ad60c05138fd643c7e6ed9e360b11ad04..19e42396d97551b5f05344106e796181fbf23027 100644 (file)
@@ -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);
 
index acaa9a75a4f0011a387ac22a2c4e42631c42055e..6022d1e1b015a8aa3cf3aaa78ea9e7baa8ae65cb 100644 (file)
@@ -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;
        }
index 1a8aa2f81c837103556ad4d11f51697a62322709..98bfd2a1c21a253ef059ec2d43af66e3b822d2ef 100644 (file)
@@ -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);
   }