ImFusion C++ SDK 4.4.0
ImFusion::Log::FileSink Class Reference

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

Default implementation for a Logger that writes to the filesystem. More...

Inheritance diagram for ImFusion::Log::FileSink:

Detailed Description

Default implementation for a Logger that writes to the filesystem.

Public Types

enum  Options { None = 0 , Truncate = 1 << 0 , SequentialThreadIds = 1 << 1 }
 Configuration options. More...
enum class  Result { NoActionNeeded , Successful , Failed }
 Enumeration of possible return values of rotateFiles(). More...

Public Member Functions

 FileSink (const Filesystem::Path &filename, Flags< Options > options=Options::None)
 Instantiates a new FileLogger.
Result rotateFiles (ByteSize sizeLimit, int numArchived)
 Performs log file rotation for this sink if applicable.
const Filesystem::Pathfilename () const
 Returns the path of the log file.
std::vector< Filesystem::Pathfilenames () const
 Returns the path of the log file as well as a best-effort list of archived log files.
Public Member Functions inherited from ImFusion::Log::Sink
void log (const LogCapture &capture)
 Logs the given message.
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.

Protected Member Functions

void logImpl (const LogCapture &capture) override
 Performs the actual logging of the given message.
void flush () override
 Ensure that all log captures are fully committed/written.
void openLogfile (Flags< Options > options)
void closeLogfile ()

Protected Attributes

Filesystem::Path m_filename
std::ofstream m_file
bool m_isRotating = false
bool m_useThreadMap = false
std::vector< LogCapturem_queuedCaptures
std::unordered_map< std::thread::id, size_t > m_threadMap

Member Enumeration Documentation

◆ Options

Configuration options.

Enumerator
None 

Append log output to the log file.

Truncate 

Clear the log file.

SequentialThreadIds 

Use sequential thread IDs starting from 0 instead of the ones from the OS.

◆ Result

Enumeration of possible return values of rotateFiles().

Enumerator
NoActionNeeded 

No log file rotation was performed since the log file size was lower than the threshold.

Successful 

Log file rotation succeeded.

Failed 

Log file rotation failed and was aborted.

Constructor & Destructor Documentation

◆ FileSink()

ImFusion::Log::FileSink::FileSink ( const Filesystem::Path & filename,
Flags< Options > options = Options::None )

Instantiates a new FileLogger.

Parameters
filenameFile name for the log file.
optionsConfiguration options.
Exceptions
std::runtime_errorThe constructor will throw if it can not open filename for any reason.

Member Function Documentation

◆ rotateFiles()

Result ImFusion::Log::FileSink::rotateFiles ( ByteSize sizeLimit,
int numArchived )

Performs log file rotation for this sink if applicable.

If the current log file size exceeds sizeLimit a log file rotation will be performed keeping up to numArchived archived files around in addition to the active log file. If the total number of archived log files exceeds this threshold the oldest archived log file will be deleted.

Archived files will be named <logfile-basename>_N.<logfile-extension> where N is counted from 1 to numArchived.

Warning
This function is not thread-safe. Do not call it while another thread might write to this sink as it might lose or corrupt the log file. It is safest if you call this function directly after construction and before calling Log::addSink().

◆ logImpl()

void ImFusion::Log::FileSink::logImpl ( const LogCapture & capture)
overrideprotectedvirtual

Performs the actual logging of the given message.

Called by log() after filtering.

Parameters
captureLog capture

Implements ImFusion::Log::Sink.

◆ flush()

void ImFusion::Log::FileSink::flush ( )
overrideprotectedvirtual

Ensure that all log captures are fully committed/written.

Implements ImFusion::Log::Sink.


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