Quark
0.1
|
An implementation of QIODevice that writes lines of text to a rotating list of files. More...
#include <FileLoggerDevice.h++>
Public Member Functions | |
FileLoggerDevice (const QString &directory, const QString &fileName, qint64 maxFileSize=1024 *1024, int numBacklogFiles=2) | |
Constructs a new FileLoggerDevice with the specified attributes. More... | |
virtual | ~FileLoggerDevice () |
Destructor. More... | |
virtual bool | open (OpenMode mode) |
Specified by QIODevice. More... | |
virtual void | close () |
Closes the currently open log file. More... | |
virtual bool | isSequential () const |
Specified by QIODevice. More... | |
virtual qint64 | bytesAvailable () const |
Specified by QIODevice. More... | |
Static Public Attributes | |
static const char * | LOG_FILE_EXTENSION |
The file extension for the log files created by this object. More... | |
Protected Member Functions | |
virtual qint64 | readData (char *data, qint64 maxlen) |
Specified by QIODevice. More... | |
virtual qint64 | writeData (const char *data, qint64 maxSize) |
Specified by QIODevice. More... | |
An implementation of QIODevice that writes lines of text to a rotating list of files.
Intended for use with QDebug as a rotating log. The class writes data to a "current" file as long as the size of the file would not exceed the specified limit. Once the limit is reached, all existing log files are rotated. If the maximum number of log files already exists, the oldest log file is deleted. A new "current" file is then opened, and writing continues.
FileLoggerDevice | ( | const QString & | directory, |
const QString & | fileName, | ||
qint64 | maxFileSize = 1024 *1024 , |
||
int | numBacklogFiles = 2 |
||
) |
Constructs a new FileLoggerDevice with the specified attributes.
directory | The path to the directory in which the rotating log files will be created. |
fileName | The base name for the log files. |
maxFileSize | The maximum size of a log file, in bytes. |
numBacklogFiles | The number of "backlog" files that will be created in addition to the "current" log file. |
|
virtual |
Destructor.
Closes the currently-open log file.
|
virtual |
Specified by QIODevice.
Always returns 0.
|
virtual |
Closes the currently open log file.
|
virtual |
Specified by QIODevice.
Always returns true
.
|
virtual |
Specified by QIODevice.
mode | The open mode. Only the following options are supported: QIODevice::WriteOnly, QIODevice::Truncate, QIODevice::Text, QIODevice::Unbuffered, QIODevice::Append. |
true
if a log file was successfully opened, false
otherwise.
|
protectedvirtual |
Specified by QIODevice.
Does nothing and returns -1.
|
protectedvirtual |
Specified by QIODevice.
Writes data to the log file. Writes newline-terminated lines from the data into the log file as long as the log file remains below the maximum file size. If the next line to be written would increase the file size beyond this limit, the logs are rotated, and then writing continues.
data | The text data to be written. |
maxSize | The maximum number of bytes to write. |
|
static |
The file extension for the log files created by this object.