#include <userver/logging/component.hpp>
Logging component
Allows to configure the default logger and/or additional loggers for your needs.
Name | Description | Default value |
---|---|---|
file_path | path to the log file | - |
level | log verbosity | info |
format | log output format, one of tskv , ltsv , json , json_yadeploy | tskv |
flush_level | messages of this and higher levels get flushed to the file immediately | warning |
message_queue_size | the size of internal message queue, must be a power of 2 | 65536 |
overflow_behavior | message handling policy while the queue is full: discard drops messages, block waits until message gets into the queue | discard |
testsuite-capture | if exists, setups additional TCP log sink for testing purposes | {} |
fs-task-processor | task processor for disk I/O operations for this logger | fs-task-processor of the loggers component |
You can specify logger output, in file_path
option:
@stdout
to write your logs to standard output stream;@stderr
to write your logs to standard error stream;@null
to suppress sending of logs;file_name%
to write your logs in file. Use USR1 signal or OnLogRotate
handler to reopen files after log rotation;unix:socket_name%
to write your logs to unix socket. Socket must be created before the service starts and closed by listener after service is shut down.Name | Description | Default value |
---|---|---|
host | testsuite hostname, e.g. localhost | - |
port | testsuite port | - |
default
section configures the default logger for LOG_*.
Definition at line 75 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. | |
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 49 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 55 of file raw_component_base.hpp.
|
inlinevirtualinherited |
Reimplemented in urabbitmq::ConsumerComponentBase, components::ComponentBase, components::Server, and server::handlers::Ping.
Definition at line 53 of file raw_component_base.hpp.
|
inlinevirtualinherited |
Reimplemented in components::ComponentBase.
Definition at line 51 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 |