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

49 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
/// Macros for convenient usage of Poco logger.
#include <sstream>
#include <Poco/Logger.h>
2019-07-08 11:41:54 +00:00
#include <../../../../dbms/src/Core/SettingsCommon.h>
#ifndef QUERY_PREVIEW_LENGTH
#define QUERY_PREVIEW_LENGTH 160
#endif
using Poco::Logger;
2019-07-08 11:41:54 +00:00
using DB::LogsLevel;
2019-07-08 14:49:04 +00:00
POCO_UNUSED static std::atomic<LogsLevel> CLIENT_LOGS_LEVEL = LogsLevel::none;
/// Logs a message to a specified logger with that level.
#define LOG_TRACE(logger, message) do { \
2019-07-08 11:41:54 +00:00
if ((logger)->trace() || CLIENT_LOGS_LEVEL >= LogsLevel::trace) {\
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
(logger)->trace(oss_internal_rare.str());}} while(false)
#define LOG_DEBUG(logger, message) do { \
2019-07-08 11:41:54 +00:00
if ((logger)->debug() || CLIENT_LOGS_LEVEL >= LogsLevel::debug) {\
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
(logger)->debug(oss_internal_rare.str());}} while(false)
#define LOG_INFO(logger, message) do { \
2019-07-08 11:41:54 +00:00
if ((logger)->information() || CLIENT_LOGS_LEVEL >= LogsLevel::information) {\
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
(logger)->information(oss_internal_rare.str());}} while(false)
#define LOG_WARNING(logger, message) do { \
2019-07-08 11:41:54 +00:00
if ((logger)->warning() || CLIENT_LOGS_LEVEL >= LogsLevel::warning) {\
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
(logger)->warning(oss_internal_rare.str());}} while(false)
#define LOG_ERROR(logger, message) do { \
2019-07-08 11:41:54 +00:00
if ((logger)->error() || CLIENT_LOGS_LEVEL >= LogsLevel::error) {\
std::stringstream oss_internal_rare; \
oss_internal_rare << message; \
(logger)->error(oss_internal_rare.str());}} while(false)