userver: logging Namespace Reference
Loading...
Searching...
No Matches
logging Namespace Reference

Detailed Description

Logging macro and utilities.

Namespaces

namespace  stacktrace_cache
 Contains functions that cache stacktrace results.
 

Classes

class  DefaultLoggerGuard
 Atomically replaces the default logger. More...
 
class  DefaultLoggerLevelScope
 Allows to override default log level within a scope. Primarily for use in tests. More...
 
struct  Hex
 Formats value in a hex mode with the fixed length representation. More...
 
struct  HexShort
 
class  LogExtra
 Extra tskv fields storage. More...
 
class  LogHelper
 
struct  Quoted
 Formats a string as quoted, escaping the '\' and '"' symbols. More...
 

Typedefs

using LoggerRef = impl::LoggerBase&
 
using LoggerPtr = std::shared_ptr<impl::LoggerBase>
 

Enumerations

enum class  Format {
  kTskv ,
  kLtsv ,
  kRaw
}
 Log formats. More...
 
enum class  Level {
  kTrace = 0 ,
  kDebug = 1 ,
  kInfo = 2 ,
  kWarning = 3 ,
  kError = 4 ,
  kCritical = 5 ,
  kNone = 6
}
 Log levels. More...
 

Functions

Format FormatFromString (std::string_view format_str)
 Parse Format enum from string.
 
Level LevelFromString (std::string_view)
 Converts lowercase level name to a corresponding Level, throws std::runtime_error if no matching log level found.
 
std::string_view ToString (Level level)
 Returns a string representation of logging level, e.g. "info".
 
std::string_view ToUpperCaseString (Level level) noexcept
 Returns a string representation of logging level, e.g. "INFO".
 
std::optional< LevelOptionalLevelFromString (const std::optional< std::string > &level_name)
 Returns std::nullopt if level_name is std::nullopt, otherwise behaves exactly like logging::LevelFromString.
 
LoggerRef GetDefaultLogger () noexcept
 Returns the default logger previously set by SetDefaultLogger. If the logger was not set - returns a logger that does no logging.
 
void SetDefaultLoggerLevel (Level)
 Sets new log level for the default logger.
 
Level GetDefaultLoggerLevel () noexcept
 Returns log level for the default logger.
 
bool ShouldLog (Level level) noexcept
 
void SetLoggerLevel (LoggerRef, Level)
 Sets new log level for a logger.
 
bool LoggerShouldLog (LoggerRef logger, Level level) noexcept
 
bool LoggerShouldLog (const LoggerPtr &logger, Level level) noexcept
 
Level GetLoggerLevel (LoggerRef logger) noexcept
 
void LogFlush ()
 Forces flush of default logger message queue.
 
void LogFlush (LoggerRef logger)
 Forces flush of logger message queue.
 
LogHelperoperator<< (LogHelper &lh, std::error_code ec)
 
template<typename T >
LogHelperoperator<< (LogHelper &lh, const std::atomic< T > &value)
 
template<typename T >
LogHelperoperator<< (LogHelper &lh, const T *value) noexcept
 
template<typename T >
LogHelperoperator<< (LogHelper &lh, T *value)
 
template<typename T >
LogHelperoperator<< (LogHelper &lh, const std::optional< T > &value)
 
template<class Result , class... Args>
LogHelperoperator<< (LogHelper &lh, Result(*)(Args...))
 
LogHelperoperator<< (LogHelper &lh, std::chrono::system_clock::time_point tp)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::seconds value)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::milliseconds value)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::microseconds value)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::nanoseconds value)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::minutes value)
 
LogHelperoperator<< (LogHelper &lh, std::chrono::hours value)
 
template<typename... Types>
LogHelperoperator<< (LogHelper &lh, const std::tuple< Types... > &value)
 
LoggerRef GetNullLogger () noexcept
 Returns a logger that drops all incoming messages.
 
LoggerPtr MakeNullLogger ()
 Creates a logger that drops all incoming messages.
 
Level Parse (const yaml_config::YamlConfig &value, formats::parse::To< Level >)
 
LoggerPtr MakeStderrLogger (const std::string &name, Format format, Level level=Level::kInfo)
 Creates synchronous stderr logger with default tskv pattern.
 
LoggerPtr MakeStdoutLogger (const std::string &name, Format format, Level level=Level::kInfo)
 Creates synchronous stdout logger with default tskv pattern.
 
