ImFusion C++ SDK 4.5.0
ImFusion::Log::Sink Class Referenceabstract

#include <ImFusion/Core/Log/Sink.h>

Interface for a logger sink that can receive individual log events. More...

Inheritance diagram for ImFusion::Log::Sink:

Detailed Description

Interface for a logger sink that can receive individual log events.

Classes

struct  LogCapture
 Structure storing a single log event. More...
struct  Filter
 Structure storing a filter. More...

Public Types

using DateTimeFormatFunction = std::function<std::string(const std::chrono::system_clock::time_point& time)>
 Signature of the callback function used by Sink to format date and time.

Public Member Functions

void log (const LogCapture &capture)
 Logs the given message.
virtual void flush ()=0
 Ensure that all log captures are fully committed/written.
bool isAccepted (Level level, const char *category) noexcept
 Checks whether a log message of given level and category is accepted (i.e.
void addWhitelistFilter (Log::Level minLevel, const std::string &category)
 Adds a whitelist filter for this logger: both conditions of the filter must be met to accept a message.
void addBlacklistFilter (Log::Level maxLevel, const std::string &category)
 Adds a blacklist filter for this logger: both conditions of the filter must be met to reject a message.
const std::vector< Filter > & whitelistFilters () const
 Return the set of whitelist filters.
const std::vector< Filter > & blacklistFilters () const
 Return the set of blacklist filters.
void removeFilters (const std::string &category)
 Removes all filters matching category.
void clearFilters ()
 Clear all filters.
bool isEnabled () const
 Returns the flag whether this logger is enabled.
void setEnabled (bool value)
 Sets the flag whether this logger is enabled.
bool setDateTimeFormatFunction (const DateTimeFormatFunction &fcn)
 Set a callback function for formatting date and time.
std::string defaultDateTimeFormatFunction (const std::chrono::system_clock::time_point &time)
 Get a string representing date and time.

Protected Member Functions

virtual void logImpl (const LogCapture &capture)=0
 Performs the actual logging of the given message.

Protected Attributes

DateTimeFormatFunction m_dateTimeFormatFunction

Member Typedef Documentation

◆ DateTimeFormatFunction

using ImFusion::Log::Sink::DateTimeFormatFunction = std::function<std::string(const std::chrono::system_clock::time_point& time)>

Signature of the callback function used by Sink to format date and time.

The time provides the time point to be converted to string. Returns the formatted string

Member Function Documentation

◆ log()

void ImFusion::Log::Sink::log ( const LogCapture & capture)

Logs the given message.

Calls logImpl() if the message passes all registered filters.

Parameters
captureLog capture

◆ flush()

virtual void ImFusion::Log::Sink::flush ( )
pure virtual

Ensure that all log captures are fully committed/written.

Implemented in ImFusion::Log::ConsoleSink, ImFusion::Log::FileSink, and ImFusion::QDebugAppender.

◆ isAccepted()

bool ImFusion::Log::Sink::isAccepted ( Level level,
const char * category )
noexcept

Checks whether a log message of given level and category is accepted (i.e.

consumed) by this Sink. A message is accepted in case it does not match any blacklist filter or if it matches at least one whitelist filter. If there are no filters defined all messages are accepted.

◆ addWhitelistFilter()

void ImFusion::Log::Sink::addWhitelistFilter ( Log::Level minLevel,
const std::string & category )

Adds a whitelist filter for this logger: both conditions of the filter must be met to accept a message.

In case of multiple whitelist filters, messages matching at least one filter will be logged, even if they also match a blacklist filter. If there are no filters defined, all messages are accepted.

Parameters
minLevelMinimum log level, messages of this level or higher will be logged.
categoryCategory filter, messages where the category contains category will be logged. Leave empty to accept all categories.

◆ addBlacklistFilter()

void ImFusion::Log::Sink::addBlacklistFilter ( Log::Level maxLevel,
const std::string & category )

Adds a blacklist filter for this logger: both conditions of the filter must be met to reject a message.

Only messages matching a whitelist filter or not matching any blacklist filter will be logged (i.e. whitelist filters take precedence over blacklist filters). If there are no filters defined all messages are accepted.

Parameters
maxLevelMaximum log level, messages of this level or lower will not be logged.
categoryCategory filter, messages where the category contains category will not be logged. Leave empty to reject all categories.

◆ setDateTimeFormatFunction()

bool ImFusion::Log::Sink::setDateTimeFormatFunction ( const DateTimeFormatFunction & fcn)

Set a callback function for formatting date and time.

Function checks whether fcn is empty and whether its execution with a current time throws an exception (including fmt::format_error). If this is the case, the function will return false and the Sink will continue using a previously set formatting function. If no above issues have occured the function will return true.

◆ logImpl()

virtual void ImFusion::Log::Sink::logImpl ( const LogCapture & capture)
protectedpure virtual

Performs the actual logging of the given message.

Called by log() after filtering.

Parameters
captureLog capture

Implemented in ImFusion::Log::ConsoleSink, ImFusion::Log::FileSink, and ImFusion::QDebugAppender.


The documentation for this class was generated from the following file:
  • ImFusion/Core/Log/Sink.h
Search Tab / S to search, Esc to close