Quark  0.1
FileLoggerDevice Class Reference

An implementation of QIODevice that writes lines of text to a rotating list of files. More...

#include <FileLoggerDevice.h++>

Inheritance diagram for FileLoggerDevice:

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

Detailed Description

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.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ FileLoggerDevice()

FileLoggerDevice ( const QString &  directory,
const QString &  fileName,
qint64  maxFileSize = 1024 *1024,
int  numBacklogFiles = 2 
)

Constructs a new FileLoggerDevice with the specified attributes.

Parameters
directoryThe path to the directory in which the rotating log files will be created.
fileNameThe base name for the log files.
maxFileSizeThe maximum size of a log file, in bytes.
numBacklogFilesThe number of "backlog" files that will be created in addition to the "current" log file.

◆ ~FileLoggerDevice()

virtual ~FileLoggerDevice ( )
virtual

Destructor.

Closes the currently-open log file.

Member Function Documentation

◆ bytesAvailable()

virtual qint64 bytesAvailable ( ) const
virtual

Specified by QIODevice.

Always returns 0.

◆ close()

virtual void close ( )
virtual

Closes the currently open log file.

◆ isSequential()

virtual bool isSequential ( ) const
virtual

Specified by QIODevice.

Always returns true.

◆ open()

virtual bool open ( OpenMode  mode)
virtual

Specified by QIODevice.

Parameters
modeThe open mode. Only the following options are supported: QIODevice::WriteOnly, QIODevice::Truncate, QIODevice::Text, QIODevice::Unbuffered, QIODevice::Append.
Returns
true if a log file was successfully opened, false otherwise.

◆ readData()

virtual qint64 readData ( char *  data,
qint64  maxlen 
)
protectedvirtual

Specified by QIODevice.

Does nothing and returns -1.

◆ writeData()

virtual qint64 writeData ( const char *  data,
qint64  maxSize 
)
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.

Parameters
dataThe text data to be written.
maxSizeThe maximum number of bytes to write.
Returns
The number of bytes actually written.

Member Data Documentation

◆ LOG_FILE_EXTENSION

const char* LOG_FILE_EXTENSION
static

The file extension for the log files created by this object.


The documentation for this class was generated from the following file: