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 | Level : std::uint8_t { kTrace = 0 , kDebug = 1 , kInfo = 2 , kWarning = 3 , kError = 4 , kCritical = 5 , kNone = 6 } |
Log levels. More... | |
enum class | Format { kTskv , kLtsv , kRaw } |
Log formats. More... | |
Functions | |
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. | |
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< Level > | OptionalLevelFromString (const std::optional< std::string > &level_name) |
Returns std::nullopt if level_name is std::nullopt, otherwise behaves exactly like logging::LevelFromString. | |
LogHelper & | operator<< (LogHelper &lh, std::error_code ec) |
template<typename T > | |
LogHelper & | operator<< (LogHelper &lh, const std::atomic< T > &value) |
template<typename T > | |
LogHelper & | operator<< (LogHelper &lh, const T *value) noexcept |
template<typename T > | |
LogHelper & | operator<< (LogHelper &lh, T *value) |
template<typename T > | |
LogHelper & | operator<< (LogHelper &lh, const std::optional< T > &value) |
template<class Result , class... Args> | |
LogHelper & | operator<< (LogHelper &lh, Result(*)(Args...)) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::system_clock::time_point tp) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::seconds value) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::milliseconds value) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::microseconds value) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::nanoseconds value) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::minutes value) |
LogHelper & | operator<< (LogHelper &lh, std::chrono::hours value) |
Format | FormatFromString (std::string_view format_str) |
Parse Format enum from string. | |
template<typename... Types> | |
LogHelper & | operator<< (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 >) |
Level | Parse (const formats::json::Value &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 |
|
strong |
Log formats.
Definition at line 13 of file format.hpp.
|
strong |
|
noexcept |
Returns the default logger previously set by SetDefaultLogger. If the logger was not set - returns a logger that does no logging.
|
noexcept |
Returns a logger that drops all incoming messages.
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.
name | logger name, for internal use, must be unique |
path | target log file path |
LoggerPtr logging::MakeNullLogger | ( | ) |
Creates a logger that drops all incoming messages.
Use GetNullLogger() is you need a reference to logger.
LoggerPtr logging::MakeStderrLogger | ( | const std::string & | name, |
Format | format, | ||
Level | level = Level::kInfo ) |
Creates synchronous stderr logger with default tskv pattern.
name | logger name, for internal use, must be unique |
LoggerPtr logging::MakeStdoutLogger | ( | const std::string & | name, |
Format | format, | ||
Level | level = Level::kInfo ) |
Creates synchronous stdout logger with default tskv pattern.
name | logger name, for internal use, must be unique |
LogHelper & logging::operator<< | ( | LogHelper & | lh, |
const std::atomic< T > & | value ) |
Definition at line 218 of file log_helper.hpp.
LogHelper & logging::operator<< | ( | LogHelper & | lh, |
const std::optional< T > & | value ) |
Definition at line 240 of file log_helper.hpp.
LogHelper & logging::operator<< | ( | LogHelper & | lh, |
const std::tuple< Types... > & | value ) |
Definition at line 15 of file log_helper_extras.hpp.
Definition at line 223 of file log_helper.hpp.
LogHelper & logging::operator<< | ( | LogHelper & | lh, |
Result(*)(Args...) | ) |
Definition at line 249 of file log_helper.hpp.
Definition at line 212 of file log_helper.hpp.
Definition at line 235 of file log_helper.hpp.
void logging::SetDefaultLoggerLevel | ( | Level | ) |
Sets new log level for the default logger.
|
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.