DtkCore
DTK Core module
RollingFileAppender.h
1/*
2 * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd.
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 as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * any later version.
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 General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef ROLLINGFILEAPPENDER_H
19#define ROLLINGFILEAPPENDER_H
20
21#include <QDateTime>
22
23#include <FileAppender.h>
24
25DCORE_BEGIN_NAMESPACE
26
27class CUTELOGGERSHARED_EXPORT RollingFileAppender : public FileAppender
28{
29 public:
35 {
37 MinutelyRollover = 0,
47 MonthlyRollover
48 };
49
50 RollingFileAppender(const QString& fileName = QString());
51
52 DatePattern datePattern() const;
53 void setDatePattern(DatePattern datePattern);
54 void setDatePattern(const QString& datePattern);
55
56 QString datePatternString() const;
57
58 void setLogFilesLimit(int limit);
59 int logFilesLimit() const;
60
61 void setLogSizeLimit(int qint64);
62 qint64 logSizeLimit() const;
63
64 protected:
65 virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
66 const char* function, const QString& category, const QString& message);
67
68 private:
69 void rollOver();
70 void computeRollOverTime();
71 void computeFrequency();
72 void removeOldFiles();
73 void setDatePatternString(const QString& datePatternString);
74
75 QString m_datePatternString;
76 DatePattern m_frequency;
77
78 QDateTime m_rollOverTime;
79 QString m_rollOverSuffix;
80 int m_logFilesLimit;
81 qint64 m_logSizeLimit;
82 mutable QMutex m_rollingMutex;
83};
84
85DCORE_END_NAMESPACE
86
87#endif // ROLLINGFILEAPPENDER_H
Simple appender that writes the log records to the plain text file.
Definition: FileAppender.h:28
virtual void append(const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, const QString &category, const QString &message)
Write the log record to the file. \reimp
Definition: FileAppender.cpp:104
LogLevel
Describes the possible severity levels of the log records
Definition: Logger.h:83
The RollingFileAppender class extends FileAppender so that the underlying file is rolled over at a us...
Definition: RollingFileAppender.h:28
DatePattern
Definition: RollingFileAppender.h:35
@ WeeklyRollover
Definition: RollingFileAppender.h:45
@ HourlyRollover
Definition: RollingFileAppender.h:39
@ DailyRollover
Definition: RollingFileAppender.h:43
@ HalfDailyRollover
Definition: RollingFileAppender.h:41