userver: userver/components/logging_configurator.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
logging_configurator.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/logging_configurator.hpp
4/// @brief @copybrief components::LoggingConfigurator
5
6#include <userver/components/component_fwd.hpp>
7#include <userver/components/raw_component_base.hpp>
8#include <userver/concurrent/async_event_source.hpp>
9#include <userver/utils/statistics/fwd.hpp>
10
11#include <dynamic_config/variables/USERVER_LOG_DYNAMIC_DEBUG.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace logging {
16struct DynamicDebugConfig;
17}
18
19namespace components {
20
21// clang-format off
22
23/// @ingroup userver_components
24///
25/// @brief Helper component to configure logging.
26///
27/// The functionality is not in Trace or Logger components because that
28/// introduces circular dependency between Logger and DynamicConfig.
29///
30/// ## LoggingConfigurator Dynamic config
31/// * @ref USERVER_LOG_DYNAMIC_DEBUG
32/// * @ref USERVER_NO_LOG_SPANS
33///
34/// ## Static options:
35/// Name | Description | Default value
36/// ---- | ----------- | -------------
37/// limited-logging-enable | set to true to make LOG_LIMITED drop repeated logs | -
38/// limited-logging-interval | utils::StringToDuration suitable duration string to group repeated logs into one message | -
39///
40/// ## Config example:
41///
42/// @snippet components/common_component_list_test.cpp Sample logging configurator component config
43
44// clang-format on
45class LoggingConfigurator final : public RawComponentBase {
46public:
47 /// @ingroup userver_component_names
48 /// @brief The default name of components::LoggingConfigurator component
49 static constexpr std::string_view kName = "logging-configurator";
50
51 LoggingConfigurator(const ComponentConfig& config, const ComponentContext& context);
52
53 ~LoggingConfigurator() override;
54
55 static yaml_config::Schema GetStaticConfigSchema();
56
57private:
58 void OnConfigUpdate(const dynamic_config::Snapshot& config);
59
60 utils::statistics::MetricsStoragePtr metrics_storage_;
61 // config_subscription_ must be the last field!
62 concurrent::AsyncEventSubscriberScope config_subscription_;
63};
64
65/// }@
66
67template <>
68inline constexpr bool kHasValidate<LoggingConfigurator> = true;
69
70} // namespace components
71
72USERVER_NAMESPACE_END