00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00016 #ifndef _LOG4CPLUS_FILE_APPENDER_HEADER_
00017 #define _LOG4CPLUS_FILE_APPENDER_HEADER_
00018
00019 #include <log4cplus/config.h>
00020 #include <log4cplus/appender.h>
00021 #include <log4cplus/fstreams.h>
00022 #include <log4cplus/helpers/property.h>
00023
00024 #if defined(__DECCXX)
00025 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::open_mode
00026 #else
00027 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::openmode
00028 #endif
00029
00030 namespace log4cplus {
00031
00035 class LOG4CPLUS_EXPORT FileAppender : public Appender {
00036 public:
00037
00038 FileAppender(const log4cplus::tstring& filename,
00039 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc,
00040 bool immediateFlush = true);
00041 FileAppender(const log4cplus::helpers::Properties& properties,
00042 LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc);
00043
00044
00045 virtual ~FileAppender();
00046
00047
00048 virtual void close();
00049
00050 protected:
00051 virtual void append(const spi::InternalLoggingEvent& event);
00052
00053
00066 bool immediateFlush;
00067
00068 log4cplus::tofstream out;
00069 log4cplus::tstring filename;
00070
00071 private:
00072 void init(const log4cplus::tstring& filename,
00073 LOG4CPLUS_OPEN_MODE_TYPE mode);
00074
00075
00076 FileAppender(const FileAppender&);
00077 FileAppender& operator=(const FileAppender&);
00078 };
00079
00080
00081
00086 class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
00087 public:
00088
00089 RollingFileAppender(const log4cplus::tstring& filename,
00090 long maxFileSize = 10*1024*1024,
00091 int maxBackupIndex = 1,
00092 bool immediateFlush = true);
00093 RollingFileAppender(const log4cplus::helpers::Properties& properties);
00094
00095
00096 virtual ~RollingFileAppender();
00097
00098 protected:
00099 virtual void append(const spi::InternalLoggingEvent& event);
00100 void rollover();
00101
00102
00103 long maxFileSize;
00104 int maxBackupIndex;
00105
00106 private:
00107 void init(long maxFileSize, int maxBackupIndex);
00108 };
00109
00110
00111
00112 enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
00113 TWICE_DAILY, HOURLY, MINUTELY};
00114
00122 class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
00123 public:
00124
00125 DailyRollingFileAppender(const log4cplus::tstring& filename,
00126 DailyRollingFileSchedule schedule = DAILY,
00127 bool immediateFlush = true,
00128 int maxBackupIndex = 10);
00129 DailyRollingFileAppender(const log4cplus::helpers::Properties& properties);
00130
00131
00132 virtual ~DailyRollingFileAppender();
00133
00134
00135 virtual void close();
00136
00137 protected:
00138 virtual void append(const spi::InternalLoggingEvent& event);
00139 void rollover();
00140 log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
00141 log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
00142
00143
00144 DailyRollingFileSchedule schedule;
00145 log4cplus::tstring scheduledFilename;
00146 log4cplus::helpers::Time nextRolloverTime;
00147 int maxBackupIndex;
00148
00149 private:
00150 void init(DailyRollingFileSchedule schedule);
00151 };
00152
00153 }
00154
00155 #endif // _LOG4CPLUS_FILE_APPENDER_HEADER_
00156