Avara3D 0.2.0
C++ API reference
a3d::log::FileLogSink Class Reference

LogSink that appends output to a file and rotates older files by size. More...

#include <a3d/log/sink/FileLogSink.h>

Inheritance diagram for a3d::log::FileLogSink:
[legend]

Public Member Functions

 FileLogSink (const std::filesystem::path &relPath, int maxFiles=DEFAULT_MAX_FILES, int maxFilesize=DEFAULT_MAX_FILESIZE)
 Creates an append-mode file sink with size-based rotation. More...
 
const std::filesystem::path & filepath () const
 Returns the path of the active log file. More...
 
int maxFiles () const
 Returns the configured maximum number of retained log files. More...
 
int maxFilesize () const
 Returns the configured rotation size threshold in bytes. More...
 
void write (const std::string &output, Level level) override
 Appends output to the active file and performs size-based rotation when needed. More...
 
void flush () override
 Flushes buffered output to the active file. More...
 
virtual void write (const std::string &output, Level level)=0
 Writes already-formatted output associated with level. More...
 
virtual void flush ()
 Flushes buffered sink output; the base implementation does nothing. More...
 

Detailed Description

LogSink that appends output to a file and rotates older files by size.

Rotation is checked after each write. Numbered backups are kept beside the active file and older backups are removed as the configured file limit is reached.

Definition at line 29 of file FileLogSink.h.

Constructor & Destructor Documentation

◆ FileLogSink()

a3d::log::FileLogSink::FileLogSink ( const std::filesystem::path &  relPath,
int  maxFiles = DEFAULT_MAX_FILES,
int  maxFilesize = DEFAULT_MAX_FILESIZE 
)
explicit

Creates an append-mode file sink with size-based rotation.

Missing parent directories are created when possible. maxFilesize is measured in bytes; the defaults retain up to five files with a 1 MiB size threshold for each active file.

Exceptions
std::invalid_argumentif maxFiles or maxFilesize is not greater than zero.
std::runtime_errorif required directories cannot be created or the log file cannot be opened.

Member Function Documentation

◆ filepath()

const std::filesystem::path & a3d::log::FileLogSink::filepath ( ) const

Returns the path of the active log file.

◆ flush()

void a3d::log::FileLogSink::flush ( )
overridevirtual

Flushes buffered output to the active file.

Reimplemented from a3d::log::LogSink.

◆ maxFiles()

int a3d::log::FileLogSink::maxFiles ( ) const

Returns the configured maximum number of retained log files.

◆ maxFilesize()

int a3d::log::FileLogSink::maxFilesize ( ) const

Returns the configured rotation size threshold in bytes.

◆ write()

void a3d::log::FileLogSink::write ( const std::string &  output,
Level  level 
)
overridevirtual

Appends output to the active file and performs size-based rotation when needed.

Implements a3d::log::LogSink.


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