00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: dailyrollingfileappender.h 00005 * created: September 2007 00006 * author: Martin Heinrich 00007 * 00008 * 00009 * Copyright 2007 Martin Heinrich 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 * 00023 ******************************************************************************/ 00024 00025 #ifndef LOG4QT_DAILYROLLINGFILEAPPENDER_H 00026 #define LOG4QT_DAILYROLLINGFILEAPPENDER_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include "log4qt/fileappender.h" 00034 00035 #include <QtCore/QDateTime> 00036 00037 00038 /****************************************************************************** 00039 * Declarations 00040 ******************************************************************************/ 00041 00042 namespace Log4Qt 00043 { 00044 00054 class DailyRollingFileAppender : public FileAppender 00055 { 00056 Q_OBJECT 00057 00065 Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern) 00066 00067 public: 00073 enum DatePattern 00074 { 00076 MINUTELY_ROLLOVER = 0, 00078 HOURLY_ROLLOVER, 00080 HALFDAILY_ROLLOVER, 00082 DAILY_ROLLOVER, 00084 WEEKLY_ROLLOVER, 00086 MONTHLY_ROLLOVER 00087 }; 00088 Q_ENUMS(DatePattern) 00089 00090 DailyRollingFileAppender(QObject *pParent = 0); 00091 DailyRollingFileAppender(Layout *pLayout, 00092 const QString &rFileName, 00093 const QString &rDatePattern, 00094 QObject *pParent = 0); 00095 virtual ~DailyRollingFileAppender(); 00096 private: 00097 DailyRollingFileAppender(const DailyRollingFileAppender &rOther); // Not implemented 00098 DailyRollingFileAppender &operator=(const DailyRollingFileAppender &rOther); // Not implemented 00099 00100 public: 00101 QString datePattern() const; 00102 00107 void setDatePattern(DatePattern datePattern); 00108 00109 void setDatePattern(const QString &rDatePattern); 00110 00111 virtual void activateOptions(); 00112 00113 protected: 00114 virtual void append(const LoggingEvent &rEvent); 00115 00133 virtual bool checkEntryConditions() const; 00134 00135 protected: 00136 #ifndef QT_NO_DEBUG_STREAM 00137 00154 virtual QDebug debug(QDebug &rDebug) const; 00155 #endif // QT_NO_DEBUG_STREAM 00156 00157 private: 00158 void computeFrequency(); 00159 void computeRollOverTime(); 00160 QString frequencyToString() const; 00161 void rollOver(); 00162 00163 private: 00164 QString mDatePattern; 00165 DatePattern mFrequency; 00166 QString mActiveDatePattern; 00167 QDateTime mRollOverTime; 00168 QString mRollOverSuffix; 00169 }; 00170 00171 00172 /************************************************************************** 00173 * Operators, Helper 00174 **************************************************************************/ 00175 00176 00177 /************************************************************************** 00178 * Inline 00179 **************************************************************************/ 00180 00181 inline QString DailyRollingFileAppender::datePattern() const 00182 { QMutexLocker locker(&mObjectGuard); 00183 return mDatePattern; } 00184 00185 inline void DailyRollingFileAppender::setDatePattern(const QString &rDatePattern) 00186 { QMutexLocker locker(&mObjectGuard); 00187 mDatePattern = rDatePattern; } 00188 00189 00190 } // namespace Log4Qt 00191 00192 00193 // Q_DECLARE_TYPEINFO(Log4Qt::DailyRollingFileAppender, Q_COMPLEX_TYPE); // Use default 00194 00195 00196 #endif // LOG4QT_DAILYROLLINGFILEAPPENDER_H