]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: LogMonitor: appropriately expand channel meta variables
authorJoao Eduardo Luis <joao@redhat.com>
Fri, 19 Sep 2014 16:24:49 +0000 (17:24 +0100)
committerJoao Eduardo Luis <joao@redhat.com>
Mon, 22 Sep 2014 16:36:29 +0000 (17:36 +0100)
We must only expand the log file's channel meta variables upon requiring
a channel's log file.  As we may have a 'default' channel that will
cover all channels, we must wait to expand channels as they come in and
do so if they haven't yet been expanded.  Expanding the 'log_file' in
place would have the unfortunate side effect of expanding, say,

default=/tmp/whatever.$channel.log

to

default=/tmp/whatever.default.log

which would not be what we wanted upon receiving a message that should
go into channel 'foo' -- assuming we specified no such channel in the
options, channel 'foo' should go into '/tmp/whatever.foo.log'.

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

index 73c5bc5a52d77fa6cc39ca036ace53903b23431d..422da91ddad223e6ece0d3d56dc5cd9c104d321e 100644 (file)
@@ -634,6 +634,7 @@ void LogMonitor::update_log_channels()
     return;
   }
 
+  channels.expand_channel_meta();
 }
 
 void LogMonitor::log_channel_info::expand_channel_meta(map<string,string> &m)
index 2826304bfeb9af1f598838119cfadf42cb4a4d87..cf870130e43a74769a125b7c0f4505c1af28822d 100644 (file)
@@ -42,6 +42,7 @@ private:
     map<string,string> syslog_level;
     map<string,string> syslog_facility;
     map<string,string> log_file;
+    map<string,string> expanded_log_file;
     map<string,string> log_file_level;
 
     void clear() {
@@ -49,14 +50,19 @@ private:
       syslog_level.clear();
       syslog_facility.clear();
       log_file.clear();
+      expanded_log_file.clear();
       log_file_level.clear();
     }
 
+    /** expands $channel meta variable on all maps *EXCEPT* log_file
+     *
+     * We won't expand the log_file map meta variables here because we
+     * intend to do that selectively during get_log_file()
+     */
     void expand_channel_meta() {
       expand_channel_meta(log_to_syslog);
       expand_channel_meta(syslog_level);
       expand_channel_meta(syslog_facility);
-      expand_channel_meta(log_file);
       expand_channel_meta(log_file_level);
     }
     void expand_channel_meta(map<string,string> &m);
@@ -79,14 +85,21 @@ private:
     }
 
     string get_log_file(const string &channel) {
-      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);
+      generic_dout(25) << __func__ << " for channel '"
+                       << channel << "'" << dendl;
+
+      if (expanded_log_file.count(channel) == 0) {
+        string fname = expand_channel_meta(
+            get_str_map_key(log_file, channel,
+              &CLOG_CHANNEL_DEFAULT),
+            channel);
+        expanded_log_file[channel] = fname;
+
+        generic_dout(20) << __func__ << " for channel '"
+                         << channel << "' expanded to '"
+                         << fname << "'" << dendl;
       }
-      return log_file[channel];
+      return expanded_log_file[channel];
     }
 
     string get_log_file_level(const string &channel) {