From 3760bc1b460fb81effdb18e79a207400a1d41bbf Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Fri, 19 Sep 2014 17:24:49 +0100 Subject: [PATCH] mon: LogMonitor: appropriately expand channel meta variables 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 --- src/mon/LogMonitor.cc | 1 + src/mon/LogMonitor.h | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 73c5bc5a52d7..422da91ddad2 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -634,6 +634,7 @@ void LogMonitor::update_log_channels() return; } + channels.expand_channel_meta(); } void LogMonitor::log_channel_info::expand_channel_meta(map &m) diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index 2826304bfeb9..cf870130e43a 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -42,6 +42,7 @@ private: map syslog_level; map syslog_facility; map log_file; + map expanded_log_file; map 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 &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) { -- 2.47.3