aboutsummaryrefslogtreecommitdiffstats
path: root/kikimr/persqueue/sdk/deprecated/cpp/v2/impl/logger.cpp
blob: 98d44d14c5fb2b4bc7ee5015c99838cfdeedd6ff (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
#include <kikimr/persqueue/sdk/deprecated/cpp/v2/logger.h>
#include <util/datetime/base.h>
#include <util/string/builder.h>
#include <util/stream/str.h>

namespace NPersQueue {

static const TStringBuf LogLevelsStrings[] = {
    "EMERG",
    "ALERT",
    "CRITICAL_INFO",
    "ERROR",
    "WARNING",
    "NOTICE",
    "INFO",
    "DEBUG",
};

TStringBuf TCerrLogger::LevelToString(int level) {
    return LogLevelsStrings[ClampVal(level, 0, int(Y_ARRAY_SIZE(LogLevelsStrings) - 1))];
}

void TCerrLogger::Log(const TString& msg, const TString& sourceId, const TString& sessionId, int level) {
    if (level > Level) {
        return;
    }

    TStringBuilder message;
    message << TInstant::Now() << " :" << LevelToString(level) << ":";
    if (sourceId) {
        message << " SourceId [" << sourceId << "]:";
    }
    if (sessionId) {
        message << " SessionId [" << sessionId << "]:";
    }
    message << " " << msg << "\n";
    Cerr << message;
}

}