userver: userver/logging/log.hpp File Reference
Loading...
Searching...
No Matches
log.hpp File Reference

Detailed Description

Logging helpers, see Logging and Tracing for more info.

Definition in file log.hpp.

Go to the source code of this file.

+ This graph shows which files directly or indirectly include this file:

Classes

class  logging::DefaultLoggerGuard
 Atomically replaces the default logger. More...
 
class  logging::DefaultLoggerLevelScope
 Allows to override global log level for the whole service within a scope. Primarily for use in tests. More...
 

Namespaces

namespace  logging
 Logging macro and utilities.
 

Macros

#define LOG_TO(logger, lvl, ...)
 If lvl matches the verbosity then builds a stream and evaluates a message for the specified logger.
 
#define LOG(lvl, ...)
 If lvl matches the verbosity then builds a stream and evaluates a message for the default logger.
 
#define LOG_TRACE(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kTrace.
 
#define LOG_DEBUG(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kDebug.
 
#define LOG_INFO(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kInfo.
 
#define LOG_WARNING(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kWarning.
 
#define LOG_ERROR(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kError.
 
#define LOG_CRITICAL(...)
 Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kCritical.
 
#define LOG_TRACE_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kTrace.
 
#define LOG_DEBUG_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kDebug.
 
#define LOG_INFO_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kInfo.
 
#define LOG_WARNING_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kWarning.
 
#define LOG_ERROR_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kError.
 
#define LOG_CRITICAL_TO(logger, ...)
 Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kCritical.
 
#define LOG_LIMITED_TO(logger, lvl, ...)
 If lvl matches the verbosity then builds a stream and evaluates a message for the logger. Ignores log messages that occur too often.
 
#define LOG_LIMITED(lvl, ...)
 If lvl matches the verbosity then builds a stream and evaluates a message for the default logger. Ignores log messages that occur too often.
 
#define LOG_LIMITED_TRACE(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kTrace.
 
#define LOG_LIMITED_DEBUG(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kDebug.
 
#define LOG_LIMITED_INFO(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kInfo.
 
#define LOG_LIMITED_WARNING(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kWarning.
 
#define LOG_LIMITED_ERROR(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kError.
 
#define LOG_LIMITED_CRITICAL(...)
 Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kCritical.
 
#define LOG_LIMITED_TRACE_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kTrace.
 
#define LOG_LIMITED_DEBUG_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kDebug.
 
#define LOG_LIMITED_INFO_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kInfo.
 
#define LOG_LIMITED_WARNING_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kWarning.
 
#define LOG_LIMITED_ERROR_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kError.
 
#define LOG_LIMITED_CRITICAL_TO(logger, ...)
 Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kCritical.
 

Functions

LoggerRef logging::GetDefaultLogger () noexcept
 Returns the default logger previously set by SetDefaultLogger. If the logger was not set - returns a logger that does no logging.
 
void logging::SetDefaultLoggerLevel (Level)
 Sets new log level for the default logger.
 
Level logging::GetDefaultLoggerLevel () noexcept
 Returns log level for the default logger.
 
bool logging::ShouldLog (Level level) noexcept
 
void logging::SetLoggerLevel (LoggerRef, Level)
 Sets new log level for a logger.
 
bool logging::LoggerShouldLog (LoggerRef logger, Level level) noexcept
 
bool logging::LoggerShouldLog (const LoggerPtr &logger, Level level) noexcept
 
Level logging::GetLoggerLevel (LoggerRef logger) noexcept
 
void logging::LogFlush ()
 Forces flush of default logger message queue.
 
void logging::LogFlush (LoggerRef logger)
 Forces flush of logger message queue.
 

Macro Definition Documentation

◆ LOG

#define LOG ( lvl,
... )

If lvl matches the verbosity then builds a stream and evaluates a message for the default logger.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 259 of file log.hpp.

◆ LOG_CRITICAL

