116 lines
2.3 KiB
C++
Executable File
116 lines
2.3 KiB
C++
Executable File
#include "ConfigLog.h"
|
|
|
|
#include "lib/logging/logging.h"
|
|
|
|
namespace bts {
|
|
namespace config {
|
|
namespace internal {
|
|
|
|
struct ConfigLog::PImpl {
|
|
PImpl()
|
|
:
|
|
print_errors(true),
|
|
logger_hub("config_logger"),
|
|
logger(logger_hub.make_logger())
|
|
{
|
|
}
|
|
|
|
bool print_errors;
|
|
log::LoggerHub logger_hub;
|
|
log::Logger &logger;
|
|
};
|
|
|
|
ConfigLog::ConfigLog() :
|
|
me (new PImpl())
|
|
{
|
|
log::LoggingConfig cfg;
|
|
cfg.level_names = { {Diag,"Diag"},{Info,"Info"},
|
|
{Warn,"Warn"},{Error,"Error"},
|
|
{Fatal,"Fatal"},{Sys,"Sys"} };
|
|
cfg.subsystem_names = { {log::Gen,"Gen"},{log::Log,"Log"} };
|
|
|
|
cfg.logger_initial_queue_size = 10;
|
|
|
|
log::Filter f;
|
|
for (auto &l : f)
|
|
l = Warn;
|
|
|
|
cfg.deployment_type = "Config";
|
|
f[log::Cfg.ordinal] = Warn;
|
|
cfg.sinks["console"] = std::make_pair (log::console_sink(cfg),f);
|
|
f[log::Cfg.ordinal] = Info;
|
|
cfg.sinks["syslog"] = std::make_pair (log::syslog_sink(cfg),f);
|
|
me->logger_hub.config(cfg);
|
|
|
|
start();
|
|
}
|
|
|
|
void ConfigLog::start()
|
|
{
|
|
me->logger_hub.start();
|
|
}
|
|
|
|
ConfigLog::~ConfigLog()
|
|
{
|
|
me->logger.mark_inactive();
|
|
}
|
|
|
|
bool ConfigLog::print_errors() const {return me->print_errors;}
|
|
void ConfigLog::set_print_errors(bool value) {me->print_errors = value;}
|
|
|
|
void ConfigLog::info(const std::string& msg)
|
|
{
|
|
if (me->print_errors)
|
|
me->logger.enqueue(log::log_ts(),log::Cfg,Info,__FILE__,__LINE__,"{0}",msg);
|
|
}
|
|
|
|
void ConfigLog::error(const std::string& msg)
|
|
{
|
|
if (me->print_errors)
|
|
me->logger.enqueue(log::log_ts(),log::Cfg,Error,__FILE__,__LINE__,"{0}",msg);
|
|
}
|
|
|
|
void ConfigLog::warning(const std::string& msg)
|
|
{
|
|
if (me->print_errors)
|
|
me->logger.enqueue(log::log_ts(),log::Cfg,Warn,__FILE__,__LINE__,"{0}",msg);
|
|
}
|
|
|
|
//
|
|
// Log Aggregator
|
|
|
|
LogAggregator::LogAggregator(IConfigLog& log) :
|
|
_log(log),
|
|
_buffer()
|
|
{
|
|
}
|
|
|
|
void LogAggregator::info(const std::string& msg) {
|
|
_buffer << msg;
|
|
#ifdef _WIN32
|
|
_buffer << std::endl;
|
|
#else
|
|
_buffer << " ";
|
|
#endif
|
|
}
|
|
|
|
void LogAggregator::error(const std::string& msg) {
|
|
_log.error(msg);
|
|
}
|
|
|
|
void LogAggregator::warning(const std::string& msg) {
|
|
_log.warning(msg);
|
|
_buffer << "> Warning: " << msg << std::endl;
|
|
#ifdef _WIN32
|
|
_buffer << std::endl;
|
|
#else
|
|
_buffer << " ";
|
|
#endif
|
|
}
|
|
|
|
std::string LogAggregator::text() { return _buffer.str(); }
|
|
|
|
|
|
}}}//namespace
|
|
|