aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/log_iface.h
blob: 3acdcd69bc3f8baa812e1238426689d70ecd6486 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once

#include "events.h"
#include "event_local.h"

namespace NActors {
    namespace NLog { 
        using EComponent = int; 

        enum EPriority : ui16 { // migrate it to EPrio whenever possible 
            PRI_EMERG, 
            PRI_ALERT, 
            PRI_CRIT, 
            PRI_ERROR, 
            PRI_WARN, 
            PRI_NOTICE, 
            PRI_INFO, 
            PRI_DEBUG, 
            PRI_TRACE 
        }; 

        enum class EPrio : ui16 { 
            Emerg = 0, 
            Alert = 1, 
            Crit = 2, 
            Error = 3, 
            Warn = 4, 
            Notice = 5, 
            Info = 6, 
            Debug = 7, 
            Trace = 8, 
        }; 

        struct TLevel { 
            TLevel(ui32 raw) 
                : Raw(raw) 
            { 
            } 

            TLevel(EPrio prio) 
                : Raw((ui16(prio) + 1) << 8) 
            { 
            } 

            EPrio ToPrio() const noexcept { 
                const auto major = Raw >> 8; 

                return major > 0 ? EPrio(major - 1) : EPrio::Emerg; 
            } 

            bool IsUrgentAbortion() const noexcept { 
                return (Raw >> 8) == 0; 
            } 

            /* Generalized monotonic level value composed with major and minor 
            levels. Minor is used for verbosity within major, basic EPrio
            mapped to (EPrio + 1, 0) and Major = 0 is reserved as special
            space with meaning like EPrio::Emerg but with extened actions.
            Thus logger should map Major = 0 to EPrio::Emerg if it have no
            idea how to handle special emergency actions.
         */

            ui32 Raw = 0; // ((ui16(EPrio) + 1) << 8) | ui8(minor) 
        }; 

        enum class EEv { 
            Log = EventSpaceBegin(TEvents::ES_LOGGER), 
            LevelReq, 
            LevelResp, 
            Ignored, 
            End 
        }; 

        static_assert(int(EEv::End) < EventSpaceEnd(TEvents::ES_LOGGER), ""); 

        class TEvLog: public TEventLocal<TEvLog, int(EEv::Log)> { 
        public: 
            TEvLog(TInstant stamp, TLevel level, EComponent comp, const TString &line)
                : Stamp(stamp) 
                , Level(level) 
                , Component(comp) 
                , Line(line)
            {
            }

            TEvLog(TInstant stamp, TLevel level, EComponent comp, TString &&line)
                : Stamp(stamp)
                , Level(level)
                , Component(comp)
                , Line(std::move(line)) 
            { 
            } 

            TEvLog(EPriority prio, EComponent comp, TString line, TInstant time = TInstant::Now()) 
                : Stamp(time) 
                , Level(EPrio(prio)) 
                , Component(comp) 
                , Line(std::move(line)) 
            { 
            } 

            const TInstant Stamp = TInstant::Max(); 
            const TLevel Level; 
            const EComponent Component = 0; 
            TString Line; 
        }; 

    } 
}