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
00069 class LOG4CPLUS_EXPORT FileAppender : public Appender {
00070 public:
00071
00072 FileAppender(const log4cplus::tstring& filename,
00073 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc,
00074 bool immediateFlush = true);
00075 FileAppender(const log4cplus::helpers::Properties& properties,
00076 log4cplus::tstring& error,
00077 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc);
00078
00079
00080 virtual ~FileAppender();
00081
00082
00083 virtual void close();
00084
00085 protected:
00086 virtual void append(const spi::InternalLoggingEvent& event);
00087
00088 void open(LOG4CPLUS_OPEN_MODE_TYPE mode);
00089 bool reopen();
00090
00091
00104 bool immediateFlush;
00105
00113 int reopenDelay;
00114
00115 unsigned long bufferSize;
00116 log4cplus::tchar * buffer;
00117
00118 log4cplus::tofstream out;
00119 log4cplus::tstring filename;
00120
00121 log4cplus::helpers::Time reopen_time;
00122
00123 private:
00124 void init(const log4cplus::tstring& filename,
00125 LOG4CPLUS_OPEN_MODE_TYPE mode);
00126
00127
00128 FileAppender(const FileAppender&);
00129 FileAppender& operator=(const FileAppender&);
00130 };
00131
00132
00133
00154 class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
00155 public:
00156
00157 RollingFileAppender(const log4cplus::tstring& filename,
00158 long maxFileSize = 10*1024*1024,
00159 int maxBackupIndex = 1,
00160 bool immediateFlush = true);
00161 RollingFileAppender(const log4cplus::helpers::Properties& properties, log4cplus::tstring& error);
00162
00163
00164 virtual ~RollingFileAppender();
00165
00166 protected:
00167 virtual void append(const spi::InternalLoggingEvent& event);
00168 void rollover();
00169
00170
00171 long maxFileSize;
00172 int maxBackupIndex;
00173
00174 private:
00175 void init(long maxFileSize, int maxBackupIndex);
00176 };
00177
00178
00179
00180 enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
00181 TWICE_DAILY, HOURLY, MINUTELY};
00182
00204 class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
00205 public:
00206
00207 DailyRollingFileAppender(const log4cplus::tstring& filename,
00208 DailyRollingFileSchedule schedule = DAILY,
00209 bool immediateFlush = true,
00210 int maxBackupIndex = 10);
00211 DailyRollingFileAppender(const log4cplus::helpers::Properties& properties, log4cplus::tstring& error);
00212
00213
00214 virtual ~DailyRollingFileAppender();
00215
00216
00217 virtual void close();
00218
00219 protected:
00220 virtual void append(const spi::InternalLoggingEvent& event);
00221 void rollover();
00222 log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
00223 log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
00224
00225
00226 DailyRollingFileSchedule schedule;
00227 log4cplus::tstring scheduledFilename;
00228 log4cplus::helpers::Time nextRolloverTime;
00229 int maxBackupIndex;
00230
00231 private:
00232 void init(DailyRollingFileSchedule schedule);
00233 };
00234
00235 }
00236
00237 #endif // _LOG4CPLUS_FILE_APPENDER_HEADER_
00238