log4cplus  2.0.5
fileappender.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: fileappender.h
4 // Created: 6/2001
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2001-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_FILE_APPENDER_HEADER_
25 #define LOG4CPLUS_FILE_APPENDER_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/appender.h>
34 #include <log4cplus/fstreams.h>
37 #include <fstream>
38 #include <locale>
39 #include <memory>
40 
41 
42 namespace log4cplus
43 {
44 
118  public:
119  // Methods
120  virtual void close();
121 
124  virtual std::locale imbue(std::locale const& loc);
125 
127  virtual std::locale getloc () const;
128 
129  protected:
130  // Ctors
132  std::ios_base::openmode mode = std::ios_base::trunc,
133  bool immediateFlush = true,
134  bool createDirs = false);
136  std::ios_base::openmode mode = std::ios_base::trunc);
137 
138  void init();
139 
140  virtual void append(const spi::InternalLoggingEvent& event);
141 
142  virtual void open(std::ios_base::openmode mode);
143  bool reopen();
144 
145  // Data
159 
167 
176 
177  unsigned long bufferSize;
178  std::unique_ptr<log4cplus::tchar[]> buffer;
179 
184  std::ios_base::openmode fileOpenMode;
185 
187 
188  private:
189  // Disallow copying of instances of this class
191  FileAppenderBase& operator=(const FileAppenderBase&);
192  };
193 
194 
202  public:
203  // Ctors
205  std::ios_base::openmode mode = std::ios_base::trunc,
206  bool immediateFlush = true,
207  bool createDirs = false);
209  std::ios_base::openmode mode = std::ios_base::trunc);
210 
211  // Dtor
212  virtual ~FileAppender();
213 
214  protected:
215  void init();
216  };
217 
219 
220 
221 
243  public:
244  // Ctors
246  long maxFileSize = 10*1024*1024, // 10 MB
247  int maxBackupIndex = 1,
248  bool immediateFlush = true,
249  bool createDirs = false);
251 
252  // Dtor
254 
255  protected:
256  virtual void append(const spi::InternalLoggingEvent& event);
257  void rollover(bool alreadyLocked = false);
258 
259  // Data
262 
263  private:
264  LOG4CPLUS_PRIVATE void init(long maxFileSize, int maxBackupIndex);
265  };
266 
267 
270 
271 
274 
312  public:
313  // Ctors
315  DailyRollingFileSchedule schedule = DAILY,
316  bool immediateFlush = true,
317  int maxBackupIndex = 10,
318  bool createDirs = false,
319  bool rollOnClose = true,
320  const log4cplus::tstring& datePattern = log4cplus::tstring());
322 
323  // Dtor
325 
326  // Methods
327  virtual void close();
328 
329  protected:
330  virtual void append(const spi::InternalLoggingEvent& event);
331  void rollover(bool alreadyLocked = false);
334 
335  // Data
342 
343  private:
344  LOG4CPLUS_PRIVATE void init(DailyRollingFileSchedule schedule);
345  };
346 
349 
350 
386  public:
387  // Ctors
389  const tstring& filenamePattern = LOG4CPLUS_TEXT("%d.log"),
390  int maxHistory = 10,
391  bool cleanHistoryOnStart = false,
392  bool immediateFlush = true,
393  bool createDirs = false,
394  bool rollOnClose = true);
396 
397  // Dtor
399 
400  protected:
401  void append(const spi::InternalLoggingEvent& event);
402  void open(std::ios_base::openmode mode);
403  void close();
404  void rollover(bool alreadyLocked = false);
405  void clean(helpers::Time time);
406  helpers::Time::duration getRolloverPeriodDuration() const;
408 
409  // Data
418 
419  private:
420  LOG4CPLUS_PRIVATE void init();
421  };
422 
425 
426 } // end namespace log4cplus
427 
428 #endif // LOG4CPLUS_FILE_APPENDER_HEADER_
log4cplus::FileAppenderBase::bufferSize
unsigned long bufferSize
Definition: fileappender.h:177
log4cplus::DailyRollingFileAppender::DailyRollingFileAppender
DailyRollingFileAppender(const log4cplus::tstring &filename, DailyRollingFileSchedule schedule=DAILY, bool immediateFlush=true, int maxBackupIndex=10, bool createDirs=false, bool rollOnClose=true, const log4cplus::tstring &datePattern=log4cplus::tstring())
log4cplus::FileAppenderBase::open
virtual void open(std::ios_base::openmode mode)
log4cplus::SharedDailyRollingFileAppenderPtr
helpers::SharedObjectPtr< DailyRollingFileAppender > SharedDailyRollingFileAppenderPtr
Definition: fileappender.h:348
log4cplus::TimeBasedRollingFileAppender::cleanHistoryOnStart
bool cleanHistoryOnStart
Definition: fileappender.h:414
log4cplus::TimeBasedRollingFileAppender::calculateNextRolloverTime
helpers::Time calculateNextRolloverTime(const helpers::Time &t) const
log4cplus::FileAppenderBase
Base class for Appenders writing log events to a file.
Definition: fileappender.h:117
timehelper.h
log4cplus::SharedTimeBasedRollingFileAppenderPtr
helpers::SharedObjectPtr< TimeBasedRollingFileAppender > SharedTimeBasedRollingFileAppenderPtr
Definition: fileappender.h:424
log4cplus::RollingFileAppender::maxFileSize
long maxFileSize
Definition: fileappender.h:260
log4cplus
Definition: appender.h:46
log4cplus::FileAppenderBase::createDirs
bool createDirs
When this variable is true, FileAppender will try to create missing directories in path leading to lo...
Definition: fileappender.h:166
log4cplus::FileAppenderBase::buffer
std::unique_ptr< log4cplus::tchar[]> buffer
Definition: fileappender.h:178
log4cplus::TimeBasedRollingFileAppender::maxHistory
int maxHistory
Definition: fileappender.h:413
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::helpers::SharedObjectPtr
Definition: pointer.h:101
log4cplus::TimeBasedRollingFileAppender::close
void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::TimeBasedRollingFileAppender
TimeBasedRollingFileAppender extends FileAppenderBase so that the underlying file is rolled over at a...
Definition: fileappender.h:385
log4cplus::FileAppenderBase::init
void init()
log4cplus::RollingFileAppender::~RollingFileAppender
virtual ~RollingFileAppender()
log4cplus::DailyRollingFileAppender
DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user ch...
Definition: fileappender.h:311
log4cplus::FileAppender::~FileAppender
virtual ~FileAppender()
log4cplus::MONTHLY
@ MONTHLY
Definition: fileappender.h:272
log4cplus::RollingFileAppender::RollingFileAppender
RollingFileAppender(const log4cplus::helpers::Properties &properties)
log4cplus::TimeBasedRollingFileAppender::TimeBasedRollingFileAppender
TimeBasedRollingFileAppender(const helpers::Properties &properties)
LOG4CPLUS_TEXT
#define LOG4CPLUS_TEXT(STRING)
Definition: clogger.h:72
log4cplus::FileAppenderBase::lockFileName
log4cplus::tstring lockFileName
Definition: fileappender.h:183
lockfile.h
log4cplus::MINUTELY
@ MINUTELY
Definition: fileappender.h:273
log4cplus::TWICE_DAILY
@ TWICE_DAILY
Definition: fileappender.h:273
log4cplus::TimeBasedRollingFileAppender::rollOnClose
bool rollOnClose
Definition: fileappender.h:417
log4cplus::TimeBasedRollingFileAppender::scheduledFilename
tstring scheduledFilename
Definition: fileappender.h:412
log4cplus::RollingFileAppender::RollingFileAppender
RollingFileAppender(const log4cplus::tstring &filename, long maxFileSize=10 *1024 *1024, int maxBackupIndex=1, bool immediateFlush=true, bool createDirs=false)
log4cplus::FileAppenderBase::fileOpenMode
std::ios_base::openmode fileOpenMode
Definition: fileappender.h:184
log4cplus::TimeBasedRollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::DailyRollingFileAppender::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::FileAppender
Appends log events to a file.
Definition: fileappender.h:201
log4cplus::RollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::FileAppender::FileAppender
FileAppender(const log4cplus::tstring &filename, std::ios_base::openmode mode=std::ios_base::trunc, bool immediateFlush=true, bool createDirs=false)
log4cplus::WEEKLY
@ WEEKLY
Definition: fileappender.h:272
log4cplus::DailyRollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::FileAppenderBase::filename
log4cplus::tstring filename
Definition: fileappender.h:181
log4cplus::DailyRollingFileAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::TimeBasedRollingFileAppender::nextRolloverTime
log4cplus::helpers::Time nextRolloverTime
Definition: fileappender.h:416
config.hxx
log4cplus::helpers::Properties
Definition: property.h:43
log4cplus::FileAppenderBase::immediateFlush
bool immediateFlush
Immediate flush means that the underlying writer or output stream will be flushed at the end of each ...
Definition: fileappender.h:158
log4cplus::DailyRollingFileAppender::~DailyRollingFileAppender
virtual ~DailyRollingFileAppender()
log4cplus::RollingFileAppender::maxBackupIndex
int maxBackupIndex
Definition: fileappender.h:261
log4cplus::DailyRollingFileAppender::schedule
DailyRollingFileSchedule schedule
Definition: fileappender.h:336
log4cplus::DailyRollingFileAppender::rollOnClose
bool rollOnClose
Definition: fileappender.h:340
log4cplus::FileAppenderBase::FileAppenderBase
FileAppenderBase(const log4cplus::tstring &filename, std::ios_base::openmode mode=std::ios_base::trunc, bool immediateFlush=true, bool createDirs=false)
log4cplus::FileAppenderBase::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::FileAppender::init
void init()
log4cplus::DailyRollingFileAppender::datePattern
log4cplus::tstring datePattern
Definition: fileappender.h:341
log4cplus::TimeBasedRollingFileAppender::lastHeartBeat
log4cplus::helpers::Time lastHeartBeat
Definition: fileappender.h:415
log4cplus::FileAppenderBase::localeName
log4cplus::tstring localeName
Definition: fileappender.h:182
log4cplus::TimeBasedRollingFileAppender::clean
void clean(helpers::Time time)
log4cplus::DailyRollingFileAppender::nextRolloverTime
log4cplus::helpers::Time nextRolloverTime
Definition: fileappender.h:338
log4cplus::TimeBasedRollingFileAppender::TimeBasedRollingFileAppender
TimeBasedRollingFileAppender(const tstring &filename=LOG4CPLUS_TEXT(""), const tstring &filenamePattern=LOG4CPLUS_TEXT("%d.log"), int maxHistory=10, bool cleanHistoryOnStart=false, bool immediateFlush=true, bool createDirs=false, bool rollOnClose=true)
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
log4cplus::FileAppenderBase::reopenDelay
int reopenDelay
When any append operation fails, reopenDelay says for how many seconds the next attempt to re-open th...
Definition: fileappender.h:175
log4cplus::TimeBasedRollingFileAppender::open
void open(std::ios_base::openmode mode)
log4cplus::FileAppenderBase::reopen_time
log4cplus::helpers::Time reopen_time
Definition: fileappender.h:186
log4cplus::HOURLY
@ HOURLY
Definition: fileappender.h:273
log4cplus::DailyRollingFileAppender::scheduledFilename
log4cplus::tstring scheduledFilename
Definition: fileappender.h:337
log4cplus::DailyRollingFileAppender::getFilename
log4cplus::tstring getFilename(const log4cplus::helpers::Time &t) const
log4cplus::TimeBasedRollingFileAppender::append
void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::TimeBasedRollingFileAppender::getRolloverPeriodDuration
helpers::Time::duration getRolloverPeriodDuration() const
log4cplus::FileAppenderBase::getloc
virtual std::locale getloc() const
log4cplus::FileAppenderBase::reopen
bool reopen()
log4cplus::TimeBasedRollingFileAppender::schedule
DailyRollingFileSchedule schedule
Definition: fileappender.h:411
log4cplus::DailyRollingFileSchedule
DailyRollingFileSchedule
Definition: fileappender.h:272
log4cplus::FileAppenderBase::out
log4cplus::tofstream out
Definition: fileappender.h:180
log4cplus::DailyRollingFileAppender::maxBackupIndex
int maxBackupIndex
Definition: fileappender.h:339
log4cplus::FileAppenderBase::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::RollingFileAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::SharedRollingFileAppenderPtr
helpers::SharedObjectPtr< RollingFileAppender > SharedRollingFileAppenderPtr
Definition: fileappender.h:269
log4cplus::helpers::Time
chrono::time_point< Clock, Duration > Time
Definition: timehelper.h:54
log4cplus::tofstream
std::basic_ofstream< tchar > tofstream
Definition: fstreams.h:41
appender.h
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
log4cplus::Appender
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
log4cplus::RollingFileAppender
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.
Definition: fileappender.h:242
log4cplus::FileAppenderBase::imbue
virtual std::locale imbue(std::locale const &loc)
Redefine default locale for output stream.
log4cplus::SharedFileAppenderPtr
helpers::SharedObjectPtr< FileAppender > SharedFileAppenderPtr
Definition: fileappender.h:218
log4cplus::TimeBasedRollingFileAppender::~TimeBasedRollingFileAppender
~TimeBasedRollingFileAppender()
log4cplus::DailyRollingFileAppender::calculateNextRolloverTime
log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time &t) const
log4cplus::FileAppenderBase::FileAppenderBase
FileAppenderBase(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
log4cplus::TimeBasedRollingFileAppender::filenamePattern
tstring filenamePattern
Definition: fileappender.h:410
log4cplus::DAILY
@ DAILY
Definition: fileappender.h:272
log4cplus::FileAppender::FileAppender
FileAppender(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
log4cplus::DailyRollingFileAppender::DailyRollingFileAppender
DailyRollingFileAppender(const log4cplus::helpers::Properties &properties)
fstreams.h