]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
logging: re-introduce derr
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 16 Dec 2010 00:29:37 +0000 (16:29 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 16 Dec 2010 18:32:45 +0000 (10:32 -0800)
Re-introduce derr as a special log level (level -1) which will show up
in all logs, and on stderr. These messages are the only messages which
will show up on stderr.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/common/DoutStreambuf.cc
src/common/DoutStreambuf.h
src/common/common_init.cc
src/common/debug.h
src/config.cc
src/config.h

index 84a5f45f27761830fa0d02259c7dd48eecb53a9f..2979a27f057b223e916b059268177f1a48c06ea4 100644 (file)
@@ -79,9 +79,9 @@ static void primitive_log(const std::string &str)
   syslog(LOG_USER | LOG_NOTICE, "%s", str.c_str());
 }
 
-static inline bool prio_is_visible_on_stderr(int prio)
+static inline bool prio_is_visible_on_stderr(signed int prio)
 {
-  return prio <= 5;
+  return prio == -1;
 }
 
 static inline int dout_prio_to_syslog_prio(int prio)
@@ -213,7 +213,7 @@ DoutStreambuf<charT, traits>::overflow(DoutStreambuf<charT, traits>::int_type c)
   }
 
   // Loop over all lines in the buffer.
-  int prio = 100;
+  signed int prio = 100;
   charT* start = obuf;
   while (true) {
     char* end = strchrnul(start, '\n');
@@ -228,7 +228,8 @@ DoutStreambuf<charT, traits>::overflow(DoutStreambuf<charT, traits>::int_type c)
       // Decode some control characters
       ++start;
       unsigned char tmp = *((unsigned char*)start);
-      prio = tmp - 11;
+      prio = tmp;
+      prio -= 12;
       ++start;
     }
     *end = '\n';
@@ -302,14 +303,19 @@ void DoutStreambuf<charT, traits>::read_global_config()
   if (g_conf.log_to_syslog) {
     flags |= DOUTSB_FLAG_SYSLOG;
   }
+
   if (g_conf.log_to_stdout) {
     if (fd_is_open(STDOUT_FILENO)) {
       flags |= DOUTSB_FLAG_STDOUT;
     }
   }
-  if (fd_is_open(STDERR_FILENO)) {
-    flags |= DOUTSB_FLAG_STDERR;
+
+  if (g_conf.log_to_stderr) {
+    if (fd_is_open(STDERR_FILENO)) {
+      flags |= DOUTSB_FLAG_STDERR;
+    }
   }
+
   if (g_conf.log_to_file) {
     if (_read_ofile_config()) {
       flags |= DOUTSB_FLAG_OFILE;
@@ -317,14 +323,6 @@ void DoutStreambuf<charT, traits>::read_global_config()
   }
 }
 
-template <typename charT, typename traits>
-void DoutStreambuf<charT, traits>::
-set_flags(int flags_)
-{
-  assert(_dout_lock.is_locked());
-  flags = flags_;
-}
-
 template <typename charT, typename traits>
 void DoutStreambuf<charT, traits>::
 set_prio(int prio)
@@ -414,8 +412,9 @@ std::string DoutStreambuf<charT, traits>::config_to_str() const
 {
   assert(_dout_lock.is_locked());
   ostringstream oss;
-  oss << "g_conf.log_to_syslog = " << g_conf.log_to_syslog << "\n";
   oss << "g_conf.log_to_stdout = " << g_conf.log_to_stdout << "\n";
+  oss << "g_conf.log_to_stderr = " << g_conf.log_to_stderr << "\n";
+  oss << "g_conf.log_to_syslog = " << g_conf.log_to_syslog << "\n";
   oss << "g_conf.log_to_file = " << g_conf.log_to_file << "\n";
   oss << "g_conf.log_file = '" << cpp_str(g_conf.log_file) << "'\n";
   oss << "g_conf.log_dir = '" << cpp_str(g_conf.log_dir) << "'\n";
index 61e6fc63573bfac09d559d097f0378d6dfcf00d7..5e93aca4124e583d54e4764ef2e0f666a05eab53 100644 (file)
@@ -56,9 +56,6 @@ public:
   // Set the flags based on the global configuration
   void read_global_config();
 
-  // Set the flags directly (for debug use only)
-  void set_flags(int flags_);
-
   // Set the priority of the messages being put into the stream
   void set_prio(int prio);
 
index a5c02b9fff152d92dc3b25961f0cbcc9fefe4fed..01382a5bad394a5bf916980fb123facccdff3366 100644 (file)
@@ -1,11 +1,22 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
 
+#include "auth/AuthSupported.h"
+#include "auth/KeyRing.h"
 #include "config.h"
-#include "tls.h"
-
 #include "include/color.h"
-
-#include "auth/KeyRing.h"
-#include "auth/AuthSupported.h"
+#include "tls.h"
 
 void common_set_defaults(bool daemon)
 {
@@ -15,7 +26,6 @@ void common_set_defaults(bool daemon)
 
     g_conf.daemonize = true;
     g_conf.logger = true;
-    g_conf.log_to_stdout = false;
   } else {
     g_conf.pid_file = 0;
   }
@@ -74,4 +84,3 @@ void common_init(std::vector<const char*>& args, const char *module_type, bool i
     }
   }
 }
