From: Joao Eduardo Luis Date: Tue, 26 Aug 2014 15:48:14 +0000 (+0100) Subject: mon: LogMonitor: expand meta variables at time-of-call X-Git-Tag: v0.86~167^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f9e105d14aeba5076ce680d8174863e28890509;p=ceph.git mon: LogMonitor: expand meta variables at time-of-call Instead of expanding it when we updated config options, as that would be nothing but trouble. Signed-off-by: Joao Eduardo Luis --- diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index e0e32ce12762..7a0197bfaab2 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -627,28 +627,35 @@ void LogMonitor::update_log_channels() return; } - channels.expand_channel_meta(); } void LogMonitor::log_channel_info::expand_channel_meta(map &m) { generic_dout(10) << __func__ << " expand map: " << m << dendl; for (map::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 &changed) { diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index d8e799add38e..9a154bd0b808 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -60,6 +60,8 @@ private: expand_channel_meta(log_file_level); } void expand_channel_meta(map &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) {