ClickHouse/libs/libcommon/include/common/logger_useful.h

52 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
/// Macros for convenient usage of Poco logger.
#include <sstream>
#include <Poco/Logger.h>
2019-07-10 12:19:17 +00:00
#include <Poco/Message.h>
2019-07-16 08:36:50 +00:00
#include <Poco/Version.h>
2019-07-08 16:11:38 +00:00
#include <Core/SettingsCommon.h>
2019-07-09 10:39:05 +00:00
#include <Common/CurrentThread.h>
#ifndef QUERY_PREVIEW_LENGTH
#define QUERY_PREVIEW_LENGTH 160
#endif
using Poco::Logger;
2019-07-10 12:19:17 +00:00
using Poco::Message;
2019-07-08 11:41:54 +00:00
using DB::LogsLevel;
2019-07-09 10:39:05 +00:00
using DB::CurrentThread;
2019-07-08 11:41:54 +00:00
/// Logs a message to a specified logger with that level.
#define LOG_SIMPLE(logger, message, priority, PRIORITY) do \
{ \
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && \
(CurrentThread::getGroup()->client_logs_level >= (priority)); \
if ((logger)->is((PRIORITY)) || is_clients_log) \
{ \
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
if (auto channel = (logger)->getChannel()) \
{ \
std::string file_function; \
file_function += __FILE__; \
file_function += "; "; \
file_function += __PRETTY_FUNCTION__; \
Message poco_message((logger)->name(), oss_internal_rare.str(), \
(PRIORITY), file_function.c_str(), __LINE__); \
channel->log(poco_message); \
} \
} \
2019-07-16 16:45:24 +00:00
} while (false)
2019-07-16 16:27:42 +00:00
2019-07-15 15:25:32 +00:00
2019-07-16 16:45:24 +00:00
#define LOG_TRACE(logger, message) LOG_SIMPLE(logger, message, LogsLevel::trace, Message::PRIO_TRACE)
#define LOG_DEBUG(logger, message) LOG_SIMPLE(logger, message, LogsLevel::debug, Message::PRIO_DEBUG)
#define LOG_INFO(logger, message) LOG_SIMPLE(logger, message, LogsLevel::information, Message::PRIO_INFORMATION)
#define LOG_WARNING(logger, message) LOG_SIMPLE(logger, message, LogsLevel::warning, Message::PRIO_WARNING)
#define LOG_ERROR(logger, message) LOG_SIMPLE(logger, message, LogsLevel::error, Message::PRIO_ERROR)
2019-08-11 20:37:53 +00:00
#define LOG_FATAL(logger, message) LOG_SIMPLE(logger, message, LogsLevel::error, Message::PRIO_FATAL)
2019-07-15 15:25:32 +00:00