| 1 | #pragma once |
|---|---|
| 2 | #include <atomic> |
| 3 | #include <vector> |
| 4 | #include <Poco/AutoPtr.h> |
| 5 | #include <Poco/Channel.h> |
| 6 | #include "ExtendedLogChannel.h" |
| 7 | #include <Interpreters/TextLog.h> |
| 8 | |
| 9 | |
| 10 | namespace DB |
| 11 | { |
| 12 | /// Works as Poco::SplitterChannel, but performs additional work: |
| 13 | /// passes logs to Client via TCP interface |
| 14 | /// tries to use extended logging interface of child for more comprehensive logging |
| 15 | class OwnSplitChannel : public Poco::Channel |
| 16 | { |
| 17 | public: |
| 18 | /// Makes an extended message from msg and passes it to the client logs queue and child (if possible) |
| 19 | void log(const Poco::Message & msg) override; |
| 20 | /// Adds a child channel |
| 21 | void addChannel(Poco::AutoPtr<Poco::Channel> channel); |
| 22 | |
| 23 | void addTextLog(std::shared_ptr<DB::TextLog> log); |
| 24 | |
| 25 | private: |
| 26 | void logSplit(const Poco::Message & msg); |
| 27 | |
| 28 | using ChannelPtr = Poco::AutoPtr<Poco::Channel>; |
| 29 | /// Handler and its pointer casted to extended interface |
| 30 | using ExtendedChannelPtrPair = std::pair<ChannelPtr, ExtendedLogChannel *>; |
| 31 | std::vector<ExtendedChannelPtrPair> channels; |
| 32 | |
| 33 | std::mutex text_log_mutex; |
| 34 | |
| 35 | std::weak_ptr<DB::TextLog> text_log; |
| 36 | }; |
| 37 | |
| 38 | } |
| 39 |