00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef LOG4QT_FILEAPPENDER_H
00026 #define LOG4QT_FILEAPPENDER_H
00027
00028
00029
00030
00031
00032
00033 #include "log4qt/writerappender.h"
00034
00035
00036
00037
00038
00039
00040 class QFile;
00041 class QTextStream;
00042
00043 namespace Log4Qt
00044 {
00045
00054 class FileAppender : public WriterAppender
00055 {
00056 Q_OBJECT
00057
00065 Q_PROPERTY(bool appendFile READ appendFile WRITE setAppendFile)
00066
00067
00074 Q_PROPERTY(bool bufferedIo READ bufferedIo WRITE setBufferedIo)
00075
00081 Q_PROPERTY(QString file READ file WRITE setFile)
00082
00083 public:
00084 FileAppender(QObject *pParent = 0);
00085 FileAppender(Layout *pLayout,
00086 const QString &rFileName,
00087 QObject *pParent = 0);
00088 FileAppender(Layout *pLayout,
00089 const QString &rFileName,
00090 bool append,
00091 QObject *pParent = 0);
00092 FileAppender(Layout *pLayout,
00093 const QString &rFileName,
00094 bool append,
00095 bool buffered,
00096 QObject *pParent = 0);
00097 virtual ~FileAppender();
00098 private:
00099 FileAppender(const FileAppender &rOther);
00100 FileAppender &operator=(const FileAppender &rOther);
00101
00102 public:
00103 bool appendFile() const;
00104 QString file() const;
00105 bool bufferedIo() const;
00106
00107 void setAppendFile(bool append);
00108 void setBufferedIo(bool buffered);
00109
00110 void setFile(const QString &rFileName);
00111
00112 virtual void activateOptions();
00113 virtual void close();
00114
00115 protected:
00131 virtual bool checkEntryConditions() const;
00132
00133 void closeFile();
00134
00135 #ifndef QT_NO_DEBUG_STREAM
00136
00148 virtual QDebug debug(QDebug &rDebug) const;
00149 #endif // QT_NO_DEBUG_STREAM
00150
00155 virtual bool handleIoErrors() const;
00156
00165 void openFile();
00166
00172 bool removeFile(QFile &rFile) const;
00173
00179 bool renameFile(QFile &rFile,
00180 const QString &rFileName) const;
00181
00182
00183
00184 private:
00185 volatile bool mAppendFile;
00186 volatile bool mBufferedIo;
00187 QString mFileName;
00188 QFile *mpFile;
00189 QTextStream *mpTextStream;
00190 };
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 inline bool FileAppender::appendFile() const
00203 {
00204 return mAppendFile; }
00205
00206 inline QString FileAppender::file() const
00207 { QMutexLocker locker(&mObjectGuard);
00208 return mFileName; }
00209
00210 inline bool FileAppender::bufferedIo() const
00211 {
00212 return mBufferedIo; }
00213
00214 inline void FileAppender::setAppendFile(bool append)
00215 {
00216 mAppendFile = append; }
00217
00218 inline void FileAppender::setBufferedIo(bool buffered)
00219 {
00220 mBufferedIo = buffered; }
00221
00222 inline void FileAppender::setFile(const QString &rFileName)
00223 { QMutexLocker locker(&mObjectGuard);
00224 mFileName = rFileName; }
00225
00226
00227 }
00228
00229
00230
00231
00232
00233 #endif // LOG4QT_FILEAPPENDER_H