#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Logger.hpp" Logger& Logger::instance() { static Logger instance; return instance; } Logger::Logger() { // Initialiaz loggers static const std::vector modules = { MOD_AV, MOD_COVER, MOD_DB, MOD_DBUPDATER, MOD_MAIN, MOD_METADATA, MOD_REMOTE, MOD_SERVICE, MOD_TRANSCODE, MOD_UI, }; BOOST_FOREACH(Module module, modules) _loggers[module].add_attribute("Module", boost::log::attributes::constant< Module >(module)); } boost::log::sources::severity_logger< Severity >& Logger::get(Module module) { return _loggers[module]; } void Logger::init(const Config& config) { boost::log::add_common_attributes(); boost::log::register_simple_formatter_factory< Severity, char >("Severity"); if (config.enableFileLogging) { boost::log::add_file_log ( boost::log::keywords::file_name = config.logPath + std::string(".%N"), boost::log::keywords::rotation_size = 10 * 1024 * 1024, boost::log::keywords::open_mode = std::ios_base::app, boost::log::keywords::format = ( boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "[%Y-%m-%d %H:%M:%S]") << " [" << boost::log::expressions::attr< Module >("Module") << "]" << " [" << boost::log::expressions::attr< Severity >("Severity") << "]" << " " << boost::log::expressions::smessage ) ); } if (config.enableConsoleLogging) { boost::log::add_console_log(std::cout, boost::log::keywords::format = ( boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "[%Y-%m-%d %H:%M:%S]") << " [" << boost::log::expressions::attr< Module >("Module") << "]" << " [" << boost::log::expressions::attr< Severity >("Severity") << "]" << " " << boost::log::expressions::smessage ) ); } boost::log::core::get()->set_filter ( boost::log::expressions::attr("Severity") <= config.minSeverity ); }