#define LOG_CRITICAL ( ...)
Value:
LOG(USERVER_NAMESPACE::logging::Level::kCritical, __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kCritical.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 311 of file log.hpp.

◆ LOG_CRITICAL_TO

#define LOG_CRITICAL_TO ( logger,
... )
Value:
LOG_TO(logger, USERVER_NAMESPACE::logging::Level::kCritical, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kCritical.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 361 of file log.hpp.

◆ LOG_DEBUG

#define LOG_DEBUG ( ...)
Value:
USERVER_IMPL_LOGS_DEBUG_ERASER(LOG_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kDebug.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Examples
postgresql/functional_tests/basic_chaos/postgres_service.cpp, samples/config_service/main.cpp, samples/grpc_service/src/greeter_client.cpp, samples/ydb_service/components/federated_topic_reader.cpp, and samples/ydb_service/components/topic_reader.cpp.

Definition at line 276 of file log.hpp.

◆ LOG_DEBUG_TO

#define LOG_DEBUG_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_DEBUG_ERASER(LOG_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kDebug.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 329 of file log.hpp.

◆ LOG_ERROR

#define LOG_ERROR ( ...)
Value:
USERVER_IMPL_LOGS_ERROR_ERASER(LOG_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kError.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Examples
samples/config_service/main.cpp, samples/grpc_middleware_service/src/middlewares/server/auth.cpp, samples/grpc_middleware_service/src/middlewares/server/meta_filter.cpp, samples/ydb_service/components/federated_topic_reader.cpp, and samples/ydb_service/components/topic_reader.cpp.

Definition at line 302 of file log.hpp.

◆ LOG_ERROR_TO

#define LOG_ERROR_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_ERROR_ERASER(LOG_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kError.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 353 of file log.hpp.

◆ LOG_INFO

#define LOG_INFO ( ...)
Value:
USERVER_IMPL_LOGS_INFO_ERASER(LOG_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kInfo.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Examples
samples/tcp_full_duplex_service/main.cpp, samples/testsuite-support/src/logcapture.cpp, samples/ydb_service/components/federated_topic_reader.cpp, and samples/ydb_service/components/topic_reader.cpp.

Definition at line 285 of file log.hpp.

◆ LOG_INFO_TO

#define LOG_INFO_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_INFO_ERASER(LOG_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kInfo.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 337 of file log.hpp.

◆ LOG_LIMITED

#define LOG_LIMITED ( lvl,
... )
Value:
LOG_LIMITED_TO(USERVER_NAMESPACE::logging::GetDefaultLogger(), (lvl), __VA_ARGS__)

If lvl matches the verbosity then builds a stream and evaluates a message for the default logger. Ignores log messages that occur too often.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 385 of file log.hpp.

◆ LOG_LIMITED_CRITICAL

#define LOG_LIMITED_CRITICAL ( ...)
Value:
LOG_LIMITED(USERVER_NAMESPACE::logging::Level::kCritical, __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kCritical.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 444 of file log.hpp.

◆ LOG_LIMITED_CRITICAL_TO

#define LOG_LIMITED_CRITICAL_TO ( logger,
... )
Value:
LOG_LIMITED_TO(logger, USERVER_NAMESPACE::logging::Level::kCritical, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kCritical.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 494 of file log.hpp.

◆ LOG_LIMITED_DEBUG

#define LOG_LIMITED_DEBUG ( ...)
Value:
USERVER_IMPL_LOGS_DEBUG_ERASER(LOG_LIMITED_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kDebug.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 404 of file log.hpp.

◆ LOG_LIMITED_DEBUG_TO

#define LOG_LIMITED_DEBUG_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_DEBUG_ERASER(LOG_LIMITED_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kDebug.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 462 of file log.hpp.

◆ LOG_LIMITED_ERROR

#define LOG_LIMITED_ERROR ( ...)
Value:
USERVER_IMPL_LOGS_ERROR_ERASER(LOG_LIMITED_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kError.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 434 of file log.hpp.

◆ LOG_LIMITED_ERROR_TO

#define LOG_LIMITED_ERROR_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_ERROR_ERASER(LOG_LIMITED_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kError.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 486 of file log.hpp.

◆ LOG_LIMITED_INFO

#define LOG_LIMITED_INFO ( ...)
Value:
USERVER_IMPL_LOGS_INFO_ERASER(LOG_LIMITED_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kInfo.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 414 of file log.hpp.

◆ LOG_LIMITED_INFO_TO

#define LOG_LIMITED_INFO_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_INFO_ERASER(LOG_LIMITED_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kInfo.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 470 of file log.hpp.

◆ LOG_LIMITED_TO

#define LOG_LIMITED_TO ( logger,
lvl,
... )

If lvl matches the verbosity then builds a stream and evaluates a message for the logger. Ignores log messages that occur too often.

Definition at line 368 of file log.hpp.

◆ LOG_LIMITED_TRACE

#define LOG_LIMITED_TRACE ( ...)
Value:
USERVER_IMPL_LOGS_TRACE_ERASER(LOG_LIMITED_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kTrace.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 394 of file log.hpp.

◆ LOG_LIMITED_TRACE_TO

#define LOG_LIMITED_TRACE_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_TRACE_ERASER(LOG_LIMITED_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kTrace.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 454 of file log.hpp.

◆ LOG_LIMITED_WARNING

#define LOG_LIMITED_WARNING ( ...)
Value:
USERVER_IMPL_LOGS_WARNING_ERASER(LOG_LIMITED_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if the log message does not occur too often and default logger level is below or equal to logging::Level::kWarning.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 424 of file log.hpp.

◆ LOG_LIMITED_WARNING_TO

#define LOG_LIMITED_WARNING_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_WARNING_ERASER(LOG_LIMITED_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if the log message does not occur too often and logger level is below or equal to logging::Level::kWarning.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 478 of file log.hpp.

◆ LOG_TO

#define LOG_TO ( logger,
lvl,
... )

If lvl matches the verbosity then builds a stream and evaluates a message for the specified logger.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 244 of file log.hpp.

◆ LOG_TRACE

#define LOG_TRACE ( ...)
Value:
USERVER_IMPL_LOGS_TRACE_ERASER(LOG_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kTrace.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 267 of file log.hpp.

◆ LOG_TRACE_TO

#define LOG_TRACE_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_TRACE_ERASER(LOG_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kTrace.

Parameters
...optional fmt::format string literal and its arguments

Not affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 321 of file log.hpp.

◆ LOG_WARNING

#define LOG_WARNING ( ...)
Value:
USERVER_IMPL_LOGS_WARNING_ERASER(LOG_TO, USERVER_NAMESPACE::logging::GetDefaultLogger(), __VA_ARGS__)

Evaluates a message and logs it to the default logger if its level is below or equal to logging::Level::kWarning.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Examples
grpc-generic-proxy/src/proxy_service.cpp, samples/ydb_service/components/federated_topic_reader.cpp, and samples/ydb_service/components/topic_reader.cpp.

Definition at line 293 of file log.hpp.

◆ LOG_WARNING_TO

#define LOG_WARNING_TO ( logger,
... )
Value:
USERVER_IMPL_LOGS_WARNING_ERASER(LOG_TO, logger, __VA_ARGS__)

Evaluates a message and logs it to the logger if its level is below or equal to logging::Level::kWarning.

Parameters
...optional fmt::format string literal and its arguments

Affected by USERVER_FEATURE_ERASE_LOG_WITH_LEVEL CMake option.

Definition at line 345 of file log.hpp.