#include <userver/logging/component.hpp>
Logging component
Allows to configure the default logger and/or additional loggers for your needs.
| Name | Description | Default value |
|---|---|---|
| span-log-level | Minimum log level for spans; defaults to the default logger's level. | – |
| fs-task-processor | Task processor for disk I/O operations. | engine::current_task::GetBlockingTaskProcessor() |
| loggers.* | Logger options. | – |
| loggers.*.file_path | Path to the log file. | – |
| loggers.*.level | Log verbosity. | info |
| loggers.*.format | Log output format. Possible values: tskv, ltsv, raw, json, json_yadeploy. | tskv |
| loggers.*.flush_level | Messages of this and higher levels get flushed to the file immediately. | warning |
| loggers.*.message_queue_size | The size of internal message queue, must be a power of 2. | 65536 |
| loggers.*.flush_queue_size | Number of queued messages that wakes the log consumer; values above half of message_queue_size are capped at half of message_queue_size. | 128 |
| loggers.*.overflow_behavior | Message handling policy while the queue is full: discard drops messages, block waits until message gets into the queue. Possible values: discard, block. | discard |
| loggers.*.truncate-on-start | If true, the log file is truncated on service start. | false |
| loggers.*.fs-task-processor | Task processor for disk I/O operations for this logger. | top-level fs-task-processor option |
| loggers.*.testsuite-capture | If exists, setups additional TCP log sink for testing purposes. | {} |
| loggers.*.testsuite-capture.host | Testsuite hostname, e.g. localhost. | – |
| loggers.*.testsuite-capture.port | Testsuite port. | – |
Options inherited from components::RawComponentBase :
| Name | Description | Default value |
|---|---|---|
| load-enabled | Set to false to disable loading of the component. | true |
default logger is the one used for LOG_*.
You can specify where logs are written in the file_path option:
For sending logs directly to an otlp (opentelemetry) sink, see opentelemetry.
Customization of log sinks beyond the ones listed above is not supported at the moment.
You can specify in what format logs are written in the format option:
When sending logs using opentelemetry, logs are written to otlp protobuf messages.
Customization of log formats beyond the ones listed above is not supported at the moment.
Writing logs to stderr:
Advanced configuration showing options for access logs and a custom opentracing logger:
Definition at line 94 of file component.hpp.
Public Member Functions | |
| Logging (const ComponentConfig &, const ComponentContext &) | |
| The component constructor. | |
| logging::LoggerPtr | GetLogger (const std::string &name) |
| Returns a logger by its name. | |
| logging::TextLoggerPtr | GetTextLogger (const std::string &name) |
| Returns a text logger by its name. | |
| void | SetLogger (const std::string &name, logging::LoggerPtr logger) |
| Sets a logger. | |
| void | SetTelemetrySettings (utils::DefaultDict< logging::TelemetrySettings > settings, utils::DefaultDict< logging::TelemetrySettings > restrictions) |
| void | RestoreTelemetrySettings () |
| logging::LoggerPtr | GetLoggerOptional (const std::string &name) |
| Returns a logger by its name. | |
| void | StartSocketLoggingDebug (const std::optional< logging::Level > &log_level) |
| void | StopSocketLoggingDebug (const std::optional< logging::Level > &log_level) |
| void | OnLogRotate () |
| Reopens log files after rotation. | |
| void | TryReopenFiles () |
| void | WriteStatistics (utils::statistics::Writer &writer) const |
| virtual ComponentHealth | GetComponentHealth () const |
| virtual void | OnLoadingCancelled () |
| virtual void | OnAllComponentsLoaded () |
| virtual void | OnGracefulShutdown (engine::Deadline) |
| virtual void | OnAllComponentsAreStopping () |
Static Public Member Functions | |
| static yaml_config::Schema | GetStaticConfigSchema () |
Static Public Attributes | |
| static constexpr std::string_view | kName = "logging" |
| The default name of components::Logging component. | |
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase, components::Redis, and server::handlers::Restart.
Definition at line 57 of file raw_component_base.hpp.
| logging::LoggerPtr components::Logging::GetLogger | ( | const std::string & | name | ) |
Returns a logger by its name.
| name | Name of the logger |
| std::runtime_error | if logger with this name is not registered |
| logging::LoggerPtr components::Logging::GetLoggerOptional | ( | const std::string & | name | ) |
Returns a logger by its name.
| name | Name of the logger |
| logging::TextLoggerPtr components::Logging::GetTextLogger | ( | const std::string & | name | ) |
Returns a text logger by its name.
| name | Name of the logger |
| std::runtime_error | if logger with this name is not registered |
| std::runtime_error | if logger is not a text logger |
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase, components::Server, and urabbitmq::ConsumerComponentBase.
Definition at line 65 of file raw_component_base.hpp.
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase, components::Server, server::handlers::Ping, and urabbitmq::ConsumerComponentBase.
Definition at line 61 of file raw_component_base.hpp.
|
virtualinherited |
Reimplemented in components::ComponentBase, and components::Server.
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase.
Definition at line 59 of file raw_component_base.hpp.
| void components::Logging::RestoreTelemetrySettings | ( | ) |
Restores levels and sampling rates captured at logger registration and clears the policies.
| void components::Logging::SetLogger | ( | const std::string & | name, |
| logging::LoggerPtr | logger ) |
Sets a logger.
| name | Name of the logger |
| logger | Logger to set |
Captures the initial level and sampling rate and applies the current telemetry policy.
| std::runtime_error | if logger is null, the name is already registered, or it is default. |
| void components::Logging::SetTelemetrySettings | ( | utils::DefaultDict< logging::TelemetrySettings > | settings, |
| utils::DefaultDict< logging::TelemetrySettings > | restrictions ) |
Replaces ordinary and external logger policies, resolving each name through utils::DefaultDict independently. Applies the stricter settings to existing and subsequently registered loggers. Log levels never fall below their initial values.
| std::runtime_error | for invalid sampling rates, without changing the policies. |