trace_logger: remove false warnings from the log

This patch eliminates warnings that occurred as side effect of using the
'Session_policy' utility ("Warning: no policy defined for label...").
The new version uses the 'with_matching_policy' function instead, which
has the nice side effect of simplifying the error handling.
This commit is contained in:
Norman Feske 2022-02-04 12:36:08 +01:00
parent 6eaeb61d58
commit 479f2e0d1f

View File

@ -93,13 +93,19 @@ class Main
_trace.for_each_subject_info([&] (Trace::Subject_id const id, _trace.for_each_subject_info([&] (Trace::Subject_id const id,
Trace::Subject_info const &info) { Trace::Subject_info const &info) {
try {
/* skip dead subjects */ /* skip dead subjects */
if (info.state() == Trace::Subject_info::DEAD) if (info.state() == Trace::Subject_info::DEAD)
return; return;
/* check if there is a matching policy in the XML config */ Session_label const label(info.session_label());
Session_policy session_policy = _session_policy(info); with_matching_policy(label, _config,
[&] (Xml_node const &policy) {
if (policy.has_attribute("thread"))
if (policy.attribute_value("thread", Thread_name()) != info.thread_name())
return;
try { try {
/* lookup monitor by subject ID */ /* lookup monitor by subject ID */
Monitor &monitor = old_monitors.find_by_subject_id(id); Monitor &monitor = old_monitors.find_by_subject_id(id);
@ -113,11 +119,11 @@ class Main
} catch (Monitor_tree::No_match) { } catch (Monitor_tree::No_match) {
/* create monitor for subject in the new tree */ /* create monitor for subject in the new tree */
_new_monitor(new_monitors, id, info, session_policy); _new_monitor(new_monitors, id, info, policy);
} }
} },
catch (Trace::Nonexistent_subject ) { return; } [&] () { /* no policy matches */ }
catch (Session_policy::No_policy_defined) { return; } );
}); });
/* all monitors in the old tree are deprecated, destroy them */ /* all monitors in the old tree are deprecated, destroy them */
@ -147,7 +153,7 @@ class Main
void _new_monitor(Monitor_tree &monitors, void _new_monitor(Monitor_tree &monitors,
Trace::Subject_id const id, Trace::Subject_id const id,
Trace::Subject_info const &info, Trace::Subject_info const &info,
Session_policy const &session_policy) Xml_node const &session_policy)
{ {
try { try {
Number_of_bytes const buffer_sz = session_policy.attribute_value("buffer", _default_buf_sz); Number_of_bytes const buffer_sz = session_policy.attribute_value("buffer", _default_buf_sz);
@ -174,17 +180,6 @@ class Main
log("new monitor: subject ", id.id); log("new monitor: subject ", id.id);
} }
Session_policy _session_policy(Trace::Subject_info const &info)
{
Session_label const label(info.session_label());
Session_policy policy(label, _config);
if (policy.has_attribute("thread"))
if (policy.attribute_value("thread", Thread_name()) != info.thread_name())
throw Session_policy::No_policy_defined();
return policy;
}
public: public:
Main(Env &env) : _env(env) { _policies.insert(_default_policy); } Main(Env &env) : _env(env) { _policies.insert(_default_policy); }