Base module

RotatingFileChannel

Log channel that writes to time-rotated log files.

RotatingFileChannel

#include <icy/logger.h>

Inherits: LogChannel

Log channel that writes to time-rotated log files.

Public Methods

ReturnNameDescription
RotatingFileChannel#### Parameters
voidwrite virtualFormats and writes the log stream entry to the current log file. Rotates the file if the rotation interval has elapsed.
voidrotate virtualCloses the current log file and opens a new one with a timestamped filename.
std::stringdir const inlineReturns the directory where log files are written.
std::stringfilename const inlineReturns the filename of the currently open log file.
introtationInterval const inlineReturns the rotation interval in seconds.
voidsetDir inlineSets the output directory for rotated log files.
voidsetExtension inlineSets the file extension for rotated log files.
voidsetRotationInterval inlineSets the rotation interval.

RotatingFileChannel

RotatingFileChannel(std::string name, std::string dir, Level level, std::string extension, int rotationInterval, std::string timeFormat)

Parameters

  • name Unique channel name.

  • dir Directory in which rotated log files are written.

  • level Minimum severity level; messages below this level are dropped.

  • extension File extension for log files (without leading dot).

  • rotationInterval Seconds between log rotations (default: 12 hours).

  • timeFormat strftime-compatible format string for timestamps.


write

virtual

virtual void write(const LogStream & stream)

Formats and writes the log stream entry to the current log file. Rotates the file if the rotation interval has elapsed.

Parameters

  • stream The log stream to write.

rotate

virtual

virtual void rotate()

Closes the current log file and opens a new one with a timestamped filename.


dir

const inline

inline std::string dir() const

Returns the directory where log files are written.


filename

const inline

inline std::string filename() const

Returns the filename of the currently open log file.


rotationInterval

const inline

inline int rotationInterval() const

Returns the rotation interval in seconds.


setDir

inline

inline void setDir(std::string dir)

Sets the output directory for rotated log files.

Parameters

  • dir Target directory path.

setExtension

inline

inline void setExtension(std::string ext)

Sets the file extension for rotated log files.

Parameters

  • ext Extension without leading dot (e.g. "log").

setRotationInterval

inline

inline void setRotationInterval(int interval)

Sets the rotation interval.

Parameters

  • interval Number of seconds between rotations.

Protected Attributes

ReturnNameDescription
std::unique_ptr< std::ofstream >_fstream
std::string_dir
std::string_filename
std::string_extension
int_rotationIntervalThe log rotation interval in seconds.
time_t_rotatedAtThe time the log was last rotated.

_fstream

std::unique_ptr< std::ofstream > _fstream

_dir

std::string _dir

_filename

std::string _filename

_extension

std::string _extension

_rotationInterval

int _rotationInterval

The log rotation interval in seconds.


_rotatedAt

time_t _rotatedAt

The time the log was last rotated.