Quark  0.1
FileLoggerDevice.h++
Go to the documentation of this file.
1 #ifndef __libquark_util_FileLoggerDevice_hxx
2 #define __libquark_util_FileLoggerDevice_hxx
3 
4 #include <QFile>
5 #include <QIODevice>
6 #include <QScopedPointer>
7 #include <QString>
8 
9 #include <quark/Quark.h++>
10 
11 namespace quark {
12 namespace util {
13 
25 class LIBQUARK_API FileLoggerDevice : public QIODevice
26 {
27  public:
28 
38  FileLoggerDevice(const QString &directory, const QString &fileName,
39  qint64 maxFileSize = 1024 * 1024, int numBacklogFiles = 2);
40 
42  virtual ~FileLoggerDevice();
43 
53  virtual bool open(OpenMode mode);
54 
56  virtual void close();
57 
59  virtual bool isSequential() const;
60 
62  virtual qint64 bytesAvailable() const;
63 
65  static const char *LOG_FILE_EXTENSION;
66 
67  protected:
68 
70  virtual qint64 readData(char *data, qint64 maxlen);
71 
82  virtual qint64 writeData(const char *data, qint64 maxSize);
83 
84  private:
85 
86  bool rotateFiles();
87  QString generateFilePath(int n = 0);
88 
89  QString _directory;
90  QString _fileName;
91  qint64 _maxFileSize;
92  int _numBacklogFiles;
93  QScopedPointer<QFile> _file;
94  qint64 _fileSize;
95 };
96 
97 } // namespace util
98 } // namespace quark
99 
100 #endif // __libquark_util_FileLoggerDevice_hxx
Definition: BarChartView.h++:6
An implementation of QIODevice that writes lines of text to a rotating list of files.
Definition: FileLoggerDevice.h++:25
#define LIBQUARK_API
Definition: Quark.h++:18
static const char * LOG_FILE_EXTENSION
The file extension for the log files created by this object.
Definition: FileLoggerDevice.h++:65