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

Use switch-case to parse configured log level

parent ca902ea7
......@@ -155,6 +155,24 @@ using migrate_atom = atom_constant<atom("migrate")>;
/// Used for triggering periodic operations.
using tick_atom = atom_constant<atom("tick")>;
/// Used as config parameter for the `logger`.
using trace_log_lvl_atom = atom_constant<atom("TRACE")>;
/// Used as config parameter for the `logger`.
using debug_log_lvl_atom = atom_constant<atom("DEBUG")>;
/// Used as config parameter for the `logger`.
using info_log_lvl_atom = atom_constant<atom("INFO")>;
/// Used as config parameter for the `logger`.
using warning_log_lvl_atom = atom_constant<atom("WARNING")>;
/// Used as config parameter for the `logger`.
using error_log_lvl_atom = atom_constant<atom("ERROR")>;
/// Used as config parameter for the `logger`.
using quiet_log_lvl_atom = atom_constant<atom("QUIET")>;
} // namespace caf
namespace std {
......
......@@ -345,25 +345,39 @@ void logger::run() {
void logger::start() {
#if defined(CAF_LOG_LEVEL)
auto& lvl = system_.config().logger_verbosity;
if (lvl == atom("QUIET"))
auto lvl_atom = system_.config().logger_verbosity;
switch (static_cast<uint64_t>(lvl_atom)) {
case quiet_log_lvl_atom::uint_value():
return;
if (lvl == atom("ERROR"))
case error_log_lvl_atom::uint_value():
level_ = CAF_LOG_LEVEL_ERROR;
else if (lvl == atom("WARNING"))
break;
case warning_log_lvl_atom::uint_value():
level_ = CAF_LOG_LEVEL_WARNING;
else if (lvl == atom("INFO"))
break;
case info_log_lvl_atom::uint_value():
level_ = CAF_LOG_LEVEL_INFO;
else if (lvl == atom("DEBUG"))
break;
case debug_log_lvl_atom::uint_value():
level_ = CAF_LOG_LEVEL_DEBUG;
else if (lvl == atom("TRACE"))
break;
case trace_log_lvl_atom::uint_value():
level_ = CAF_LOG_LEVEL_TRACE;
else
break;
default: {
constexpr atom_value level_names[] = {
error_log_lvl_atom::value, warning_log_lvl_atom::value,
info_log_lvl_atom::value, debug_log_lvl_atom::value,
trace_log_lvl_atom::value};
lvl_atom = level_names[CAF_LOG_LEVEL];
level_ = CAF_LOG_LEVEL;
}
}
thread_ = std::thread{[this] { this->run(); }};
std::string msg = "ENTRY log level = ";
const char* levels[] = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"};
msg += levels[level_];
std::string msg = "ENTRY level = ";
msg += to_string(lvl_atom);
msg += ", node = ";
msg += to_string(system_.node());
log(CAF_LOG_LEVEL_INFO, "caf", "caf::logger", "run", __FILE__, __LINE__, msg);
#endif
}
......
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