Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

fileappender.h

Go to the documentation of this file.
00001 // Module:  Log4CPLUS
00002 // File:    fileappender.h
00003 // Created: 6/2001
00004 // Author:  Tad E. Smith
00005 //
00006 //
00007 // Copyright (C) Tad E. Smith  All rights reserved.
00008 //
00009 // This software is published under the terms of the Apache Software
00010 // License version 1.1, a copy of which has been included with this
00011 // distribution in the LICENSE.APL file.
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       // Ctors
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       // Dtor
00045         virtual ~FileAppender();
00046 
00047       // Methods
00048         virtual void close();
00049 
00050     protected:
00051         virtual void append(const spi::InternalLoggingEvent& event);
00052 
00053       // Data
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       // Disallow copying of instances of this class
00076         FileAppender(const FileAppender&);
00077         FileAppender& operator=(const FileAppender&);
00078     };
00079 
00080 
00081 
00086     class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
00087     public:
00088       // Ctors
00089         RollingFileAppender(const log4cplus::tstring& filename,
00090                             long maxFileSize = 10*1024*1024, // 10 MB
00091                             int maxBackupIndex = 1,
00092                             bool immediateFlush = true);
00093         RollingFileAppender(const log4cplus::helpers::Properties& properties);
00094 
00095       // Dtor
00096         virtual ~RollingFileAppender();
00097 
00098     protected:
00099         virtual void append(const spi::InternalLoggingEvent& event);
00100         void rollover();
00101 
00102       // Data
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       // Ctors
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       // Dtor
00132         virtual ~DailyRollingFileAppender();
00133         
00134       // Methods
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       // Data
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 } // end namespace log4cplus
00154 
00155 #endif // _LOG4CPLUS_FILE_APPENDER_HEADER_
00156 

Generated on Mon Feb 9 09:10:30 2004 for log4cplus by doxygen 1.3.2