Log file writer. More...
#include <fileWriter.hpp>
Public Member Functions | |
| FileWriter (const anch::conf::Section &conf) | |
| virtual | ~FileWriter () |
| virtual void | write (const std::string &message) |
| Public Member Functions inherited from anch::log::Writer | |
| Writer (const anch::conf::Section &conf) | |
| virtual | ~Writer () |
Protected Member Functions | |
| void | writeLine (const std::string &line) |
| bool | rotate () |
| void | rotateFiles () |
| std::filesystem::path | archive (std::uint32_t index) const |
| Protected Member Functions inherited from anch::log::Writer | |
| std::string | format (const std::string &msg) |
Protected Attributes | |
| std::ofstream | _output |
| std::filesystem::path | _path |
| std::uint64_t | _maxSize |
| std::uint32_t | _maxFiles |
Log file writer.
Manage file writer with file rotation on size.
Configuration:
path: the log file path (mandatory ; its directory has to exist) ;max-size: maximum file size before rotation, in bytes, with optional unit K, M, G or T (powers of 1024). No rotation when not set ;max-rotate-files: number of archives to keep (<path>.0 is the most recent). Default to 1. With 0, the file is truncated on rotation.File system errors during rotation are ignored: the current file is kept and rotation is tried again later.
| anch::log::FileWriter::FileWriter | ( | const anch::conf::Section & | conf | ) |
FileWriter constructor
| conf | the writer's configuration |
| std::invalid_argument | invalid configuration or file which can not be opened |
|
virtual |
FileWriter destructor
|
protected |
Archive path
| index | the archive index |
<path>.<index>
|
protected |
Check if file has to be rotate according to configuration and its size
|
protected |
Rotate files when current reachs the maximum file length.
|
virtual |
Write message in the file and flush it.
Rotate log file when needed.
| message | Message to write |
Implements anch::log::Writer.
Reimplemented in anch::log::LowPriorityWriter, and anch::log::ThreadSafeWriter.
|
protected |
Write an already formatted line in the file (without flush) and rotate log file when needed.
| line | the formatted line (without end of line) |
|
protected |
Number of archives to keep
|
protected |
Maximum file size (0 for no rotation)
|
protected |
Ouput file stream
|
protected |
File name