summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/logger/FileAppender.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/logger/FileAppender.h')
-rw-r--r--rbutil/rbutilqt/logger/FileAppender.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/logger/FileAppender.h b/rbutil/rbutilqt/logger/FileAppender.h
new file mode 100644
index 0000000000..70a70c3e43
--- /dev/null
+++ b/rbutil/rbutilqt/logger/FileAppender.h
@@ -0,0 +1,63 @@
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
26//! File is the simple appender that writes the log records to the plain text file.
27class CUTELOGGERSHARED_EXPORT FileAppender : public AbstractStringAppender
28{
29 public:
30 //! Constructs the new file appender assigned to file with the given name.
31 FileAppender(const QString& fileName = QString());
32 ~FileAppender();
33
34 //! Returns the name set by setFileName() or to the FileAppender constructor.
35 /**
36 * \sa setFileName()
37 */
38 QString fileName() const;
39
40 //! Sets the name of the file. The name can have no path, a relative path, or an absolute path.
41 /**
42 * \sa fileName()
43 */
44 void setFileName(const QString&);
45
46 protected:
47 //! Write the log record to the file.
48 /**
49 * \sa fileName()
50 * \sa AbstractStringAppender::format()
51 */
52 virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
53 const char* function, const QString& message);
54 bool openFile();
55 void closeFile();
56
57 private:
58 QFile m_logFile;
59 QTextStream m_logStream;
60 mutable QMutex m_logFileMutex;
61};
62
63#endif // FILEAPPENDER_H