aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/composite_creator.cpp
blob: 206426576694527fcaf84e0e5b40068b1dd984aa (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
#include "composite_creator.h"
#include "composite.h"
#include "uninitialized_creator.h"

THolder<TLogBackend> TCompositeBackendCreator::DoCreateLogBackend() const {
    auto res = MakeHolder<TCompositeLogBackend>();
    for (const auto& child : Children) {
        res->AddLogBackend(child->CreateLogBackend());
    }
    return std::move(res);
}


TCompositeBackendCreator::TCompositeBackendCreator()
    : TLogBackendCreatorBase("composite")
{}

bool TCompositeBackendCreator::Init(const IInitContext& ctx) {
    for (const auto& child : ctx.GetChildren("SubLogger")) {
        Children.emplace_back(MakeHolder<TLogBackendCreatorUninitialized>());
        if (!Children.back()->Init(*child)) {
            return false;
        }
    }
    return true;
}

ILogBackendCreator::TFactory::TRegistrator<TCompositeBackendCreator> TCompositeBackendCreator::Registrar("composite");

void TCompositeBackendCreator::DoToJson(NJson::TJsonValue& value) const {
    for (const auto& child: Children) {
        child->ToJson(value["SubLogger"].AppendValue(NJson::JSON_MAP));
    }
}