Home
Base module

RotatingFileChannel

Log channel that writes to time-rotated log files.

RotatingFileChannel

#include <icy/logger.h>
class RotatingFileChannel

Defined in src/base/include/icy/logger.h:478

Inherits: LogChannel

Log channel that writes to time-rotated log files.

List of all members

NameKindOwner
RotatingFileChannelfunctionDeclared here
~RotatingFileChannelfunctionDeclared here
writefunctionDeclared here
rotatefunctionDeclared here
dirfunctionDeclared here
filenamefunctionDeclared here
rotationIntervalfunctionDeclared here
setDirfunctionDeclared here
setExtensionfunctionDeclared here
setRotationIntervalfunctionDeclared here
_fstreamvariableDeclared here
_dirvariableDeclared here
_filenamevariableDeclared here
_extensionvariableDeclared here
_rotationIntervalvariableDeclared here
_rotatedAtvariableDeclared here
LogChannelfunctionInherited from LogChannel
~LogChannelfunctionInherited from LogChannel
writefunctionInherited from LogChannel
writefunctionInherited from LogChannel
formatfunctionInherited from LogChannel
namefunctionInherited from LogChannel
levelfunctionInherited from LogChannel
timeFormatfunctionInherited from LogChannel
setLevelfunctionInherited from LogChannel
setTimeFormatfunctionInherited from LogChannel
setFilterfunctionInherited from LogChannel
_namevariableInherited from LogChannel
_levelvariableInherited from LogChannel
_timeFormatvariableInherited from LogChannel
_filtervariableInherited from LogChannel

Inherited from LogChannel

KindNameDescription
functionLogChannel
function~LogChannel virtualDefaulted destructor.
functionwrite virtualWrites a log stream entry to this channel.
functionwrite virtualWrites a plain message to this channel.
functionformat virtualFormats a log stream entry into the given output stream.
functionname const inlineReturns the channel name.
functionlevel const inlineReturns the minimum severity level.
functiontimeFormat const inlineReturns the timestamp format string.
functionsetLevel inlineSets the minimum severity level.
functionsetTimeFormat inlineSets the timestamp format string.
functionsetFilter inlineSets a realm filter; only messages whose realm matches are written.
variable_name
variable_level
variable_timeFormat
variable_filter

Public Methods

ReturnNameDescription
RotatingFileChannel
voidwrite virtual overrideFormats 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 = Level::Debug, std::string extension = "log", int rotationInterval = 12 *3600, std::string timeFormat = "%H:%M:%S")

Defined in src/base/include/icy/logger.h:487

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 override

virtual void write(const LogStream & stream) override

Defined in src/base/include/icy/logger.h:498

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.
Reimplements

rotate

virtual

virtual void rotate()

Defined in src/base/include/icy/logger.h:501

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


dir

const inline

inline std::string dir() const

Defined in src/base/include/icy/logger.h:504

Returns the directory where log files are written.


filename

const inline

inline std::string filename() const

Defined in src/base/include/icy/logger.h:507

Returns the filename of the currently open log file.


rotationInterval

const inline

inline int rotationInterval() const

Defined in src/base/include/icy/logger.h:510

Returns the rotation interval in seconds.


setDir

inline

inline void setDir(std::string dir)

Defined in src/base/include/icy/logger.h:514

Sets the output directory for rotated log files.

Parameters

  • dir Target directory path.

setExtension

inline

inline void setExtension(std::string ext)

Defined in src/base/include/icy/logger.h:518

Sets the file extension for rotated log files.

Parameters

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

setRotationInterval

inline

inline void setRotationInterval(int interval)

Defined in src/base/include/icy/logger.h:522

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

Defined in src/base/include/icy/logger.h:525


_dir

std::string _dir

Defined in src/base/include/icy/logger.h:526


_filename

std::string _filename

Defined in src/base/include/icy/logger.h:527


_extension

std::string _extension

Defined in src/base/include/icy/logger.h:528


_rotationInterval

int _rotationInterval

Defined in src/base/include/icy/logger.h:529

The log rotation interval in seconds.


_rotatedAt

time_t _rotatedAt

Defined in src/base/include/icy/logger.h:530

The time the log was last rotated.