diff options
author | iddqd <iddqd@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:45 +0300 |
commit | 07fce9c5f7771600d0b3d70e1f88fd8a7e164d85 (patch) | |
tree | e4aa4750fbb864d70f8c06cf03d2750e979ea3bf /library/cpp/logger/composite_ut.cpp | |
parent | af42068bf6cd93c976b80dd0388fa48cdf65da11 (diff) | |
download | ydb-07fce9c5f7771600d0b3d70e1f88fd8a7e164d85.tar.gz |
Restoring authorship annotation for <iddqd@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/composite_ut.cpp')
-rw-r--r-- | library/cpp/logger/composite_ut.cpp | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/library/cpp/logger/composite_ut.cpp b/library/cpp/logger/composite_ut.cpp index f330419271..a75122eb57 100644 --- a/library/cpp/logger/composite_ut.cpp +++ b/library/cpp/logger/composite_ut.cpp @@ -1,98 +1,98 @@ -#include "log.h" -#include <library/cpp/logger/init_context/config.h> -#include <library/cpp/logger/init_context/yconf.h> -#include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/yconf/patcher/unstrict_config.h> -#include <util/stream/file.h> -#include <util/system/fs.h> - -Y_UNIT_TEST_SUITE(TCompositeLogTest) -{ - TVector<TString> ReadLines(const TString & filename) { - TVector<TString> lines; - TIFStream fin(filename); - TString line; - while (fin.ReadLine(line)) { - lines.push_back(std::move(line)); - } - return lines; - } - - void Clear(const TString & filename) { - NFs::Remove(filename + "1"); - NFs::Remove(filename + "2"); - } - - void DoTestComposite(const ILogBackendCreator::IInitContext& ctx, const TString & filename) { - Clear(filename); - { - TLog log; - { - auto creator = ILogBackendCreator::Create(ctx); - log.ResetBackend(creator->CreateLogBackend()); - log.ReopenLog(); - } - log.Write(TLOG_ERR, "first\n"); - log.Write(TLOG_DEBUG, "second\n"); - } - auto data1 = ReadLines(filename + "1"); - auto data2 = ReadLines(filename + "2"); - UNIT_ASSERT_VALUES_EQUAL(data1.size(), 2); - UNIT_ASSERT(data1[0] == "first"); - UNIT_ASSERT(data1[1] == "second"); - - UNIT_ASSERT_VALUES_EQUAL(data2.size(), 1); - UNIT_ASSERT(data2[0] == "first"); - Clear(filename); - } - - Y_UNIT_TEST(TestCompositeConfig) { - TString s(R"( -{ - "LoggerType": "composite", - "SubLogger":[ - { - "LoggerType": "file", - "Path": "config_log_1" - }, { - "LoggerType": "config_log_2", - "LogLevel": "INFO" - } - ] -})"); - TStringInput si(s); - NConfig::TConfig cfg = NConfig::TConfig::FromJson(si); - //Прогоняем конфигурацию через серализацию и десериализацию - TLogBackendCreatorInitContextConfig ctx(cfg); - TString newCfg = ILogBackendCreator::Create(ctx)->AsJson().GetStringRobust(); - TStringInput si2(newCfg); - DoTestComposite(TLogBackendCreatorInitContextConfig(NConfig::TConfig::FromJson(si2)), "config_log_"); - - } - Y_UNIT_TEST(TestCompositeYConf) { - constexpr const char* CONFIG = R"( -<Logger> - LoggerType: composite - <SubLogger> - LoggerType: file - Path: yconf_log_1 - </SubLogger> - <SubLogger> - LoggerType: yconf_log_2 - LogLevel: INFO - </SubLogger> -</Logger> -)"; - TUnstrictConfig cfg; - if (!cfg.ParseMemory(CONFIG)) { - TString errors; - cfg.PrintErrors(errors); - UNIT_ASSERT_C(false, errors); - } - TLogBackendCreatorInitContextYConf ctx(*cfg.GetFirstChild("Logger")); - //Прогоняем конфигурацию через серализацию и десериализацию - TUnstrictConfig newCfg; - UNIT_ASSERT(newCfg.ParseJson(ILogBackendCreator::Create(ctx)->AsJson())); - DoTestComposite(TLogBackendCreatorInitContextYConf(*newCfg.GetRootSection()), "yconf_log_"); - } -}; +#include "log.h" +#include <library/cpp/logger/init_context/config.h> +#include <library/cpp/logger/init_context/yconf.h> +#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/yconf/patcher/unstrict_config.h> +#include <util/stream/file.h> +#include <util/system/fs.h> + +Y_UNIT_TEST_SUITE(TCompositeLogTest) +{ + TVector<TString> ReadLines(const TString & filename) { + TVector<TString> lines; + TIFStream fin(filename); + TString line; + while (fin.ReadLine(line)) { + lines.push_back(std::move(line)); + } + return lines; + } + + void Clear(const TString & filename) { + NFs::Remove(filename + "1"); + NFs::Remove(filename + "2"); + } + + void DoTestComposite(const ILogBackendCreator::IInitContext& ctx, const TString & filename) { + Clear(filename); + { + TLog log; + { + auto creator = ILogBackendCreator::Create(ctx); + log.ResetBackend(creator->CreateLogBackend()); + log.ReopenLog(); + } + log.Write(TLOG_ERR, "first\n"); + log.Write(TLOG_DEBUG, "second\n"); + } + auto data1 = ReadLines(filename + "1"); + auto data2 = ReadLines(filename + "2"); + UNIT_ASSERT_VALUES_EQUAL(data1.size(), 2); + UNIT_ASSERT(data1[0] == "first"); + UNIT_ASSERT(data1[1] == "second"); + + UNIT_ASSERT_VALUES_EQUAL(data2.size(), 1); + UNIT_ASSERT(data2[0] == "first"); + Clear(filename); + } + + Y_UNIT_TEST(TestCompositeConfig) { + TString s(R"( +{ + "LoggerType": "composite", + "SubLogger":[ + { + "LoggerType": "file", + "Path": "config_log_1" + }, { + "LoggerType": "config_log_2", + "LogLevel": "INFO" + } + ] +})"); + TStringInput si(s); + NConfig::TConfig cfg = NConfig::TConfig::FromJson(si); + //Прогоняем конфигурацию через серализацию и десериализацию + TLogBackendCreatorInitContextConfig ctx(cfg); + TString newCfg = ILogBackendCreator::Create(ctx)->AsJson().GetStringRobust(); + TStringInput si2(newCfg); + DoTestComposite(TLogBackendCreatorInitContextConfig(NConfig::TConfig::FromJson(si2)), "config_log_"); + + } + Y_UNIT_TEST(TestCompositeYConf) { + constexpr const char* CONFIG = R"( +<Logger> + LoggerType: composite + <SubLogger> + LoggerType: file + Path: yconf_log_1 + </SubLogger> + <SubLogger> + LoggerType: yconf_log_2 + LogLevel: INFO + </SubLogger> +</Logger> +)"; + TUnstrictConfig cfg; + if (!cfg.ParseMemory(CONFIG)) { + TString errors; + cfg.PrintErrors(errors); + UNIT_ASSERT_C(false, errors); + } + TLogBackendCreatorInitContextYConf ctx(*cfg.GetFirstChild("Logger")); + //Прогоняем конфигурацию через серализацию и десериализацию + TUnstrictConfig newCfg; + UNIT_ASSERT(newCfg.ParseJson(ILogBackendCreator::Create(ctx)->AsJson())); + DoTestComposite(TLogBackendCreatorInitContextYConf(*newCfg.GetRootSection()), "yconf_log_"); + } +}; |