You.i Engine
CYILogger Class Reference

#include <logging/YiLogger.h>

Static Public Member Functions

static void Initialize ()
 
static bool IsEnabled ()
 
static void Enable ()
 
static void Disable ()
 
static void SetEnabled (bool enable)
 
static void Flush ()
 
static EYILogLevel GetFlushLevel ()
 
static void SetFlushLevel (EYILogLevel level)
 
static EYILogLevel GetLevel ()
 
static void SetLevel (EYILogLevel level)
 
static void SetPattern (const CYIString &pattern)
 
static std::shared_ptr< spdlog::sinks::sink > CreateConsoleSink ()
 
static std::shared_ptr< spdlog::sinks::sink > CreateFileSink (const CYIString &filePath, bool truncate=false)
 
static void AddSink (std::shared_ptr< spdlog::sinks::sink > pSink)
 
static void RemoveSink (const std::shared_ptr< spdlog::sinks::sink > &pSink)
 
static void RemoveAllSinks ()
 
static std::function< bool(const CYILogMessage &)> CreateFilter (std::map< CYIString, EYILogLevel > tagLevels, EYILogLevel elseMinLevel=EYILogLevel::trace)
 
static void PushFilter (std::function< bool(const CYILogMessage &)> predicate)
 
static void PopFilter ()
 
static void RemoveAllFilters ()
 

Member Function Documentation

◆ AddSink()

static void CYILogger::AddSink ( std::shared_ptr< spdlog::sinks::sink >  pSink)
static

Adds a new logging sink to be used in addition to the already installed ones.

◆ CreateConsoleSink()

static std::shared_ptr<spdlog::sinks::sink> CYILogger::CreateConsoleSink ( )
static

Creates a new logging sink for logging to console (stdout/stderr)

If connected to a user-facing terminal, log messages are decorated with colors using ANSI escape sequences.

◆ CreateFileSink()

static std::shared_ptr<spdlog::sinks::sink> CYILogger::CreateFileSink ( const CYIString filePath,
bool  truncate = false 
)
static

Creates a logging sink for writing log messages to a file.

The truncate flag controls whether the file will be truncated before output or messages will be appended to the existing log file contents.

◆ CreateFilter()

static std::function<bool(const CYILogMessage &)> CYILogger::CreateFilter ( std::map< CYIString, EYILogLevel tagLevels,
EYILogLevel  elseMinLevel = EYILogLevel::trace 
)
static

Creates a predicate function for filtering of log messages based on the supplied map of log tags as keys and minimum logging levels as values.

The map specifies filtering behavior for messages with tags matching those found in the specified map.

The predicate created by this method searches each incoming message tag in the specified map of tags, and rejects a message with a logging level below the minimum specified level of the matching log tag. If a given tag is not found, the default behavior is to just let the message pass through (and hand it over to any other filters down the stack, if installed).

There is an optional parameter however that you can explicitly specify to provide a fallback minimum level to match against, for messages that do not match any of the specified tags. This can be used for "opt-in" logging where only messages with specified tags are allowed through while the rest of the messages are either completely suppressed (EYILogLevel::off) or only emitted if serious enough (e.g. EYILogLevel::warn).

It usually makes sense to use this mode for the last filter of the filter stack.

Example 1:

{"Tag1", EYILogLevel::warn},
{"Tag2", EYILogLevel::info}
}));

Example 2, with a special fallback minimum logging level: only Tag1 and Tag2 messages will come through (if their levels are higher than specified); the rest will be suppressed.

{"Tag1", EYILogLevel::debug},
{"Tag2", EYILogLevel::trace}
}, EYILogLevel::off));

◆ Disable()

static void CYILogger::Disable ( )
static

Disables logging using the default logger.

◆ Enable()

static void CYILogger::Enable ( )
static

Enables logging using the default logger.

◆ Flush()

static void CYILogger::Flush ( )
static

Forces flushing of the internal logging buffers.

◆ GetFlushLevel()

static EYILogLevel CYILogger::GetFlushLevel ( )
static

Returns the minimum level used for automatic flushing of the internal logging buffers.

◆ GetLevel()

static EYILogLevel CYILogger::GetLevel ( )
static

Returns the current logging level.

◆ Initialize()

static void CYILogger::Initialize ( )
static

Performs initial logger setup and configuration.

This API is intended to be called once and early, before logging is used, for instance at the top of the main() entry function.

