Commit 5ea96794 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'topic/component-blacklist'

parents b3b8fc9b 1f8a509b
......@@ -73,5 +73,5 @@ console-format="%m"
; configures the minimum severity of messages that are written to the console
; (quiet|error|warning|info|debug|trace)
console-verbosity='trace'
; excludes listed components from logging
component-filter=""
; excludes listed components from logging (list of atoms)
component-blacklist=[]
......@@ -28,11 +28,12 @@
#include <unordered_map>
#include "caf/abstract_actor.hpp"
#include "caf/atom.hpp"
#include "caf/config.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/arg_wrapper.hpp"
#include "caf/detail/pretty_type_name.hpp"
#include "caf/detail/log_level.hpp"
#include "caf/detail/pretty_type_name.hpp"
#include "caf/detail/ringbuffer.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/detail/shared_spinlock.hpp"
......@@ -113,7 +114,7 @@ public:
event& operator=(const event&) = default;
event(unsigned lvl, unsigned line, string_view cat, string_view full_fun,
event(unsigned lvl, unsigned line, atom_value cat, string_view full_fun,
string_view fun, string_view fn, std::string msg, std::thread::id t,
actor_id a, timestamp ts);
......@@ -126,7 +127,7 @@ public:
unsigned line_number;
/// Name of the category (component) logging the event.
string_view category_name;
atom_value category_name;
/// Name of the current function as reported by `__PRETTY_FUNCTION__`.
string_view pretty_fun;
......@@ -228,7 +229,7 @@ public:
/// Returns whether the logger is configured to accept input for given
/// component and log level.
bool accepts(unsigned level, string_view component_name);
bool accepts(unsigned level, atom_value component_name);
/// Returns the output format used for the log file.
const line_format& file_format() const {
......@@ -345,7 +346,7 @@ private:
config cfg_;
// Filters events by component name.
std::string component_filter;
std::vector<atom_value> component_blacklist;
// References the parent system.
actor_system& system_;
......@@ -416,7 +417,7 @@ bool operator==(const logger::field& x, const logger::field& y);
#define CAF_LOG_MAKE_EVENT(aid, component, loglvl, message) \
::caf::logger::event { \
loglvl, __LINE__, component, CAF_PRETTY_FUN, __func__, \
loglvl, __LINE__, caf::atom(component), CAF_PRETTY_FUN, __func__, \
caf::logger::skip_path(__FILE__), \
(::caf::logger::line_builder{} << message).get(), \
::std::this_thread::get_id(), aid, ::caf::make_timestamp() \
......@@ -457,7 +458,7 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
do { \
auto CAF_UNIFYN(caf_logger) = caf::logger::current_logger(); \
if (CAF_UNIFYN(caf_logger) != nullptr \
&& CAF_UNIFYN(caf_logger)->accepts(loglvl, component)) \
&& CAF_UNIFYN(caf_logger)->accepts(loglvl, caf::atom(component))) \
CAF_UNIFYN(caf_logger) \
->log(CAF_LOG_MAKE_EVENT(CAF_UNIFYN(caf_logger)->thread_local_aid(), \
component, loglvl, message)); \
......@@ -563,7 +564,7 @@ inline caf::actor_id caf_set_aid_dummy() { return 0; }
/// The log component responsible for logging control flow events that are
/// crucial for understanding happens-before relations. See RFC SE-0001.
#define CAF_LOG_FLOW_COMPONENT "caf.flow"
#define CAF_LOG_FLOW_COMPONENT "caf_flow"
#define CAF_LOG_SPAWN_EVENT(ref, ctor_data) \
CAF_LOG_IMPL(CAF_LOG_FLOW_COMPONENT, CAF_LOG_LEVEL_DEBUG, \
......
......@@ -35,7 +35,7 @@ R make_actor(actor_id aid, node_id nid, actor_system* sys, Ts&&... xs) {
#if CAF_LOG_LEVEL >= CAF_LOG_LEVEL_DEBUG
actor_storage<T>* ptr = nullptr;
if (logger::current_logger()->accepts(CAF_LOG_LEVEL_DEBUG,
CAF_LOG_FLOW_COMPONENT)) {
caf::atom(CAF_LOG_FLOW_COMPONENT))) {
std::string args;
args = deep_to_string(std::forward_as_tuple(xs...));
ptr = new actor_storage<T>(aid, std::move(nid), sys,
......
......@@ -305,6 +305,20 @@ std::string to_string(const optional<T>& x) {
return x ? "*" + deep_to_string(*x) : "none";
}
/// Returns an rvalue to the value managed by `x`.
/// @relates optional
template <class T>
T&& move_if_optional(optional<T>& x) {
return std::move(*x);
}
/// Returns `*x`.
/// @relates optional
template <class T>
T& move_if_optional(T* x) {
return *x;
}
// -- [X.Y.8] comparison with optional ----------------------------------------
/// @relates optional
......@@ -493,4 +507,3 @@ bool operator>=(const T& lhs, const optional<T>& rhs) {
}
} // namespace caf
......@@ -157,7 +157,9 @@ actor_system_config::actor_system_config()
"sets the console output verbosity "
"(quiet|error|warning|info|debug|trace)")
.add(logger_component_filter, "component-filter",
"exclude all listed components from logging")
"DEPRECATED/IGNORED, use component-blacklist instead")
.add<std::vector<atom_value>>("component-blacklist",
"exclude all listed components from logging")
.add(logger_verbosity, "verbosity",
"set file and console verbosity (deprecated)")
.add(logger_inline_output, "inline-output",
......
......@@ -254,7 +254,7 @@ logger::config::config()
// nop
}
logger::event::event(unsigned lvl, unsigned line, string_view cat,
logger::event::event(unsigned lvl, unsigned line, atom_value cat,
string_view full_fun, string_view fun, string_view fn,
std::string msg, std::thread::id t, actor_id a,
timestamp ts)
......@@ -351,15 +351,11 @@ logger* logger::current_logger() {
return get_current_logger();
}
bool logger::accepts(unsigned level, string_view cname) {
bool logger::accepts(unsigned level, atom_value cname) {
if (level > cfg_.verbosity)
return false;
if (!component_filter.empty()) {
auto it = std::search(component_filter.begin(), component_filter.end(),
cname.begin(), cname.end());
return it != component_filter.end();
}
return true;
return !std::any_of(component_blacklist.begin(), component_blacklist.end(),
[=](atom_value name) { return name == cname; });
}
logger::logger(actor_system& sys) : system_(sys) {
......@@ -377,8 +373,10 @@ logger::~logger() {
void logger::init(actor_system_config& cfg) {
CAF_IGNORE_UNUSED(cfg);
namespace lg = defaults::logger;
component_filter = get_or(cfg, "logger.component-filter",
lg::component_filter);
using atom_list = std::vector<atom_value>;
auto blacklist = get_if<atom_list>(&cfg, "logger.component-blacklist");
if (blacklist)
component_blacklist = move_if_optional(blacklist);
// Parse the configured log level.
auto verbosity = get_if<atom_value>(&cfg, "logger.verbosity");
auto file_verbosity = verbosity ? *verbosity : lg::file_verbosity;
......@@ -476,7 +474,7 @@ void logger::render(std::ostream& out, const line_format& lf,
const event& x) const {
for (auto& f : lf)
switch (f.kind) {
case category_field: out << x.category_name; break;
case category_field: out << to_string(x.category_name); break;
case class_name_field: render_fun_prefix(out, x); break;
case date_field: render_date(out, x.tstamp); break;
case file_field: out << x.file_name; break;
......@@ -617,8 +615,8 @@ void logger::log_first_line() {
msg += to_string(get_or(system_.config(), config_name, default_value));
msg += ", node = ";
msg += to_string(system_.node());
msg += ", component_filter = ";
msg += deep_to_string(component_filter);
msg += ", component-blacklist = ";
msg += deep_to_string(component_blacklist);
return msg;
};
namespace lg = defaults::logger;
......
......@@ -180,7 +180,7 @@ CAF_TEST(rendering) {
logger::event e{
CAF_LOG_LEVEL_WARNING,
42,
"unit.test",
atom("unit_test"),
"void ns::foo::bar()",
"bar",
"foo.cpp",
......@@ -199,7 +199,7 @@ CAF_TEST(rendering) {
using namespace std::placeholders;
auto render_event = bind(&logger::render, &lg, _1, _2, _3);
CAF_CHECK_EQUAL(render(render_event, lf, e),
"unit.test WARN actor0 ns.foo bar foo.cpp:42 hello world");
"unit_test WARN actor0 ns.foo bar foo.cpp:42 hello world");
}
CAF_TEST(render_fun_prefix) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment