From: Sage Weil Date: Sat, 22 Feb 2020 16:59:37 +0000 (-0600) Subject: mon/LogMonitor: fix debug output for logmonitor output file parsing X-Git-Tag: v15.1.1~212^2~11 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c0ab4f8c2298a072f97f6ab859ee04b856e70ea4;p=ceph-ci.git mon/LogMonitor: fix debug output for logmonitor output file parsing Signed-off-by: Sage Weil --- diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 3197ddb4b54..73f83230e56 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -33,6 +33,107 @@ #include "include/compat.h" #define dout_subsys ceph_subsys_mon + +string LogMonitor::log_channel_info::get_log_file(const string &channel) +{ + 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_CONFIG_DEFAULT_KEY), + channel); + expanded_log_file[channel] = fname; + + dout(20) << __func__ << " for channel '" + << channel << "' expanded to '" + << fname << "'" << dendl; + } + return expanded_log_file[channel]; +} + + +void LogMonitor::log_channel_info::expand_channel_meta(map &m) +{ + dout(20) << __func__ << " expand map: " << m << dendl; + for (map::iterator p = m.begin(); p != m.end(); ++p) { + m[p->first] = expand_channel_meta(p->second, p->first); + } + dout(20) << __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; + } + dout(20) << __func__ << " from '" << input + << "' to '" << s << "'" << dendl; + + return s; +} + +bool LogMonitor::log_channel_info::do_log_to_syslog(const string &channel) { + string v = get_str_map_key(log_to_syslog, channel, + &CLOG_CONFIG_DEFAULT_KEY); + // We expect booleans, but they are in k/v pairs, kept + // as strings, in 'log_to_syslog'. We must ensure + // compatibility with existing boolean handling, and so + // we are here using a modified version of how + // md_config_t::set_val_raw() handles booleans. We will + // accept both 'true' and 'false', but will also check for + // '1' and '0'. The main distiction between this and the + // original code is that we will assume everything not '1', + // '0', 'true' or 'false' to be 'false'. + bool ret = false; + + if (boost::iequals(v, "false")) { + ret = false; + } else if (boost::iequals(v, "true")) { + ret = true; + } else { + std::string err; + int b = strict_strtol(v.c_str(), 10, &err); + ret = (err.empty() && b == 1); + } + + return ret; +} + +ceph::logging::Graylog::Ref LogMonitor::log_channel_info::get_graylog( + const string &channel) +{ + dout(25) << __func__ << " for channel '" + << channel << "'" << dendl; + + if (graylogs.count(channel) == 0) { + auto graylog(std::make_shared("mon")); + + graylog->set_fsid(g_conf().get_val("fsid")); + graylog->set_hostname(g_conf()->host); + graylog->set_destination(get_str_map_key(log_to_graylog_host, channel, + &CLOG_CONFIG_DEFAULT_KEY), + atoi(get_str_map_key(log_to_graylog_port, channel, + &CLOG_CONFIG_DEFAULT_KEY).c_str())); + + graylogs[channel] = graylog; + dout(20) << __func__ << " for channel '" + << channel << "' to graylog host '" + << log_to_graylog_host[channel] << ":" + << log_to_graylog_port[channel] + << "'" << dendl; + } + return graylogs[channel]; +} + + #undef dout_prefix #define dout_prefix _prefix(_dout, mon, get_last_committed()) static ostream& _prefix(std::ostream *_dout, Monitor *mon, version_t v) { @@ -798,85 +899,6 @@ void LogMonitor::update_log_channels() channels.expand_channel_meta(); } -void LogMonitor::log_channel_info::expand_channel_meta(map &m) -{ - generic_dout(20) << __func__ << " expand map: " << m << dendl; - for (map::iterator p = m.begin(); p != m.end(); ++p) { - m[p->first] = expand_channel_meta(p->second, p->first); - } - generic_dout(20) << __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; -} - -bool LogMonitor::log_channel_info::do_log_to_syslog(const string &channel) { - string v = get_str_map_key(log_to_syslog, channel, - &CLOG_CONFIG_DEFAULT_KEY); - // We expect booleans, but they are in k/v pairs, kept - // as strings, in 'log_to_syslog'. We must ensure - // compatibility with existing boolean handling, and so - // we are here using a modified version of how - // md_config_t::set_val_raw() handles booleans. We will - // accept both 'true' and 'false', but will also check for - // '1' and '0'. The main distiction between this and the - // original code is that we will assume everything not '1', - // '0', 'true' or 'false' to be 'false'. - bool ret = false; - - if (boost::iequals(v, "false")) { - ret = false; - } else if (boost::iequals(v, "true")) { - ret = true; - } else { - std::string err; - int b = strict_strtol(v.c_str(), 10, &err); - ret = (err.empty() && b == 1); - } - - return ret; -} - -ceph::logging::Graylog::Ref LogMonitor::log_channel_info::get_graylog( - const string &channel) -{ - generic_dout(25) << __func__ << " for channel '" - << channel << "'" << dendl; - - if (graylogs.count(channel) == 0) { - auto graylog(std::make_shared("mon")); - - graylog->set_fsid(g_conf().get_val("fsid")); - graylog->set_hostname(g_conf()->host); - graylog->set_destination(get_str_map_key(log_to_graylog_host, channel, - &CLOG_CONFIG_DEFAULT_KEY), - atoi(get_str_map_key(log_to_graylog_port, channel, - &CLOG_CONFIG_DEFAULT_KEY).c_str())); - - graylogs[channel] = graylog; - generic_dout(20) << __func__ << " for channel '" - << channel << "' to graylog host '" - << log_to_graylog_host[channel] << ":" - << log_to_graylog_port[channel] - << "'" << dendl; - } - return graylogs[channel]; -} void LogMonitor::handle_conf_change(const ConfigProxy& conf, const std::set &changed) diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index 215ef485e5a..394403ce353 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -97,22 +97,7 @@ private: &CLOG_CONFIG_DEFAULT_KEY); } - string get_log_file(const string &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_CONFIG_DEFAULT_KEY), - channel); - expanded_log_file[channel] = fname; - - generic_dout(20) << __func__ << " for channel '" - << channel << "' expanded to '" - << fname << "'" << dendl; - } - return expanded_log_file[channel]; - } + string get_log_file(const string &channel); string get_log_file_level(const string &channel) { return get_str_map_key(log_file_level, channel,