#include <userver/logging/component.hpp>
Logging component
Allows to configure the default logger and/or additional loggers for your needs.
Options inherited from components::RawComponentBase :
default logger is the one used for LOG_*.
You can specify where logs are written in the file_path option:
file_path: '@stdout' to write your logs to standard output stream;file_path: '@stderr' to write your logs to standard error stream;file_path: '@null' to suppress sending of logs;file_path: /absolute/path/to/log/file.log to write your logs to file. Use USR1 signal or server::handlers::OnLogRotate to reopen files after log rotation;file_path: 'unix:/absolute/path/to/logs.sock' to write your logs to unix socket. Socket must be created before the service starts and closed by listener after service is shut down.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:
format: tskv for traditional optimized userver-flavoured TSKV representation. See utils::encoding::TskvParser for the exact format specification;format: ltsv for the same format, with : instead of = for key-value separator;format: raw for TSKV logs with timestamp and other default tags stripped, useful for custom loggers;format: json for JSON logs. logging::JsonString can be used with this format for rich hierarchical log tags;format: json_yadeploy for JSON logs with a slightly different structure.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 83 of file component.hpp.
Inheritance diagram for components::Logging: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. | |
| 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 | 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, and server::handlers::Restart.
Definition at line 52 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 |
nullptr if not registered | 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 urabbitmq::ConsumerComponentBase, components::ComponentBase, and components::Server.
Definition at line 58 of file raw_component_base.hpp.
|
inlinevirtualinherited |
Reimplemented in urabbitmq::ConsumerComponentBase, components::ComponentBase, components::Server, and server::handlers::Ping.
Definition at line 56 of file raw_component_base.hpp.
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase.
Definition at line 54 of file raw_component_base.hpp.
| void components::Logging::SetLogger | ( | const std::string & | name, |
| logging::LoggerPtr | logger | ||
| ) |
Sets a logger.
| name | Name of the logger |
| logger | Logger to set |