aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/log_buffer.h
blob: 60bc09cc8551129faaf8f08956bdb731e571a111 (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
#pragma once

#include "log_metrics.h"
#include "log_iface.h"
#include "log_settings.h"

#include <util/generic/intrlist.h>

namespace NActors {
class TLogBuffer {
    static const size_t LOG_STRUCTURE_BYTES = sizeof(NLog::TEvLog);
    static const ui16 LOG_PRIORITIES_NUMBER = 9;
    
    ILoggerMetrics &Metrics;
    const NLog::TSettings &Settings;

    TIntrusiveListWithAutoDelete<NLog::TEvLog, TDelete, NLog::TEvLogBufferMainListTag> Logs;
    TIntrusiveList<NLog::TEvLog, NLog::TEvLogBufferLevelListTag> PrioLogsList[LOG_PRIORITIES_NUMBER];

    ui64 SizeBytes = 0;    
    ui64 IgnoredCount = 0;
    ui16 IgnoredHighestPrio = LOG_PRIORITIES_NUMBER - 1;

    size_t GetLogCostInBytes(NLog::TEvLog *log) const;
    void HandleIgnoredLog(NLog::TEvLog *log);
    bool CheckSize(NLog::TEvLog *log);
    static inline ui16 GetPrioIndex(NLog::EPrio);
    inline TIntrusiveList<NLog::TEvLog, NLog::TEvLogBufferLevelListTag> &GetPrioLogs(NLog::EPrio);

    public:
    TLogBuffer(ILoggerMetrics &metrics, const NLog::TSettings &Settings);
    void AddLog(NLog::TEvLog *log);
    NLog::TEvLog *Pop();
    bool IsEmpty() const;
    bool CheckLogIgnoring() const;
    ui64 GetIgnoredCount();
    NLog::EPrio GetIgnoredHighestPrio();
    void ClearIgnoredCount();
};
}