/* * Copyright (C) 2013 Emeric Poupon * * This file is part of LMS. * * LMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LMS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LMS. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config/ConfigReader.hpp" #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, }; for(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() { boost::log::add_common_attributes(); boost::log::register_simple_formatter_factory< Severity, char >("Severity"); if (ConfigReader::instance().getBool("main.logger.file.enable", false)) { boost::log::add_file_log ( boost::log::keywords::file_name = ConfigReader::instance().getString("main.logger.file.path") + std::string(".%N"), boost::log::keywords::rotation_size = 10 * 1024 * 1024, boost::log::keywords::open_mode = std::ios_base::app, boost::log::keywords::auto_flush = true, 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 (ConfigReader::instance().getBool("main.logger.console.enable", false)) { 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") <= ConfigReader::instance().getULong("main.logger.level", SEV_DEBUG) ); }