#pragma once #include #include #include #include #include "ExtendedLogChannel.h" #include "OwnJSONPatternFormatter.h" #include "OwnPatternFormatter.h" namespace DB { // Like Poco::FormattingChannel but supports the extended logging interface and log level filter class OwnFormattingChannel : public Poco::Channel, public ExtendedLogChannel { public: explicit OwnFormattingChannel( Poco::AutoPtr pFormatter_ = nullptr, Poco::AutoPtr pChannel_ = nullptr) : pFormatter(pFormatter_), pChannel(pChannel_), priority(Poco::Message::PRIO_TRACE) { } void setChannel(Poco::AutoPtr pChannel_) { pChannel = pChannel_; } void setLevel(Poco::Message::Priority priority_) { priority = priority_; } // Poco::Logger::parseLevel returns ints void setLevel(int level) { priority = static_cast(level); } void open() override { if (pChannel) pChannel->open(); } void close() override { if (pChannel) pChannel->close(); } void setProperty(const std::string& name, const std::string& value) override { if (pChannel) pChannel->setProperty(name, value); } void log(const Poco::Message & msg) override; void logExtended(const ExtendedLogMessage & msg) override; ~OwnFormattingChannel() override; private: Poco::AutoPtr pFormatter; Poco::AutoPtr pChannel; std::atomic priority; }; }