-
index 9c33e4c500fbf7e47306f8421e8cca3b981e579e..2b4e539b65310da202fe61467b139c01e22918ec 100644 (file)
@@ -35,13 +35,13 @@ extern int dout_handle_daemonize();
 
 extern int dout_create_rank_symlink(int n);
 
-static inline void _dout_begin_line(int prio) {
+static inline void _dout_begin_line(signed int prio) {
   if (unlikely(_dout_need_open))
     _dout_open_log();
 
   // Put priority information into dout
   _doss->sputc(1);
-  _doss->sputc(prio + 11);
+  _doss->sputc(prio + 12);
 
   // Some information that goes in every dout message
   *_dout << g_clock.now() << " " << std::hex << pthread_self()
@@ -76,6 +76,7 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) {
 
 #define dendl std::endl; } } while (0)
 
+#define derr dout(-1)
 
 extern void hex2str(const char *s, int len, char *buf, int dest_len);
 
index e07cc0fcf9c2c797927880023e5de563935f7ef7..fb31b4b4e6d8c0a74613a44691b8da21d4002165 100644 (file)
@@ -18,6 +18,7 @@
 #include "include/types.h"
 
 #include "common/Clock.h"
+#include "common/DoutStreambuf.h"
 #include "common/Logger.h"
 #include "common/BackTrace.h"
 
@@ -325,7 +326,6 @@ static struct config_option config_optionsp[] = {
        OPTION(log_dir, 0, OPT_STR, "/var/log/ceph"),
        OPTION(log_sym_dir, 0, OPT_STR, 0),
        OPTION(log_sym_history, 0, OPT_INT, 10),
-       OPTION(log_to_stdout, 0, OPT_BOOL, true),
        OPTION(log_to_syslog, 0, OPT_BOOL, false),
        OPTION(log_per_instance, 0, OPT_BOOL, false),
        OPTION(log_to_file, 0, OPT_BOOL, true),
@@ -1124,6 +1124,9 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
   std::vector<const char *> nargs;
   bool conf_specified = false;
 
+  g_conf.log_to_stdout = false;
+  g_conf.log_to_stderr = true;
+
   if (!g_conf.id)
     g_conf.id = (char *)g_default_id;
   if (!g_conf.type)
@@ -1144,17 +1147,12 @@ void parse_startup_config_options(std::vector<const char*>& args, const char *mo
       show_config = true;
     } else if (isdaemon && CONF_ARG_EQ("bind", 0)) {
       g_conf.public_addr.parse(args[++i]);
-    } else if (isdaemon && CONF_ARG_EQ("nodaemon", 'D')) {
+    } else if (CONF_ARG_EQ("nodaemon", 'D')) {
       g_conf.daemonize = false;
       g_conf.log_to_stdout = true;
-      /*
-    } else if (isdaemon && CONF_ARG_EQ("daemonize", 'd')) {
-      g_conf.daemonize = true;
-      g_conf.log_to_stdout = false;
-      */
-    } else if (isdaemon && CONF_ARG_EQ("foreground", 'f')) {
+      g_conf.log_to_stderr = false;
+    } else if (CONF_ARG_EQ("foreground", 'f')) {
       g_conf.daemonize = false;
-      //g_conf.log_to_stdout = false;
     } else if (isdaemon && (CONF_ARG_EQ("id", 'i') || CONF_ARG_EQ("name", 'n'))) {
       CONF_SAFE_SET_ARG_VAL(&g_conf.id, OPT_STR);
     } else if (!isdaemon && (CONF_ARG_EQ("id", 'I') || CONF_ARG_EQ("name", 'n'))) {
@@ -1246,22 +1244,20 @@ void generic_usage()
 {
   cerr << "   -c ceph.conf or --conf=ceph.conf\n";
   cerr << "        get options from given conf file" << std::endl;
+  cerr << "   -D   run in foreground.\n";
+  cerr << "   -f   run in foreground. Show all log messages on stdout.\n";
 }
 
 void generic_server_usage()
 {
   cerr << "   --debug_ms N\n";
   cerr << "        set message debug level (e.g. 1)\n";
-  cerr << "   -D   debug (no fork, log to stdout)\n";
-  cerr << "   -f   foreground (no fork, log to file)\n";
   generic_usage();
   exit(1);
 }
 void generic_client_usage()
 {
   generic_usage();
-  cerr << "   -d   daemonize (detach, fork, log to file)\n";
-  cerr << "   -f   foreground (no fork, log to file)" << std::endl;
   exit(1);
 }
 
index 69d22c7fc955820958d2c8319268ef0f220a1e7c..0acfbd360987d28861b0cb45c69ff2805d91e805 100644 (file)
@@ -81,7 +81,9 @@ struct md_config_t {
   const char *log_dir;
   const char *log_sym_dir;
   int log_sym_history;
+
   bool log_to_stdout;
+  bool log_to_stderr;
   bool log_to_syslog;
   bool log_per_instance;
   bool log_to_file;