This commit is contained in:
Pedro Pinto committed 2017-08-07 17:21:12 -04:00
commit 950e7b7e2d
350 files changed
+38599

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
#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 = { {Gen,"Gen"},{Log,"Log"} };
cfg.logger_initial_queue_size = 10;
log::Filter f;
f[Cfg.ordinal] = Warn;
cfg.sinks["console"] = std::make_pair (log::console_sink(),f);
f[Cfg.ordinal] = Info;
cfg.sinks["syslog"] = std::make_pair (log::syslog_sink(),f);
me->logger_hub.config(cfg);
}
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(Cfg,Info,__FILE__,__LINE__,"{0}",msg);
}
void ConfigLog::error(const std::string& msg)
{
if (me->print_errors)
me->logger.enqueue(Cfg,Error,__FILE__,__LINE__,"{0}",msg);
}
void ConfigLog::warning(const std::string& msg)
{
if (me->print_errors)
me->logger.enqueue(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