aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/backend_creator.cpp
blob: ea430edb83a937bcb1777bebc98bf1ad8b7d3b53 (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
#include "backend_creator.h"
#include "stream.h"
#include "uninitialized_creator.h"
#include <util/system/yassert.h>
#include <util/stream/debug.h>
#include <util/stream/output.h>


THolder<TLogBackend> ILogBackendCreator::CreateLogBackend() const {
    try {
        return DoCreateLogBackend();
    } catch(...) {
        Cdbg << "Warning: " << CurrentExceptionMessage() << ". Use stderr instead." << Endl;
    }
    return MakeHolder<TStreamLogBackend>(&Cerr);
}

bool ILogBackendCreator::Init(const IInitContext& /*ctx*/) {
    return true;
}


NJson::TJsonValue ILogBackendCreator::AsJson() const {
    NJson::TJsonValue json;
    ToJson(json);
    return json;
}

THolder<ILogBackendCreator> ILogBackendCreator::Create(const IInitContext& ctx) {
    auto res = MakeHolder<TLogBackendCreatorUninitialized>();
    if(!res->Init(ctx)) {
        Cdbg << "Cannot init log backend creator";
        return nullptr;
    }
    return res;
}

TLogBackendCreatorBase::TLogBackendCreatorBase(const TString& type)
    : Type(type)
{}

void TLogBackendCreatorBase::ToJson(NJson::TJsonValue& value) const {
    value["LoggerType"] = Type;
    DoToJson(value);
}