/*
* 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
#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::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 (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
);
}