aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/thread.h
blob: b936b0ddcbdb705585733f32469c289b68c80879 (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
#pragma once

#include "backend.h"

#include <util/generic/ptr.h>

#include <functional>

class TThreadedLogBackend: public TLogBackend {
public:
    TThreadedLogBackend(TLogBackend* slave);
    TThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback = {});
    ~TThreadedLogBackend() override;

    void WriteData(const TLogRecord& rec) override;
    void ReopenLog() override;
    void ReopenLogNoFlush() override;
    size_t QueueSize() const override;

    // Write an emergency message when the memory allocator is corrupted.
    // The TThreadedLogBackend object can't be used after this method is called.
    void WriteEmergencyData(const TLogRecord& rec);
 
private:
    class TImpl;
    THolder<TImpl> Impl_;
};

class TOwningThreadedLogBackend: private THolder<TLogBackend>, public TThreadedLogBackend {
public:
    TOwningThreadedLogBackend(TLogBackend* slave);
    TOwningThreadedLogBackend(TLogBackend* slave, size_t queuelen, std::function<void()> queueOverflowCallback = {});
    ~TOwningThreadedLogBackend() override;
};