◆ IsEnabled()

static bool CYILogger::IsEnabled ( )
static

Returns true if logging using the default logger is enabled, false otherwise.

◆ PopFilter()

static void CYILogger::PopFilter ( )
static

Removes the last added log message filter from the stack of already installed filters.

Note
General logger/sink-level log message filtering is unaffected by the log filter stack.

◆ PushFilter()

static void CYILogger::PushFilter ( std::function< bool(const CYILogMessage &)>  predicate)
static

Adds a new log message filter to the stack of already installed filters.

(Each filter potentially reduces logging traffic, not unlike a stack of light filters in photo cameras.)

Before each log message reaches the installed set of logging sinks, it is sent through the stack of installed filters (if any), selectively eliminating some messages from the overall log traffic, depending on the result of the predicate function execution.

A given log message is kept if the predicate function returns true and is filtered out otherwise.

Note
General logger/sink-level log message filtering is unaffected by the log filter stack.

◆ RemoveAllFilters()

static void CYILogger::RemoveAllFilters ( )
static

Removes all log message filters.

Note
General logger/sink-level log message filtering is unaffected by the log filter stack.

◆ RemoveAllSinks()

static void CYILogger::RemoveAllSinks ( )
static

Removes all logging sinks.

The result of this operation is a no-op logging behavior. This call can be used to override stock logging sink(s) to have full run-time control over where logs go.

◆ RemoveSink()

static void CYILogger::RemoveSink ( const std::shared_ptr< spdlog::sinks::sink > &  pSink)
static

Removes a logging sink from the list of installed ones.

◆ SetEnabled()

static void CYILogger::SetEnabled ( bool  enable)
static

Enables or disables logging using the default logger, given a flag argument.

◆ SetFlushLevel()

static void CYILogger::SetFlushLevel ( EYILogLevel  level)
static

Configures automatic flushing of the internal logging buffers given a certain log level as a minimum.

◆ SetLevel()

static void CYILogger::SetLevel ( EYILogLevel  level)
static

Sets a new logging level.

All messages below the given level will be excluded from the log.

◆ SetPattern()

static void CYILogger::SetPattern ( const CYIString pattern)
static

Sets a new logging format pattern.

The pattern string consists of the specified text used verbatim plus pattern flags performing dynamic value substitution. The pattern flags are in the form of "%flag" and are modeled after the strftime function:

flag meaning
"%v" The actual text to log
"%t" Thread id
"%P" Process id
"%n" Logger's name
"%l" The full log level of the message
"%L" Short log level of the message
"%a" Abbreviated weekday name
"%A" Full weekday name
"%b" Abbreviated month name
"%B" Full month name
"%c" Date and time representation
"%C" Year in 2 last digits
"%Y" Year in 4 full digits
"%D" or "%x" Short MM/DD/YY date
"%m" Month (01-12)
"%d" Day of month (01-31)
"%H" Hours in 24-hour format (00-23)
"%I" Hours in 12-hour format (01-12)
"%M" Minutes (00-59)
"%S" Seconds (00-59)
"%e" Millisecond part of the current second (000-999)
"%f" Microsecond part of the current second (000000-999999)
"%F" Nanosecond part of the current second (000000000-999999999)
"%p" AM/PM string
"%r" Time using 12-hour clock
"%R" Time using 24-hour clock (HH:MM), equivalent to "%H:%M"
"%T" or "%X" ISO 8601 time format (HH:MM:SS), equivalent to "%H:%M:%S"
"%z" ISO 8601 offset from UTC in timezone ([+/-]HH:MM)
"%E" Seconds since the epoch
"%%" The % sign
"%o" Elapsed time in milliseconds since previous message
"%i" Elapsed time in microseconds since previous message
"%u" Elapsed time in nanoseconds since previous message
"%O" Elapsed time in seconds since previous message

For more format specifiers, see spdlog formatting documentation Example:

CYILogger::SetPattern("%Y-%m-%d %T.%e %P:%t %L/%s: %v");
Note
Some of the platform-specific log sinks may prepend some fields like timestamps to the logged lines regardless of the pattern string specifiers. In those cases, the pattern string can be adjusted accordingly to exclude specifiers causing duplicated information in the log. Formatting of the pre-supplied fields can be non-adjustable as supplied by the platform logging facilities.

The documentation for this class was generated from the following file: