RotatingFileChannel
RotatingFileChannel
#include <icy/logger.h>Inherits:
LogChannel
Log channel that writes to time-rotated log files.
Public Methods
| Return | Name | Description |
|---|---|---|
RotatingFileChannel | #### Parameters | |
void | write virtual | Formats and writes the log stream entry to the current log file. Rotates the file if the rotation interval has elapsed. |
void | rotate virtual | Closes the current log file and opens a new one with a timestamped filename. |
std::string | dir const inline | Returns the directory where log files are written. |
std::string | filename const inline | Returns the filename of the currently open log file. |
int | rotationInterval const inline | Returns the rotation interval in seconds. |
void | setDir inline | Sets the output directory for rotated log files. |
void | setExtension inline | Sets the file extension for rotated log files. |
void | setRotationInterval inline | Sets the rotation interval. |
RotatingFileChannel
RotatingFileChannel(std::string name, std::string dir, Level level, std::string extension, int rotationInterval, std::string timeFormat)Parameters
nameUnique channel name.dirDirectory in which rotated log files are written.levelMinimum severity level; messages below this level are dropped.extensionFile extension for log files (without leading dot).rotationIntervalSeconds between log rotations (default: 12 hours).timeFormatstrftime-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
streamThe 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() constReturns the directory where log files are written.
filename
const inline
inline std::string filename() constReturns the filename of the currently open log file.
rotationInterval
const inline
inline int rotationInterval() constReturns the rotation interval in seconds.
setDir
inline
inline void setDir(std::string dir)Sets the output directory for rotated log files.
Parameters
dirTarget directory path.
setExtension
inline
inline void setExtension(std::string ext)Sets the file extension for rotated log files.
Parameters
extExtension without leading dot (e.g. "log").
setRotationInterval
inline
inline void setRotationInterval(int interval)Sets the rotation interval.
Parameters
intervalNumber of seconds between rotations.
Protected Attributes
| Return | Name | Description |
|---|---|---|
std::unique_ptr< std::ofstream > | _fstream | |
std::string | _dir | |
std::string | _filename | |
std::string | _extension | |
int | _rotationInterval | The log rotation interval in seconds. |
time_t | _rotatedAt | The 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 _rotationIntervalThe log rotation interval in seconds.
_rotatedAt
time_t _rotatedAtThe time the log was last rotated.
