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/impl/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/// ## 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 impl::ComponentBase {
45 public:
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,
51 const ComponentContext& context);
52
53 ~LoggingConfigurator() override;
54
55 static yaml_config::Schema GetStaticConfigSchema();
56
57 private:
58 void OnConfigUpdate(const dynamic_config::Snapshot& config);
59
60 concurrent::AsyncEventSubscriberScope config_subscription_;
61 rcu::Variable<logging::DynamicDebugConfig> dynamic_debug_;
62};
63
64/// }@
65
66template <>
67inline constexpr bool kHasValidate<LoggingConfigurator> = true;
68
69} // namespace components
70
71USERVER_NAMESPACE_END