aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/core/logging/fluent_log-inl.h
blob: 896829cda2106e9d8354112bf370dc056baeccd5 (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
#ifndef FLUENT_LOG_INL_H_
#error "Direct inclusion of this file is not allowed, include log.h"
// For the sake of sane code completion.
#include "log.h"
#include "fluent_log.h" // it makes CLion happy
#endif
#undef FLUENT_LOG_INL_H_

namespace NYT::NLogging {

////////////////////////////////////////////////////////////////////////////////

template <class TParent>
TOneShotFluentLogEventImpl<TParent>::TOneShotFluentLogEventImpl(
    TStatePtr state,
    const NLogging::TLogger& logger,
    NLogging::ELogLevel level)
    : TBase(state->GetConsumer())
    , State_(std::move(state))
    , Logger_(&logger)
    , Level_(level)
{
    for (const auto& [key, value] : logger.GetStructuredTags()) {
        (*this).Item(key).Value(value);
    }
}

template <class TParent>
NYTree::TFluentYsonBuilder::TAny<TOneShotFluentLogEventImpl<TParent>&&> TOneShotFluentLogEventImpl<TParent>::Item(TStringBuf key)
{
    this->Consumer->OnKeyedItem(key);
    return NYTree::TFluentYsonBuilder::TAny<TThis&&>(this->Consumer, std::move(*this));
}

template <class TParent>
TOneShotFluentLogEventImpl<TParent>::~TOneShotFluentLogEventImpl()
{
    if (State_ && *Logger_) {
        LogStructuredEvent(*Logger_, State_->GetValue(), Level_);
    }
}

template <class TParent>
template <class T, class... TExtraArgs>
typename TOneShotFluentLogEventImpl<TParent>::TThis& TOneShotFluentLogEventImpl<TParent>::OptionalItem(TStringBuf key, const T& optionalValue, TExtraArgs&&... extraArgs)
{
    using NYTree::Serialize;

    if (optionalValue) {
        this->Consumer->OnKeyedItem(key);
        Serialize(optionalValue, this->Consumer, std::forward<TExtraArgs>(extraArgs)...);
    }
    return *this;
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NLogging