2021-01-14 16:20:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-02-08 13:50:03 +00:00
|
|
|
#include <libnuraft/nuraft.hxx> // Y_IGNORE
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/logger_useful.h>
|
2021-02-10 09:28:53 +00:00
|
|
|
#include <Core/SettingsEnums.h>
|
2021-01-14 16:20:33 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class LoggerWrapper : public nuraft::logger
|
|
|
|
{
|
2021-02-19 14:13:29 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
static inline const std::unordered_map<LogsLevel, Poco::Message::Priority> LEVELS =
|
|
|
|
{
|
|
|
|
{LogsLevel::trace, Poco::Message::Priority::PRIO_TRACE},
|
|
|
|
{LogsLevel::debug, Poco::Message::Priority::PRIO_DEBUG},
|
|
|
|
{LogsLevel::information, Poco::Message::PRIO_INFORMATION},
|
|
|
|
{LogsLevel::warning, Poco::Message::PRIO_WARNING},
|
|
|
|
{LogsLevel::error, Poco::Message::PRIO_ERROR},
|
|
|
|
{LogsLevel::fatal, Poco::Message::PRIO_FATAL}
|
|
|
|
};
|
|
|
|
static inline const int LEVEL_MAX = static_cast<int>(LogsLevel::trace);
|
|
|
|
static inline const int LEVEL_MIN = static_cast<int>(LogsLevel::none);
|
|
|
|
|
2021-01-14 20:43:52 +00:00
|
|
|
public:
|
2021-02-10 09:28:53 +00:00
|
|
|
LoggerWrapper(const std::string & name, LogsLevel level_)
|
2021-01-14 16:20:33 +00:00
|
|
|
: log(&Poco::Logger::get(name))
|
2021-02-19 14:13:29 +00:00
|
|
|
, level(level_)
|
2021-01-25 10:19:02 +00:00
|
|
|
{
|
2021-02-19 14:13:29 +00:00
|
|
|
log->setLevel(static_cast<int>(LEVELS.at(level)));
|
2021-01-25 10:19:02 +00:00
|
|
|
}
|
2021-01-14 16:20:33 +00:00
|
|
|
|
|
|
|
void put_details(
|
2021-01-26 08:17:19 +00:00
|
|
|
int level_,
|
2021-01-14 16:20:33 +00:00
|
|
|
const char * /* source_file */,
|
|
|
|
const char * /* func_name */,
|
|
|
|
size_t /* line_number */,
|
|
|
|
const std::string & msg) override
|
|
|
|
{
|
2021-02-19 14:13:29 +00:00
|
|
|
LogsLevel db_level = static_cast<LogsLevel>(level_);
|
|
|
|
LOG_IMPL(log, db_level, LEVELS.at(db_level), msg);
|
2021-01-14 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 08:17:19 +00:00
|
|
|
void set_level(int level_) override
|
2021-01-14 16:20:33 +00:00
|
|
|
{
|
2021-02-19 14:13:29 +00:00
|
|
|
level_ = std::min(LEVEL_MAX, std::max(LEVEL_MIN, level_));
|
|
|
|
level = static_cast<LogsLevel>(level_);
|
|
|
|
log->setLevel(static_cast<int>(LEVELS.at(level)));
|
2021-01-14 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_level() override
|
|
|
|
{
|
2021-02-19 14:13:29 +00:00
|
|
|
LogsLevel lvl = level;
|
|
|
|
return static_cast<int>(lvl);
|
2021-01-14 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 20:43:52 +00:00
|
|
|
private:
|
2021-01-14 16:20:33 +00:00
|
|
|
Poco::Logger * log;
|
2021-02-19 14:13:29 +00:00
|
|
|
std::atomic<LogsLevel> level;
|
2021-01-14 16:20:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|