00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: rollingfileappender.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_ROLINGFILEAPPENDER_H 00026 #define LOG4QT_ROLINGFILEAPPENDER_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include "log4qt/fileappender.h" 00034 00035 00036 /****************************************************************************** 00037 * Declarations 00038 ******************************************************************************/ 00039 00040 namespace Log4Qt 00041 { 00042 00052 class RollingFileAppender : public FileAppender 00053 { 00054 Q_OBJECT 00055 00063 Q_PROPERTY(int maxBackupIndex READ maxBackupIndex WRITE setMaxBackupIndex) 00064 00065 00072 Q_PROPERTY(qint64 maximumFileSize READ maximumFileSize WRITE setMaximumFileSize) 00073 00079 Q_PROPERTY(QString maxFileSize WRITE setMaxFileSize) 00080 00081 public: 00082 RollingFileAppender(QObject *pParent = 0); 00083 RollingFileAppender(Layout *pLayout, 00084 const QString &rFileName, 00085 QObject *pParent = 0); 00086 RollingFileAppender(Layout *pLayout, 00087 const QString &rFileName, 00088 bool append, 00089 QObject *pParent = 0); 00090 virtual ~RollingFileAppender(); 00091 private: 00092 RollingFileAppender(const RollingFileAppender &rOther); // Not implemented 00093 RollingFileAppender &operator=(const RollingFileAppender &rOther); // Not implemented 00094 00095 public: 00096 int maxBackupIndex() const; 00097 qint64 maximumFileSize() const; 00098 void setMaxBackupIndex(int maxBackupIndex); 00099 void setMaximumFileSize(qint64 maximumFileSize); 00100 void setMaxFileSize(const QString &rMaxFileSize); 00101 00102 protected: 00103 virtual void append(const LoggingEvent &rEvent); 00104 00105 #ifndef QT_NO_DEBUG_STREAM 00106 00120 virtual QDebug debug(QDebug &rDebug) const; 00121 #endif // QT_NO_DEBUG_STREAM 00122 00123 private: 00124 void rollOver(); 00125 00126 private: 00127 int mMaxBackupIndex; 00128 qint64 mMaximumFileSize; 00129 }; 00130 00131 00132 /************************************************************************** 00133 * Operators, Helper 00134 **************************************************************************/ 00135 00136 00137 /************************************************************************** 00138 * Inline 00139 **************************************************************************/ 00140 00141 inline int RollingFileAppender::maxBackupIndex() const 00142 { QMutexLocker locker(&mObjectGuard); 00143 return mMaxBackupIndex; } 00144 00145 inline qint64 RollingFileAppender::maximumFileSize() const 00146 { QMutexLocker locker(&mObjectGuard); 00147 return mMaximumFileSize; } 00148 00149 inline void RollingFileAppender::setMaxBackupIndex(int maxBackupIndex) 00150 { QMutexLocker locker(&mObjectGuard); 00151 mMaxBackupIndex = maxBackupIndex; } 00152 00153 inline void RollingFileAppender::setMaximumFileSize(qint64 maximumFileSize) 00154 { QMutexLocker locker(&mObjectGuard); 00155 mMaximumFileSize = maximumFileSize; } 00156 00157 00158 } // namespace Log4Qt 00159 00160 00161 // Q_DECLARE_TYPEINFO(Log4Qt::RollingFileAppender, Q_COMPLEX_TYPE); // Use default 00162 00163 00164 #endif // LOG4QT_ROLINGFILEAPPENDER_H