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