00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00023 #ifndef _LOG4CPLUS_FILE_APPENDER_HEADER_
00024 #define _LOG4CPLUS_FILE_APPENDER_HEADER_
00025
00026 #include "dcmtk/oflog/config.h"
00027 #include "dcmtk/oflog/appender.h"
00028 #include "dcmtk/oflog/fstreams.h"
00029 #include "dcmtk/oflog/helpers/property.h"
00030 #include "dcmtk/oflog/helpers/timehelp.h"
00031
00032 #if defined(__DECCXX)
00033 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::open_mode
00034 #else
00035 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::openmode
00036 #endif
00037
00038 namespace log4cplus {
00039
00064 class LOG4CPLUS_EXPORT FileAppender : public Appender {
00065 public:
00066
00067 FileAppender(const log4cplus::tstring& filename,
00068 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc,
00069 bool immediateFlush = true);
00070 FileAppender(const log4cplus::helpers::Properties& properties,
00071 log4cplus::tstring& error,
00072 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc);
00073
00074
00075 virtual ~FileAppender();
00076
00077
00078 virtual void close();
00079
00080 protected:
00081 virtual void append(const spi::InternalLoggingEvent& event);
00082
00083 void open(LOG4CPLUS_OPEN_MODE_TYPE mode);
00084 bool reopen();
00085
00086
00099 bool immediateFlush;
00100
00108 int reopenDelay;
00109
00110 log4cplus::tofstream out;
00111 log4cplus::tstring filename;
00112
00113 log4cplus::helpers::Time reopen_time;
00114
00115 private:
00116 void init(const log4cplus::tstring& filename,
00117 LOG4CPLUS_OPEN_MODE_TYPE mode);
00118
00119
00120 FileAppender(const FileAppender&);
00121 FileAppender& operator=(const FileAppender&);
00122 };
00123
00124
00125
00146 class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
00147 public:
00148
00149 RollingFileAppender(const log4cplus::tstring& filename,
00150 long maxFileSize = 10*1024*1024,
00151 int maxBackupIndex = 1,
00152 bool immediateFlush = true);
00153 RollingFileAppender(const log4cplus::helpers::Properties& properties, log4cplus::tstring& error);
00154
00155
00156 virtual ~RollingFileAppender();
00157
00158 protected:
00159 virtual void append(const spi::InternalLoggingEvent& event);
00160 void rollover();
00161
00162
00163 long maxFileSize;
00164 int maxBackupIndex;
00165
00166 private:
00167 void init(long maxFileSize, int maxBackupIndex);
00168 };
00169
00170
00171
00172 enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
00173 TWICE_DAILY, HOURLY, MINUTELY};
00174
00196 class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
00197 public:
00198
00199 DailyRollingFileAppender(const log4cplus::tstring& filename,
00200 DailyRollingFileSchedule schedule = DAILY,
00201 bool immediateFlush = true,
00202 int maxBackupIndex = 10);
00203 DailyRollingFileAppender(const log4cplus::helpers::Properties& properties, log4cplus::tstring& error);
00204
00205
00206 virtual ~DailyRollingFileAppender();
00207
00208
00209 virtual void close();
00210
00211 protected:
00212 virtual void append(const spi::InternalLoggingEvent& event);
00213 void rollover();
00214 log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
00215 log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
00216
00217
00218 DailyRollingFileSchedule schedule;
00219 log4cplus::tstring scheduledFilename;
00220 log4cplus::helpers::Time nextRolloverTime;
00221 int maxBackupIndex;
00222
00223 private:
00224 void init(DailyRollingFileSchedule schedule);
00225 };
00226
00227 }
00228
00229 #endif // _LOG4CPLUS_FILE_APPENDER_HEADER_
00230