]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: allow syslog level and facility for cluster log to be controlled
authorSage Weil <sage@inktank.com>
Wed, 20 Feb 2013 20:47:38 +0000 (12:47 -0800)
committerSage Weil <sage@inktank.com>
Wed, 20 Feb 2013 20:52:32 +0000 (12:52 -0800)
Allow user to control the minimum level to go to syslog for the client-
and server-side submission paths for the cluster log, along with the syslog
'facility'.  See syslog(3) man page.

Also move the level checks into a LogEntry method.

Closes: #3704
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Joao Luis <joao.luis@inktank.com>
src/common/LogClient.cc
src/common/LogEntry.cc
src/common/LogEntry.h
src/common/config_opts.h
src/mon/LogMonitor.cc

index 0dce8bd69a032d25fbf26cfb3224d703005431ef..86c82fb6e424f211b5ffe775258ac12b3439e410 100644 (file)
@@ -86,10 +86,8 @@ void LogClient::do_log(clog_type type, const std::string& s)
 
   // log to syslog?
   if (cct->_conf->clog_to_syslog) {
-    ostringstream oss;
-    oss << e;
-    string str(oss.str());
-    syslog(clog_type_to_syslog_prio(e.type) | LOG_USER, "%s", str.c_str());
+    e.log_to_syslog(cct->_conf->clog_to_syslog_level,
+                   cct->_conf->clog_to_syslog_facility);
   }
 
   // log to monitor?
index 80801bcf3a305167a3a0417d3bf9e8be95371bc1..97b173f1fd87918de979fdaa7ea7238b4fb0214c 100644 (file)
@@ -1,28 +1,14 @@
 
 #include <syslog.h>
 
+#include <boost/algorithm/string.hpp>
+
 #include "LogEntry.h"
 #include "Formatter.h"
 
+#include "include/stringify.h"
+
 
-int clog_type_to_syslog_prio(clog_type t)
-{
-  switch (t) {
-    case CLOG_DEBUG:
-      return LOG_DEBUG;
-    case CLOG_INFO:
-      return LOG_INFO;
-    case CLOG_WARN:
-      return LOG_WARNING;
-    case CLOG_ERROR:
-      return LOG_ERR;
-    case CLOG_SEC:
-      return LOG_CRIT;
-    default:
-      assert(0);
-      return 0;
-  }
-}
 
 // ----
 // LogEntryKey
@@ -56,6 +42,104 @@ void LogEntryKey::generate_test_instances(list<LogEntryKey*>& o)
 
 // ----
 
