aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/init_context
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/logger/init_context
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/logger/init_context')
-rw-r--r--library/cpp/logger/init_context/README.md5
-rw-r--r--library/cpp/logger/init_context/config.cpp26
-rw-r--r--library/cpp/logger/init_context/config.h14
-rw-r--r--library/cpp/logger/init_context/ya.make20
-rw-r--r--library/cpp/logger/init_context/yconf.cpp18
-rw-r--r--library/cpp/logger/init_context/yconf.h13
6 files changed, 96 insertions, 0 deletions
diff --git a/library/cpp/logger/init_context/README.md b/library/cpp/logger/init_context/README.md
new file mode 100644
index 00000000000..93564e48906
--- /dev/null
+++ b/library/cpp/logger/init_context/README.md
@@ -0,0 +1,5 @@
+Эта библиотека содержит две раплизации InitContext для TLogBackendCreator.
+
+TLogBackendCreatorInitContextYConf работает с YandexConfig (library/cpp/yconf).
+
+TLogBackendCreatorInitContextConfig работает с NConfig::TConfig (library/cpp/config).
diff --git a/library/cpp/logger/init_context/config.cpp b/library/cpp/logger/init_context/config.cpp
new file mode 100644
index 00000000000..30efa13333d
--- /dev/null
+++ b/library/cpp/logger/init_context/config.cpp
@@ -0,0 +1,26 @@
+#include "config.h"
+
+TLogBackendCreatorInitContextConfig::TLogBackendCreatorInitContextConfig(const NConfig::TConfig& config)
+ : Config(config)
+{}
+
+bool TLogBackendCreatorInitContextConfig::GetValue(TStringBuf name, TString& var) const {
+ if (Config.Has(name)) {
+ var = Config[name].Get<TString>();
+ return true;
+ }
+ return false;
+}
+
+TVector<THolder<ILogBackendCreator::IInitContext>> TLogBackendCreatorInitContextConfig::GetChildren(TStringBuf name) const {
+ TVector<THolder<IInitContext>> result;
+ const NConfig::TConfig& child = Config[name];
+ if (child.IsA<NConfig::TArray>()) {
+ for (const auto& i: child.Get<NConfig::TArray>()) {
+ result.emplace_back(MakeHolder<TLogBackendCreatorInitContextConfig>(i));
+ }
+ } else if (!child.IsNull()) {
+ result.emplace_back(MakeHolder<TLogBackendCreatorInitContextConfig>(child));
+ }
+ return result;
+}
diff --git a/library/cpp/logger/init_context/config.h b/library/cpp/logger/init_context/config.h
new file mode 100644
index 00000000000..8227d13176c
--- /dev/null
+++ b/library/cpp/logger/init_context/config.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <library/cpp/logger/backend_creator.h>
+#include <library/cpp/config/config.h>
+
+class TLogBackendCreatorInitContextConfig : public ILogBackendCreator::IInitContext {
+public:
+ TLogBackendCreatorInitContextConfig(const NConfig::TConfig& config);
+ virtual bool GetValue(TStringBuf name, TString& var) const override;
+ virtual TVector<THolder<IInitContext>> GetChildren(TStringBuf name) const override;
+
+private:
+ const NConfig::TConfig& Config;
+};
diff --git a/library/cpp/logger/init_context/ya.make b/library/cpp/logger/init_context/ya.make
new file mode 100644
index 00000000000..9572a34c60f
--- /dev/null
+++ b/library/cpp/logger/init_context/ya.make
@@ -0,0 +1,20 @@
+OWNER(
+ pg
+ mvel
+ g:util
+ g:base
+)
+
+LIBRARY()
+
+PEERDIR(
+ library/cpp/logger
+ library/cpp/config
+ library/cpp/yconf
+)
+SRCS(
+ config.cpp
+ yconf.cpp
+)
+
+END()
diff --git a/library/cpp/logger/init_context/yconf.cpp b/library/cpp/logger/init_context/yconf.cpp
new file mode 100644
index 00000000000..c7da1d607cb
--- /dev/null
+++ b/library/cpp/logger/init_context/yconf.cpp
@@ -0,0 +1,18 @@
+#include "yconf.h"
+
+TLogBackendCreatorInitContextYConf::TLogBackendCreatorInitContextYConf(const TYandexConfig::Section& section)
+ : Section(section)
+{}
+
+bool TLogBackendCreatorInitContextYConf::GetValue(TStringBuf name, TString& var) const {
+ return Section.GetDirectives().GetValue(name, var);
+}
+
+TVector<THolder<ILogBackendCreator::IInitContext>> TLogBackendCreatorInitContextYConf::GetChildren(TStringBuf name) const {
+ TVector<THolder<IInitContext>> result;
+ auto children = Section.GetAllChildren();
+ for (auto range = children.equal_range(TCiString(name)); range.first != range.second; ++range.first) {
+ result.emplace_back(MakeHolder<TLogBackendCreatorInitContextYConf>(*range.first->second));
+ }
+ return result;
+}
diff --git a/library/cpp/logger/init_context/yconf.h b/library/cpp/logger/init_context/yconf.h
new file mode 100644
index 00000000000..b1867d271d9
--- /dev/null
+++ b/library/cpp/logger/init_context/yconf.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <library/cpp/logger/backend_creator.h>
+#include <library/cpp/yconf/conf.h>
+
+class TLogBackendCreatorInitContextYConf: public ILogBackendCreator::IInitContext {
+public:
+ TLogBackendCreatorInitContextYConf(const TYandexConfig::Section& section);
+ virtual bool GetValue(TStringBuf name, TString& var) const override;
+ virtual TVector<THolder<IInitContext>> GetChildren(TStringBuf name) const override;
+private:
+ const TYandexConfig::Section& Section;
+};