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/dynamic_config/source.hpp>
10#include <userver/rcu/rcu.hpp>
11
12#include <dynamic_config/variables/USERVER_LOG_DYNAMIC_DEBUG.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace logging {
17struct DynamicDebugConfig;
18}
19
20namespace components {
21
22// clang-format off
23
24/// @ingroup userver_components
25///
26/// @brief Helper component to configure logging.
27///
28/// The functionality is not in Trace or Logger components because that
29/// introduces circular dependency between Logger and DynamicConfig.
30///
31/// ## LoggingConfigurator Dynamic config
32/// * @ref USERVER_LOG_DYNAMIC_DEBUG
33/// * @ref USERVER_NO_LOG_SPANS
34///
35/// ## Static options:
36/// Name | Description | Default value
37/// ---- | ----------- | -------------
38/// limited-logging-enable | set to true to make LOG_LIMITED drop repeated logs | -
39/// limited-logging-interval | utils::StringToDuration suitable duration string to group repeated logs into one message | -
40///
41/// ## Config example:
42///
43/// @snippet components/common_component_list_test.cpp Sample logging configurator component config
44
45// clang-format on
46class LoggingConfigurator final : public RawComponentBase {
47public:
48 /// @ingroup userver_component_names
49 /// @brief The default name of components::LoggingConfigurator component
50 static constexpr std::string_view kName = "logging-configurator";
51
52 LoggingConfigurator(const ComponentConfig& config, const ComponentContext& context);
53
54 ~LoggingConfigurator() override;
55
56 static yaml_config::Schema GetStaticConfigSchema();
57
58private:
59 void OnConfigUpdate(const dynamic_config::Snapshot& config);
60
61 concurrent::AsyncEventSubscriberScope config_subscription_;
62 rcu::Variable<logging::DynamicDebugConfig> dynamic_debug_;
63};
64
65/// }@
66
67template <>
68inline constexpr bool kHasValidate<LoggingConfigurator> = true;
69
70} // namespace components
71
72USERVER_NAMESPACE_END