OFFIS DCMTK  Version 3.6.0
fileap.h
Go to the documentation of this file.
1 // Module: Log4CPLUS
2 // File: fileappender.h
3 // Created: 6/2001
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2001-2009 Tad E. Smith
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 
23 #ifndef _LOG4CPLUS_FILE_APPENDER_HEADER_
24 #define _LOG4CPLUS_FILE_APPENDER_HEADER_
25 
26 #include "dcmtk/oflog/config.h"
27 #include "dcmtk/oflog/appender.h"
28 #include "dcmtk/oflog/fstreams.h"
31 
32 #if defined(__DECCXX)
33 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::open_mode
34 #else
35 # define LOG4CPLUS_OPEN_MODE_TYPE LOG4CPLUS_FSTREAM_NAMESPACE::ios::openmode
36 #endif
37 
38 namespace log4cplus {
39 
64  class LOG4CPLUS_EXPORT FileAppender : public Appender {
65  public:
66  // Ctors
67  FileAppender(const log4cplus::tstring& filename,
68  LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc,
69  bool immediateFlush = true);
71  log4cplus::tstring& error,
72  LOG4CPLUS_OPEN_MODE_TYPE mode = LOG4CPLUS_FSTREAM_NAMESPACE::ios::trunc);
73 
74  // Dtor
75  virtual ~FileAppender();
76 
77  // Methods
78  virtual void close();
79 
80  protected:
81  virtual void append(const spi::InternalLoggingEvent& event);
82 
83  void open(LOG4CPLUS_OPEN_MODE_TYPE mode);
84  bool reopen();
85 
86  // Data
100 
109 
110  log4cplus::tofstream out;
111  log4cplus::tstring filename;
112 
113  log4cplus::helpers::Time reopen_time;
114 
115  private:
116  void init(const log4cplus::tstring& filename,
117  LOG4CPLUS_OPEN_MODE_TYPE mode);
118 
119  // Disallow copying of instances of this class
120  FileAppender(const FileAppender&);
121  FileAppender& operator=(const FileAppender&);
122  };
123 
124 
125 
146  class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
147  public:
148  // Ctors
149  RollingFileAppender(const log4cplus::tstring& filename,
150  long maxFileSize = 10*1024*1024, // 10 MB
151  int maxBackupIndex = 1,
152  bool immediateFlush = true);
154 
155  // Dtor
156  virtual ~RollingFileAppender();
157 
158  protected:
159  virtual void append(const spi::InternalLoggingEvent& event);
160  void rollover();
161 
162  // Data
163  long maxFileSize;
164  int maxBackupIndex;
165 
166  private:
167  void init(long maxFileSize, int maxBackupIndex);
168  };
169 
170 
171 
172  enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
173  TWICE_DAILY, HOURLY, MINUTELY};
174 
196  class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
197  public:
198  // Ctors
200  DailyRollingFileSchedule schedule = DAILY,
201  bool immediateFlush = true,
202  int maxBackupIndex = 10);
204 
205  // Dtor
206  virtual ~DailyRollingFileAppender();
207 
208  // Methods
209  virtual void close();
210 
211  protected:
212  virtual void append(const spi::InternalLoggingEvent& event);
213  void rollover();
214  log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
215  log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
216 
217  // Data
218  DailyRollingFileSchedule schedule;
219  log4cplus::tstring scheduledFilename;
220  log4cplus::helpers::Time nextRolloverTime;
221  int maxBackupIndex;
222 
223  private:
224  void init(DailyRollingFileSchedule schedule);
225  };
226 
227 } // end namespace log4cplus
228 
229 #endif // _LOG4CPLUS_FILE_APPENDER_HEADER_
230 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2