ClickHouse/src/Coordination/LoggerWrapper.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
1.8 KiB
C++
Raw Normal View History

2021-01-14 16:20:33 +00:00
#pragma once
2021-10-27 23:10:39 +00:00
#include <libnuraft/nuraft.hxx>
2022-04-27 15:05:45 +00:00
#include <Common/logger_useful.h>
#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 =
{
2024-01-04 07:59:44 +00:00
{LogsLevel::test, Poco::Message::Priority::PRIO_TEST},
2021-02-19 14:13:29 +00:00
{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:
LoggerWrapper(const std::string & name, LogsLevel level_)
2024-01-23 17:04:50 +00:00
: log(getLogger(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), fmt::runtime(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:
2024-01-23 17:04:50 +00:00
LoggerPtr log;
2021-02-19 14:13:29 +00:00
std::atomic<LogsLevel> level;
2021-01-14 16:20:33 +00:00
};
}