]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: LogMonitor: expand meta variables at time-of-call
authorJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 26 Aug 2014 15:48:14 +0000 (16:48 +0100)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 27 Aug 2014 18:02:04 +0000 (19:02 +0100)
Instead of expanding it when we updated config options, as that would be
nothing but trouble.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/mon/LogMonitor.cc
src/mon/LogMonitor.h

index e0e32ce1276245cebd16e09b9678c858e2579f98..7a0197bfaab219b933f29371c6c9b733bc539440 100644 (file)
@@ -627,28 +627,35 @@ void LogMonitor::update_log_channels()
     return;
   }
 
-  channels.expand_channel_meta();
 }
 
 void LogMonitor::log_channel_info::expand_channel_meta(map<string,string> &m)
 {
   generic_dout(10) << __func__ << " expand map: " << m << dendl;
   for (map<string,string>::iterator p = m.begin(); p != m.end(); ++p) {
-    size_t pos = string::npos;
-    string s = p->second;
-    bool found_meta = false;
-    while ((pos = s.find(LOG_META_CHANNEL)) != string::npos) {
-      found_meta = true;
-      string tmp = s.substr(0, pos-1) + p->first;
-      if (pos+LOG_META_CHANNEL.length() < s.length())
-        tmp = p->second.substr(pos+LOG_META_CHANNEL.length()+1);
-      s = tmp;
-    }
-    if (found_meta)
-      m[p->first] = s;
+    m[p->first] = expand_channel_meta(p->second, p->first);
   }
   generic_dout(10) << __func__ << " expanded map: " << m << dendl;
 }
+
+string LogMonitor::log_channel_info::expand_channel_meta(
+    const string &input,
+    const string &change_to)
+{
+  size_t pos = string::npos;
+  string s(input);
+  while ((pos = s.find(LOG_META_CHANNEL)) != string::npos) {
+    string tmp = s.substr(0, pos) + change_to;
+    if (pos+LOG_META_CHANNEL.length() < s.length())
+      tmp += s.substr(pos+LOG_META_CHANNEL.length());
+    s = tmp;
+  }
+  generic_dout(20) << __func__ << " from '" << input
+                   << "' to '" << s << "'" << dendl;
+
+  return s;
+}
+
 void LogMonitor::handle_conf_change(const struct md_config_t *conf,
                                     const std::set<std::string> &changed)
 {
index d8e799add38e3206802594dbbc981e09ba7180cb..9a154bd0b808bf874d3831ccf30f17740700764a 100644 (file)
@@ -60,6 +60,8 @@ private:
       expand_channel_meta(log_file_level);
     }
     void expand_channel_meta(map<string,string> &m);
+    string expand_channel_meta(const string &input,
+                               const string &change_to);
 
     bool do_log_to_syslog(const string &channel) {
       return (get_str_map_key(log_to_syslog, channel,
@@ -77,8 +79,14 @@ private:
     }
 
     string get_log_file(const string &channel) {
-      return get_str_map_key(log_file, channel,
-                             &CLOG_CHANNEL_DEFAULT);
+      string fname;
+      if (log_file.count(channel) == 0) {
+        log_file[channel] = expand_channel_meta(
+                              get_str_map_key(log_file, channel,
+                                              &CLOG_CHANNEL_DEFAULT),
+                              channel);
+      }
+      return log_file[channel];
     }
 
     string get_log_file_level(const string &channel) {