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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#include "yt_log.h"
#include "logger.h"
#include <util/generic/guid.h>
#include <util/system/mutex.h>
namespace NYT {
using namespace NLogging;
////////////////////////////////////////////////////////////////////////////////
namespace {
class TLogManager
: public ILogManager
{
public:
static constexpr TStringBuf CategoryName = "Wrapper";
public:
void RegisterStaticAnchor(
TLoggingAnchor* anchor,
::TSourceLocation sourceLocation,
TStringBuf anchorMessage) override
{
if (anchor->Registered.exchange(true)) {
return;
}
anchor->Enabled.store(true);
auto guard = Guard(Mutex_);
anchor->SourceLocation = sourceLocation;
anchor->AnchorMessage = anchorMessage;
}
void UpdateAnchor(TLoggingAnchor* /*position*/) override
{ }
void Enqueue(TLogEvent&& event) override
{
auto message = TString(event.MessageRef.ToStringBuf());
LogMessage(
ToImplLevel(event.Level),
::TSourceLocation(event.SourceFile, event.SourceLine),
"%.*s",
event.MessageRef.size(),
event.MessageRef.begin());
}
const TLoggingCategory* GetCategory(TStringBuf categoryName) override
{
Y_VERIFY(categoryName == CategoryName);
return &Category_;
}
void UpdateCategory(TLoggingCategory* /*category*/) override
{
Y_FAIL();
}
bool GetAbortOnAlert() const override
{
return false;
}
private:
static ILogger::ELevel ToImplLevel(ELogLevel level)
{
switch (level) {
case ELogLevel::Minimum:
case ELogLevel::Trace:
case ELogLevel::Debug:
return ILogger::ELevel::DEBUG;
case ELogLevel::Info:
return ILogger::ELevel::INFO;
case ELogLevel::Warning:
case ELogLevel::Error:
return ILogger::ELevel::ERROR;
case ELogLevel::Alert:
case ELogLevel::Fatal:
case ELogLevel::Maximum:
return ILogger::ELevel::FATAL;
}
}
static void LogMessage(ILogger::ELevel level, const ::TSourceLocation& sourceLocation, const char* format, ...)
{
va_list args;
va_start(args, format);
GetLogger()->Log(level, sourceLocation, format, args);
va_end(args);
}
private:
::TMutex Mutex_;
std::atomic<int> ActualVersion_{1};
const TLoggingCategory Category_{
.Name{CategoryName},
.MinPlainTextLevel{ELogLevel::Minimum},
.CurrentVersion{1},
.ActualVersion = &ActualVersion_,
};
};
TLogManager LogManager;
} // namespace
////////////////////////////////////////////////////////////////////////////////
TLogger Logger(&LogManager, TLogManager::CategoryName);
////////////////////////////////////////////////////////////////////////////////
void FormatValue(TStringBuilderBase* builder, const TGUID& value, TStringBuf /*format*/)
{
builder->AppendString(GetGuidAsString(value));
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|