log4cplus 2.0.8
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
42namespace 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
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:
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:
402 void open(std::ios_base::openmode mode);
403 void close();
404 void rollover(bool alreadyLocked = false);
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_
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user ch...
Definition: fileappender.h:311
void rollover(bool alreadyLocked=false)
DailyRollingFileAppender(const log4cplus::helpers::Properties &properties)
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::tstring getFilename(const log4cplus::helpers::Time &t) const
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())
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time &t) const
DailyRollingFileSchedule schedule
Definition: fileappender.h:336
log4cplus::helpers::Time nextRolloverTime
Definition: fileappender.h:338
log4cplus::tstring scheduledFilename
Definition: fileappender.h:337
Base class for Appenders writing log events to a file.
Definition: fileappender.h:117
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::helpers::Time reopen_time
Definition: fileappender.h:186
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::tstring lockFileName
Definition: fileappender.h:183
bool createDirs
When this variable is true, FileAppender will try to create missing directories in path leading to lo...
Definition: fileappender.h:166
virtual std::locale imbue(std::locale const &loc)
Redefine default locale for output stream.
std::ios_base::openmode fileOpenMode
Definition: fileappender.h:184
log4cplus::tofstream out
Definition: fileappender.h:180
log4cplus::tstring filename
Definition: fileappender.h:181
virtual void open(std::ios_base::openmode mode)
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::tstring localeName
Definition: fileappender.h:182
FileAppenderBase(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
std::unique_ptr< log4cplus::tchar[]> buffer
Definition: fileappender.h:178
FileAppenderBase(const log4cplus::tstring &filename, std::ios_base::openmode mode=std::ios_base::trunc, bool immediateFlush=true, bool createDirs=false)
virtual std::locale getloc() const
Appends log events to a file.
Definition: fileappender.h:201
FileAppender(const log4cplus::tstring &filename, std::ios_base::openmode mode=std::ios_base::trunc, bool immediateFlush=true, bool createDirs=false)
FileAppender(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size.
Definition: fileappender.h:242
RollingFileAppender(const log4cplus::helpers::Properties &properties)
void rollover(bool alreadyLocked=false)
RollingFileAppender(const log4cplus::tstring &filename, long maxFileSize=10 *1024 *1024, int maxBackupIndex=1, bool immediateFlush=true, bool createDirs=false)
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
TimeBasedRollingFileAppender extends FileAppenderBase so that the underlying file is rolled over at a...
Definition: fileappender.h:385
TimeBasedRollingFileAppender(const helpers::Properties &properties)
log4cplus::helpers::Time lastHeartBeat
Definition: fileappender.h:415
void close()
Release any resources allocated within the appender such as file handles, network connections,...
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)
void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::helpers::Time nextRolloverTime
Definition: fileappender.h:416
DailyRollingFileSchedule schedule
Definition: fileappender.h:411
void open(std::ios_base::openmode mode)
helpers::Time calculateNextRolloverTime(const helpers::Time &t) const
void rollover(bool alreadyLocked=false)
helpers::Time::duration getRolloverPeriodDuration() const
The internal representation of logging events.
Definition: loggingevent.h:51
#define LOG4CPLUS_TEXT(STRING)
Definition: clogger.h:72
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
chrono::time_point< Clock, Duration > Time
Definition: timehelper.h:54
helpers::SharedObjectPtr< RollingFileAppender > SharedRollingFileAppenderPtr
Definition: fileappender.h:269
helpers::SharedObjectPtr< DailyRollingFileAppender > SharedDailyRollingFileAppenderPtr
Definition: fileappender.h:348
std::basic_ofstream< tchar > tofstream
Definition: fstreams.h:41
helpers::SharedObjectPtr< TimeBasedRollingFileAppender > SharedTimeBasedRollingFileAppenderPtr
Definition: fileappender.h:424
std::basic_string< tchar > tstring
Definition: tstring.h:39
DailyRollingFileSchedule
Definition: fileappender.h:272
helpers::SharedObjectPtr< FileAppender > SharedFileAppenderPtr
Definition: fileappender.h:218
#define LOG4CPLUS_EXPORT
Definition: win32.h:141