LoggerPtr MakeFileLogger (const std::string &name, const std::string &path, Format format, Level level=Level::kInfo)
 Creates synchronous file logger with default tskv pattern.
 

Variables

constexpr auto kLevelMax = static_cast<int>(Level::kNone)
 
const LogExtra kEmptyLogExtra
 

Typedef Documentation

◆ LoggerPtr

using logging::LoggerPtr = std::shared_ptr<impl::LoggerBase>

Definition at line 19 of file fwd.hpp.

◆ LoggerRef

using logging::LoggerRef = impl::LoggerBase&

Definition at line 18 of file fwd.hpp.

Enumeration Type Documentation

◆ Format

enum class logging::Format
strong

Log formats.

Definition at line 13 of file format.hpp.

◆ Level

enum class logging::Level
strong

Log levels.

Definition at line 15 of file level.hpp.

Function Documentation

◆ GetDefaultLogger()

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.

Note
While the coroutine engine is running, any reference to the default logger is guaranteed to be alive. No lifetime guarantees are given for the default logger reference outside the engine's lifetime. The rule of thumb there is not to keep this reference in any extended scope.

◆ GetNullLogger()

LoggerRef logging::GetNullLogger ( )
noexcept

Returns a logger that drops all incoming messages.

See also
components::Logging

◆ MakeFileLogger()

LoggerPtr logging::MakeFileLogger ( const std::string & name,
const std::string & path,
Format format,
Level level = Level::kInfo )

Creates synchronous file logger with default tskv pattern.

Parameters
namelogger name, for internal use, must be unique
pathtarget log file path
See also
components::Logging

◆ MakeNullLogger()

LoggerPtr logging::MakeNullLogger ( )

Creates a logger that drops all incoming messages.

Use GetNullLogger() is you need a reference to logger.

See also
components::Logging

◆ MakeStderrLogger()

LoggerPtr logging::MakeStderrLogger ( const std::string & name,
Format format,
Level level = Level::kInfo )

Creates synchronous stderr logger with default tskv pattern.

Parameters
namelogger name, for internal use, must be unique
See also
components::Logging

◆ MakeStdoutLogger()

LoggerPtr logging::MakeStdoutLogger ( const std::string & name,
Format format,
Level level = Level::kInfo )

Creates synchronous stdout logger with default tskv pattern.

Parameters
namelogger name, for internal use, must be unique
See also
components::Logging

◆ operator<<() [1/7]

template<typename T >
LogHelper & logging::operator<< ( LogHelper & lh,
const std::atomic< T > & value )

Definition at line 214 of file log_helper.hpp.

◆ operator<<() [2/7]

template<typename T >
LogHelper & logging::operator<< ( LogHelper & lh,
const std::optional< T > & value )

Definition at line 236 of file log_helper.hpp.

◆ operator<<() [3/7]

template<typename... Types>
LogHelper & logging::operator<< ( LogHelper & lh,
const std::tuple< Types... > & value )

Definition at line 15 of file log_helper_extras.hpp.

◆ operator<<() [4/7]

template<typename T >
LogHelper & logging::operator<< ( LogHelper & lh,
const T * value )
noexcept

Definition at line 219 of file log_helper.hpp.

◆ operator<<() [5/7]

template<class Result , class... Args>
LogHelper & logging::operator<< ( LogHelper & lh,
Result(*)(Args...)  )

Definition at line 245 of file log_helper.hpp.

◆ operator<<() [6/7]

LogHelper & logging::operator<< ( LogHelper & lh,
std::error_code ec )
inline

Definition at line 207 of file log_helper.hpp.

◆ operator<<() [7/7]

template<typename T >
LogHelper & logging::operator<< ( LogHelper & lh,
T * value )

Definition at line 231 of file log_helper.hpp.

◆ SetDefaultLoggerLevel()

void logging::SetDefaultLoggerLevel ( Level )

Sets new log level for the default logger.

Note
Prefer using logging::DefaultLoggerLevelScope if possible

◆ ShouldLog()

bool logging::ShouldLog ( Level level)
noexcept

Returns true if the provided log level is greater or equal to the current log level and to the tracing::Span (if any) local log level.

Variable Documentation

◆ kLevelMax

constexpr auto logging::kLevelMax = static_cast<int>(Level::kNone)
inlineconstexpr

Definition at line 25 of file level.hpp.