CuteLogger
Fast and simple logging solution for Qt based applications
FileAppender.h
1/*
2 Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com)
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License version 2.1
6 as published by the Free Software Foundation and appearing in the file
7 LICENSE.LGPL included in the packaging of this file.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13*/
14#ifndef FILEAPPENDER_H
15#define FILEAPPENDER_H
16
17// Logger
18#include "CuteLogger_global.h"
19#include <AbstractStringAppender.h>
20
21// Qt
22#include <QFile>
23#include <QTextStream>
24
25
26class CUTELOGGERSHARED_EXPORT FileAppender : public AbstractStringAppender
27{
28 public:
29 FileAppender(const QString& fileName = QString());
31
32 QString fileName() const;
33 void setFileName(const QString&);
34
35 bool flushOnWrite() const;
36 void setFlushOnWrite(bool);
37
38 bool flush();
39
40 bool reopenFile();
41
42 protected:
43 virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
44 const char* function, const QString& category, const QString& message);
45 bool openFile();
46 void closeFile();
47
48 private:
49 QFile m_logFile;
50 bool m_flushOnWrite;
51 QTextStream m_logStream;
52 mutable QMutex m_logFileMutex;
53};
54
55#endif // FILEAPPENDER_H
virtual void append(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, const QString &category, const QString &message)=0
Writes the log record to the logger instance.
AbstractStringAppender()
Constructs a new string appender object.
Definition AbstractStringAppender.cpp:51
QString fileName() const
Returns the name set by setFileName() or to the FileAppender constructor.
Definition FileAppender.cpp:45
void setFlushOnWrite(bool)
Allows FileAppender to flush file immediately after writing a log record.
Definition FileAppender.cpp:83
FileAppender(const QString &fileName=QString())
Constructs the new file appender assigned to file with the given name.
Definition FileAppender.cpp:28
bool flush()
Force-flush any remaining buffers to file system. Returns true if successful, otherwise returns false...
Definition FileAppender.cpp:90
void setFileName(const QString &)
Sets the name of the file. The name can have no path, a relative path, or an absolute path.
Definition FileAppender.cpp:56
LogLevel
Describes the possible severity levels of the log records.
Definition Logger.h:101