]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
logging: add g_conf.clog_to_syslog
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 3 Dec 2010 23:33:48 +0000 (15:33 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 6 Dec 2010 23:38:12 +0000 (15:38 -0800)
Add a new configuration option that allows you to send central log
messages to syslog.

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

index b3900c8a852bfc64fc2dc7eababc9fef8e10d78f..26f054411d0d4288a68251cfbf478fbc03e00f92 100644 (file)
@@ -27,6 +27,7 @@
 #include <iostream>
 #include <errno.h>
 #include <sys/stat.h>
+#include <syslog.h>
 
 #ifdef DARWIN
 #include <sys/param.h>
 
 #include "config.h"
 
+/*
+ * Given a clog log_type, return the equivalent syslog priority
+ */
+static inline 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;
+  }
+}
+
 LogClientTemp::LogClientTemp(clog_type type_, LogClient &parent_)
   : type(type_), parent(parent_)
 {
@@ -87,6 +110,33 @@ void LogClient::send_log()
 }
 
 void LogClient::_send_log()
+{
+  if (g_conf.clog_to_syslog)
+    _send_log_to_syslog();
+  if (g_conf.clog_to_monitors)
+    _send_log_to_monitors();
+}
+
+void LogClient::_send_log_to_syslog()
+{
+  std::deque<LogEntry>::const_reverse_iterator rbegin = log_queue.rbegin();
+  std::deque<LogEntry>::const_reverse_iterator rend = log_queue.rend();
+  for (std::deque<LogEntry>::const_reverse_iterator a = rbegin; a != rend; ++a) {
+    const LogEntry entry(*a);
+    if (entry.seq < last_syslog)
+      break;
+    ostringstream oss;
+    oss << entry;
+    string str(oss.str());
+    syslog(clog_type_to_syslog_prio(entry.type) | LOG_USER, "%s", str.c_str());
+  }
+  if (rbegin != rend) {
+    const LogEntry entry(*rbegin);
+    last_syslog = entry.seq;
+  }
+}
+
+void LogClient::_send_log_to_monitors()
 {
   if (log_queue.empty())
     return;
index 1738269ae03f11e7d822c7fb6466e2b4ab93ca93..c63bddd7302ad7e293f8a4b157c3cc7336b25536 100644 (file)
@@ -58,7 +58,7 @@ public:
 
   LogClient(Messenger *m, MonMap *mm, MonClient *mc, enum logclient_flag_t flags) :
     messenger(m), monmap(mm), monc(mc), is_synchronous(flags & FLAG_SYNC),
-    log_lock("LogClient::log_lock"), last_log(0) { }
+    log_lock("LogClient::log_lock"), last_log(0), last_syslog(0) { }
 
   void send_log();
   void handle_log_ack(MLogAck *m);
@@ -100,6 +100,8 @@ private:
   void do_log(clog_type type, const std::string& s);
   bool ms_dispatch(Message *m);
   void _send_log();
+  void _send_log_to_syslog();
+  void _send_log_to_monitors();
   void ms_handle_connect(Connection *con);
   bool ms_handle_reset(Connection *con) { return false; }
   void ms_handle_remote_reset(Connection *con) {}
@@ -110,6 +112,7 @@ private:
   bool is_synchronous;
   Mutex log_lock;
   version_t last_log;
+  uint64_t last_syslog;
   std::deque<LogEntry> log_queue;
 
   friend class LogClientTemp;
index ad514a6a47357d6d295f2c309754e6816c56cd80..abeaff8ae33d21a65bd1959e452f90adb45b959a 100644 (file)
@@ -327,6 +327,8 @@ static struct config_option config_optionsp[] = {
        OPTION(log_sym_history, 0, OPT_INT, 10),
        OPTION(log_to_stdout, 0, OPT_BOOL, true),
        OPTION(log_per_instance, 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(conf, 'c', OPT_STR, "/etc/ceph/ceph.conf, ~/.ceph/config, ceph.conf"),
        OPTION(chdir, 0, OPT_STR, "/"),
index f5853c144631154c514c8eb40ea7fb7ec5e342fd..b492e7371854af120f4372c72f5f2ae551d0b701 100644 (file)
@@ -84,6 +84,9 @@ struct md_config_t {
   bool log_to_stdout;
   bool log_per_instance;
 
+  bool clog_to_monitors;
+  bool clog_to_syslog;
+
   const char *pid_file;
 
   const char *conf;