1 | #pragma once |
---|---|
2 | #include <Poco/AutoPtr.h> |
3 | #include <Poco/Channel.h> |
4 | #include <Poco/FormattingChannel.h> |
5 | #include "ExtendedLogChannel.h" |
6 | #include "OwnPatternFormatter.h" |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | // Like Poco::FormattingChannel but supports the extended logging interface and log level filter |
12 | class OwnFormattingChannel : public Poco::Channel, public ExtendedLogChannel |
13 | { |
14 | public: |
15 | explicit OwnFormattingChannel( |
16 | Poco::AutoPtr<OwnPatternFormatter> pFormatter_ = nullptr, Poco::AutoPtr<Poco::Channel> pChannel_ = nullptr) |
17 | : pFormatter(std::move(pFormatter_)), pChannel(std::move(pChannel_)) |
18 | { |
19 | } |
20 | |
21 | void setChannel(Poco::AutoPtr<Poco::Channel> pChannel_) { pChannel = std::move(pChannel_); } |
22 | |
23 | void setLevel(Poco::Message::Priority priority_) { priority = priority_; } |
24 | |
25 | void open() override |
26 | { |
27 | if (pChannel) |
28 | pChannel->open(); |
29 | } |
30 | |
31 | void close() override |
32 | { |
33 | if (pChannel) |
34 | pChannel->close(); |
35 | } |
36 | |
37 | void log(const Poco::Message & msg) override; |
38 | void logExtended(const ExtendedLogMessage & msg) override; |
39 | |
40 | ~OwnFormattingChannel() override; |
41 | |
42 | private: |
43 | Poco::AutoPtr<OwnPatternFormatter> pFormatter; |
44 | Poco::AutoPtr<Poco::Channel> pChannel; |
45 | Poco::Message::Priority priority = Poco::Message::PRIO_TRACE; |
46 | }; |
47 | |
48 | } |
49 |