+int clog_type_to_syslog_level(clog_type t)
+{
+  switch (t) {
+    case CLOG_DEBUG:
+      return LOG_DEBUG;
+    case CLOG_INFO:
+      return LOG_INFO;
+    case CLOG_WARN:
+      return LOG_WARNING;
+    case CLOG_ERROR:
+      return LOG_ERR;
+    case CLOG_SEC:
+      return LOG_CRIT;
+    default:
+      assert(0);
+      return 0;
+  }
+}
+
+int string_to_syslog_level(string s)
+{
+  if (boost::iequals(s, "debug"))
+    return LOG_DEBUG;
+  if (boost::iequals(s, "info") ||
+      boost::iequals(s, "notice"))
+    return LOG_INFO;
+  if (boost::iequals(s, "warning") ||
+      boost::iequals(s, "warn"))
+    return LOG_WARNING;
+  if (boost::iequals(s, "error") ||
+      boost::iequals(s, "err"))
+    return LOG_ERR;
+  if (boost::iequals(s, "crit") ||
+      boost::iequals(s, "critical") ||
+      boost::iequals(s, "emerg"))
+    return LOG_CRIT;
+
+  // err on the side of noise!
+  return LOG_DEBUG;
+}
+
+int string_to_syslog_facility(string s)
+{
+  if (boost::iequals(s, "auth"))
+    return LOG_AUTH;
+  if (boost::iequals(s, "authpriv"))
+    return LOG_AUTHPRIV;
+  if (boost::iequals(s, "cron"))
+    return LOG_CRON;
+  if (boost::iequals(s, "daemon"))
+    return LOG_DAEMON;
+  if (boost::iequals(s, "ftp"))
+    return LOG_FTP;
+  if (boost::iequals(s, "kern"))
+    return LOG_KERN;
+  if (boost::iequals(s, "local0"))
+    return LOG_LOCAL0;
+  if (boost::iequals(s, "local1"))
+    return LOG_LOCAL1;
+  if (boost::iequals(s, "local2"))
+    return LOG_LOCAL2;
+  if (boost::iequals(s, "local3"))
+    return LOG_LOCAL3;
+  if (boost::iequals(s, "local4"))
+    return LOG_LOCAL4;
+  if (boost::iequals(s, "local5"))
+    return LOG_LOCAL5;
+  if (boost::iequals(s, "local6"))
+    return LOG_LOCAL6;
+  if (boost::iequals(s, "local7"))
+    return LOG_LOCAL7;
+  if (boost::iequals(s, "lpr"))
+    return LOG_LPR;
+  if (boost::iequals(s, "mail"))
+    return LOG_MAIL;
+  if (boost::iequals(s, "news"))
+    return LOG_NEWS;
+  if (boost::iequals(s, "syslog"))
+    return LOG_SYSLOG;
+  if (boost::iequals(s, "user"))
+    return LOG_USER;
+  if (boost::iequals(s, "uucp"))
+    return LOG_UUCP;
+
+  // default to USER
+  return LOG_USER;
+}
+
+void LogEntry::log_to_syslog(string level, string facility)
+{
+  int min = string_to_syslog_level(level);
+  int l = clog_type_to_syslog_level(type);
+  if (l <= min) {
+    int f = string_to_syslog_facility(facility);
+    syslog(l | f, "%s", stringify(*this).c_str());
+  }
+}
+
 void LogEntry::encode(bufferlist& bl) const
 {
   ENCODE_START(2, 2, bl);
index cea6801301694b3e99f6d7198989e9744bf43502..81c23537d317053b9981fd7ccf000370ab566b42 100644 (file)
@@ -35,7 +35,10 @@ typedef enum {
 /*
  * Given a clog log_type, return the equivalent syslog priority
  */
-int clog_type_to_syslog_prio(clog_type t);
+int clog_type_to_syslog_level(clog_type t);
+
+int string_to_syslog_level(string s);
+int string_to_syslog_facility(string s);
 
 
 struct LogEntryKey {
@@ -66,6 +69,8 @@ struct LogEntry {
 
   LogEntryKey key() const { return LogEntryKey(who, stamp, seq); }
 
+  void log_to_syslog(string level, string facility);
+
   void encode(bufferlist& bl) const;
   void decode(bufferlist::iterator& bl);
   void dump(Formatter *f) const;
index 2fb52a8762279a51e3678906eaf394cb37988148..573e87f9a4a838afefec92f1bb3677e712d27f33 100644 (file)
@@ -42,8 +42,12 @@ OPTION(log_flush_on_exit, OPT_BOOL, true)
 
 OPTION(clog_to_monitors, OPT_BOOL, true)
 OPTION(clog_to_syslog, OPT_BOOL, false)
+OPTION(clog_to_syslog_level, OPT_STR, "info")         // this level and above
+OPTION(clog_to_syslog_facility, OPT_STR, "daemon")
 
 OPTION(mon_cluster_log_to_syslog, OPT_BOOL, false)
+OPTION(mon_cluster_log_to_syslog_level, OPT_STR, "info")   // this level and above
+OPTION(mon_cluster_log_to_syslog_facility, OPT_STR, "daemon")
 OPTION(mon_cluster_log_file, OPT_STR, "/var/log/ceph/$cluster.log")
 
 DEFAULT_SUBSYS(0, 5)
index f06de5217a0c403b0aea98456ab085769b3b0a6e..84ff0dd07435bfeae793adcfdd0b3b2cc166d2a0 100644 (file)
@@ -128,7 +128,8 @@ void LogMonitor::update_from_paxos()
       string s = ss.str();
 
       if (g_conf->mon_cluster_log_to_syslog) {
-       syslog(clog_type_to_syslog_prio(le.type) | LOG_USER, "%s", s.c_str());
+       le.log_to_syslog(g_conf->mon_cluster_log_to_syslog_level,
+                        g_conf->mon_cluster_log_to_syslog_facility);
       }
       if (g_conf->mon_cluster_log_file.length()) {
        blog.append(s + "\n");