11#include <boost/log/common.hpp>
12#include <boost/log/utility/setup/console.hpp>
13#include <boost/log/utility/setup/file.hpp>
18const std::map<std::string, Logged::level> Logged::levelNames = {
19 {
"all", level::ALL },
20 {
"All", level::ALL },
21 {
"ALL", level::ALL },
22 {
"trace", level::TRACE },
23 {
"TRACE", level::TRACE },
24 {
"debug", level::DEBUG_LVL },
25 {
"DEBUG", level::DEBUG_LVL },
26 {
"info", level::INFO },
27 {
"INFO", level::INFO },
28 {
"warning", level::WARNING },
29 {
"WARNING", level::WARNING },
30 {
"error", level::ERROR },
31 {
"ERROR", level::ERROR },
32 {
"critical", level::CRITICAL },
33 {
"CRITICAL", level::CRITICAL },
34 {
"fatal", level::CRITICAL },
35 {
"FATAL", level::CRITICAL },
36 {
"alert", level::ALERT },
37 {
"ALERT", level::ALERT },
38 {
"emergency", level::EMERGENCY },
39 {
"EMERGENCY", level::EMERGENCY },
40 {
"none", level::NONE },
41 {
"None", level::NONE },
42 {
"NONE", level::NONE },
45const std::map<int, std::string> keyMap = {
46 { Logged::MINIMUM_LOG_LEVEL_KEY,
"Logged.minimum_log_level" },
47 { Logged::FILE_NAME_PATTERN_KEY,
"Logged.file_name_pattern" },
48 { Logged::CONSOLE_LOG_LEVEL_KEY,
"Logged.console_log_level" },
50BOOST_LOG_ATTRIBUTE_KEYWORD(Severity,
"Severity", Logged::level)
52boost::log::sources::severity_logger<Logged::level> sl;
58 keyMap.at(MINIMUM_LOG_LEVEL_KEY), std::string(
"info")));
60 keyMap.at(FILE_NAME_PATTERN_KEY), std::string(
"nextsim.%T.log"));
61 boost::log::add_file_log(boost::log::keywords::file_name = fileNamePattern,
63 boost::log::keywords::filter = (Severity >= minimumLogLevel));
66 keyMap.at(CONSOLE_LOG_LEVEL_KEY), std::string(
"none")));
67 boost::log::add_console_log(
68 std::cout, boost::log::keywords::filter = (Severity >= consoleLogLevel));
71void Logged::log(
const std::string& message, Logged::level lvl)
73 BOOST_LOG_SEV(sl, lvl) << message;
static void configure()
Static function that configures the logger.
static void log(const std::string &message, const level lvl=level::NOTICE)
Logs a message at the given log level, or default to level::NOTICE.