aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Loggers/OwnSplitChannel.h
blob: a6ee8af5b1407d332d32fb273aed49cf0fe2a69f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <atomic>
#include <vector>
#include <map>
#include <mutex>
#include <Poco/AutoPtr.h>
#include <Poco/Channel.h>
#include "ExtendedLogChannel.h"

#ifndef WITHOUT_TEXT_LOG
namespace DB
{
    template <typename> class SystemLogQueue;
    struct TextLogElement;
    using TextLogQueue = SystemLogQueue<TextLogElement>;
}
#endif

namespace DB
{
/// Works as Poco::SplitterChannel, but performs additional work:
///  passes logs to Client via TCP interface
///  tries to use extended logging interface of child for more comprehensive logging
class OwnSplitChannel : public Poco::Channel
{
public:
    /// Makes an extended message from msg and passes it to the client logs queue and child (if possible)
    void log(const Poco::Message & msg) override;

    void setChannelProperty(const std::string& channel_name, const std::string& name, const std::string& value);

    /// Adds a child channel
    void addChannel(Poco::AutoPtr<Poco::Channel> channel, const std::string & name);

#ifndef WITHOUT_TEXT_LOG
    void addTextLog(std::shared_ptr<DB::TextLogQueue> log_queue, int max_priority);
#endif

    void setLevel(const std::string & name, int level);

private:
    void logSplit(const Poco::Message & msg);
    void tryLogSplit(const Poco::Message & msg);

    using ChannelPtr = Poco::AutoPtr<Poco::Channel>;
    /// Handler and its pointer casted to extended interface
    using ExtendedChannelPtrPair = std::pair<ChannelPtr, ExtendedLogChannel *>;
    std::map<std::string, ExtendedChannelPtrPair> channels;

#ifndef WITHOUT_TEXT_LOG
    std::weak_ptr<DB::TextLogQueue> text_log;
    std::atomic<int> text_log_max_priority = -1;
#endif
};

}