aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/uninitialized_creator.cpp
blob: 26dd168529f7947d58c1e579d01fccad68c4187f (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
#include "uninitialized_creator.h"
#include "filter_creator.h"
#include "thread_creator.h"
#include "file_creator.h"
#include "null_creator.h"
#include <util/string/cast.h>

THolder<TLogBackend> TLogBackendCreatorUninitialized::DoCreateLogBackend() const {
    return Slave->CreateLogBackend();
}

void TLogBackendCreatorUninitialized::InitCustom(const TString& type, ELogPriority priority, bool threaded) {
    if (!type) {
        Slave = MakeHolder<TNullLogBackendCreator>();
    } else if (TFactory::Has(type)) {
        Slave = TFactory::MakeHolder(type);
    } else {
        Slave = MakeHolder<TFileLogBackendCreator>(type);
    }

    if (threaded) {
        Slave = MakeHolder<TOwningThreadedLogBackendCreator>(std::move(Slave));
    }

    if (priority != LOG_MAX_PRIORITY) {
        Slave = MakeHolder<TFilteredBackendCreator>(std::move(Slave), priority);
    }
}

bool TLogBackendCreatorUninitialized::Init(const IInitContext& ctx) {
    auto type = ctx.GetOrElse("LoggerType", TString());
    bool threaded = ctx.GetOrElse("Threaded", false);
    ELogPriority priority = LOG_MAX_PRIORITY;
    TString prStr;
    if (ctx.GetValue("LogLevel", prStr)) {
        if (!TryFromString(prStr, priority)) {
            priority = (ELogPriority)FromString<int>(prStr);
        }
    }
    InitCustom(type, priority, threaded);
    return Slave->Init(ctx);
}


void TLogBackendCreatorUninitialized::ToJson(NJson::TJsonValue& value) const {
    Y_VERIFY(Slave, "Serialization off uninitialized LogBackendCreator");
    Slave->ToJson(value);
}

ILogBackendCreator::TFactory::TRegistrator<TLogBackendCreatorUninitialized> TLogBackendCreatorUninitialized::Registrar("");