2015-09-29 19:21:02 +00:00
|
|
|
#pragma once
|
2017-02-02 14:19:13 +00:00
|
|
|
|
|
|
|
/// Macros for convenient usage of Poco logger.
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
2019-07-08 16:11:38 +00:00
|
|
|
#include <atomic>
|
2015-09-29 19:21:02 +00:00
|
|
|
#include <Poco/Logger.h>
|
2019-07-10 12:19:17 +00:00
|
|
|
#include <Poco/Message.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>
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2015-09-29 19:21:02 +00:00
|
|
|
/// Logs a message to a specified logger with that level.
|
|
|
|
|
2019-07-15 15:25:32 +00:00
|
|
|
#if defined(POCO_CLICKHOUSE_PATCH)
|
|
|
|
|
|
|
|
#define LOG_TRACE(logger, message) do { \
|
|
|
|
if ((logger)->trace()) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
|
|
|
oss_internal_rare << message; \
|
|
|
|
(logger)->trace(oss_internal_rare.str());}} while(false)
|
|
|
|
|
|
|
|
#define LOG_DEBUG(logger, message) do { \
|
|
|
|
if ((logger)->debug()) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
|
|
|
oss_internal_rare << message; \
|
|
|
|
(logger)->debug(oss_internal_rare.str());}} while(false)
|
|
|
|
|
|
|
|
#define LOG_INFO(logger, message) do { \
|
|
|
|
if ((logger)->information()) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
|
|
|
oss_internal_rare << message; \
|
|
|
|
(logger)->information(oss_internal_rare.str());}} while(false)
|
|
|
|
|
|
|
|
#define LOG_WARNING(logger, message) do { \
|
|
|
|
if ((logger)->warning()) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
|
|
|
oss_internal_rare << message; \
|
|
|
|
(logger)->warning(oss_internal_rare.str());}} while(false)
|
|
|
|
|
|
|
|
#define LOG_ERROR(logger, message) do { \
|
|
|
|
if ((logger)->error()) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
|
|
|
oss_internal_rare << message; \
|
|
|
|
(logger)->error(oss_internal_rare.str());}} while(false)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-09-29 19:21:02 +00:00
|
|
|
#define LOG_TRACE(logger, message) do { \
|
2019-07-10 12:19:17 +00:00
|
|
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && (CurrentThread::getGroup()->client_logs_level >= LogsLevel::trace); \
|
|
|
|
if ((logger)->trace() || is_clients_log) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
2017-04-01 07:20:54 +00:00
|
|
|
oss_internal_rare << message; \
|
2019-07-10 12:19:17 +00:00
|
|
|
if (is_clients_log) {\
|
|
|
|
(logger)->force_log(oss_internal_rare.str(), Message::PRIO_TRACE); \
|
|
|
|
} else { \
|
|
|
|
(logger)->trace(oss_internal_rare.str()); \
|
|
|
|
}}} while(false)
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#define LOG_DEBUG(logger, message) do { \
|
2019-07-10 12:19:17 +00:00
|
|
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && (CurrentThread::getGroup()->client_logs_level >= LogsLevel::debug); \
|
|
|
|
if ((logger)->debug() || is_clients_log) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
2017-04-01 07:20:54 +00:00
|
|
|
oss_internal_rare << message; \
|
2019-07-10 12:19:17 +00:00
|
|
|
if (is_clients_log) {\
|
|
|
|
(logger)->force_log(oss_internal_rare.str(), Message::PRIO_DEBUG); \
|
|
|
|
} else { \
|
|
|
|
(logger)->debug(oss_internal_rare.str()); \
|
|
|
|
}}} while(false)
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#define LOG_INFO(logger, message) do { \
|
2019-07-10 12:19:17 +00:00
|
|
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && (CurrentThread::getGroup()->client_logs_level >= LogsLevel::information); \
|
|
|
|
if ((logger)->information() || is_clients_log) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
2017-04-01 07:20:54 +00:00
|
|
|
oss_internal_rare << message; \
|
2019-07-10 12:19:17 +00:00
|
|
|
if (is_clients_log) {\
|
|
|
|
(logger)->force_log(oss_internal_rare.str(), Message::PRIO_INFORMATION); \
|
|
|
|
} else { \
|
|
|
|
(logger)->information(oss_internal_rare.str()); \
|
|
|
|
}}} while(false)
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#define LOG_WARNING(logger, message) do { \
|
2019-07-10 12:19:17 +00:00
|
|
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && (CurrentThread::getGroup()->client_logs_level >= LogsLevel::warning); \
|
|
|
|
if ((logger)->warning() || is_clients_log) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
2017-04-01 07:20:54 +00:00
|
|
|
oss_internal_rare << message; \
|
2019-07-10 12:19:17 +00:00
|
|
|
if (is_clients_log) {\
|
|
|
|
(logger)->force_log(oss_internal_rare.str(), Message::PRIO_WARNING); \
|
|
|
|
} else { \
|
|
|
|
(logger)->warning(oss_internal_rare.str()); \
|
|
|
|
}}} while(false)
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
#define LOG_ERROR(logger, message) do { \
|
2019-07-10 12:19:17 +00:00
|
|
|
const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && (CurrentThread::getGroup()->client_logs_level >= LogsLevel::error); \
|
|
|
|
if ((logger)->error() || is_clients_log) {\
|
|
|
|
std::stringstream oss_internal_rare; \
|
2017-04-01 07:20:54 +00:00
|
|
|
oss_internal_rare << message; \
|
2019-07-10 12:19:17 +00:00
|
|
|
if (is_clients_log) {\
|
|
|
|
(logger)->force_log(oss_internal_rare.str(), Message::PRIO_ERROR); \
|
|
|
|
} else { \
|
|
|
|
(logger)->error(oss_internal_rare.str()); \
|
|
|
|
}}} while(false)
|
2019-07-15 15:25:32 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|