1#pragma once
2
3/// Macros for convenient usage of Poco logger.
4
5#include <sstream>
6#include <Poco/Logger.h>
7#include <Poco/Message.h>
8#include <Poco/Version.h>
9#include <Common/CurrentThread.h>
10
11#ifndef QUERY_PREVIEW_LENGTH
12#define QUERY_PREVIEW_LENGTH 160
13#endif
14
15using Poco::Logger;
16using Poco::Message;
17using DB::LogsLevel;
18using DB::CurrentThread;
19
20/// Logs a message to a specified logger with that level.
21
22#define LOG_SIMPLE(logger, message, priority, PRIORITY) do \
23{ \
24 const bool is_clients_log = (CurrentThread::getGroup() != nullptr) && \
25 (CurrentThread::getGroup()->client_logs_level >= (priority)); \
26 if ((logger)->is((PRIORITY)) || is_clients_log) \
27 { \
28 std::stringstream oss_internal_rare; \
29 oss_internal_rare << message; \
30 if (auto channel = (logger)->getChannel()) \
31 { \
32 std::string file_function; \
33 file_function += __FILE__; \
34 file_function += "; "; \
35 file_function += __PRETTY_FUNCTION__; \
36 Message poco_message((logger)->name(), oss_internal_rare.str(), \
37 (PRIORITY), file_function.c_str(), __LINE__); \
38 channel->log(poco_message); \
39 } \
40 } \
41} while (false)
42
43
44#define LOG_TRACE(logger, message) LOG_SIMPLE(logger, message, LogsLevel::trace, Message::PRIO_TRACE)
45#define LOG_DEBUG(logger, message) LOG_SIMPLE(logger, message, LogsLevel::debug, Message::PRIO_DEBUG)
46#define LOG_INFO(logger, message) LOG_SIMPLE(logger, message, LogsLevel::information, Message::PRIO_INFORMATION)
47#define LOG_WARNING(logger, message) LOG_SIMPLE(logger, message, LogsLevel::warning, Message::PRIO_WARNING)
48#define LOG_ERROR(logger, message) LOG_SIMPLE(logger, message, LogsLevel::error, Message::PRIO_ERROR)
49#define LOG_FATAL(logger, message) LOG_SIMPLE(logger, message, LogsLevel::error, Message::PRIO_FATAL)
50
51