![]() |
ImFusion C++ SDK 4.5.0
|
#include <ImFusion/Core/Log/FileSink.h>
Default implementation for a Logger that writes to the filesystem. More...
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 Types inherited from ImFusion::Log::Sink | |
| 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 | |
| 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::Path & | filename () const |
| Returns the path of the log file. | |
| std::vector< Filesystem::Path > | filenames () 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. | |
| 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 | |
| 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< LogCapture > | m_queuedCaptures |
| std::unordered_map< std::thread::id, size_t > | m_threadMap |
| Protected Attributes inherited from ImFusion::Log::Sink | |
| DateTimeFormatFunction | m_dateTimeFormatFunction |
|
strong |
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. |
| ImFusion::Log::FileSink::FileSink | ( | const Filesystem::Path & | filename, |
| Flags< Options > | options = Options::None ) |
Instantiates a new FileLogger.
| filename | File name for the log file. |
| options | Configuration options. |
| std::runtime_error | The constructor will throw if it can not open filename for any reason. |
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.
|
overrideprotectedvirtual |
Performs the actual logging of the given message.
Called by log() after filtering.
| capture | Log capture |
Implements ImFusion::Log::Sink.
|
overrideprotectedvirtual |
Ensure that all log captures are fully committed/written.
Implements ImFusion::Log::Sink.