fileappender.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: fileappender.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_FILE_APPENDER_HEADER_
#define LOG4CPLUS_FILE_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/appender.h>
#include <log4cplus/fstreams.h>
#include <log4cplus/helpers/timehelper.h>
#include <log4cplus/helpers/lockfile.h>
#include <fstream>
#include <locale>
#include <memory>
namespace log4cplus
{
class LOG4CPLUS_EXPORT FileAppenderBase : public Appender {
public:
// Methods
virtual void close();
virtual std::locale imbue(std::locale const& loc);
virtual std::locale getloc () const;
protected:
// Ctors
FileAppenderBase(const log4cplus::tstring& filename,
std::ios_base::openmode mode = std::ios_base::trunc,
bool immediateFlush = true,
bool createDirs = false);
FileAppenderBase(const log4cplus::helpers::Properties& properties,
std::ios_base::openmode mode = std::ios_base::trunc);
void init();
virtual void append(const spi::InternalLoggingEvent& event);
virtual void open(std::ios_base::openmode mode);
bool reopen();
// Data
bool immediateFlush;
bool createDirs;
int reopenDelay;
unsigned long bufferSize;
std::unique_ptr<log4cplus::tchar[]> buffer;
log4cplus::tofstream out;
log4cplus::tstring filename;
log4cplus::tstring localeName;
log4cplus::tstring lockFileName;
std::ios_base::openmode fileOpenMode;
log4cplus::helpers::Time reopen_time;
private:
// Disallow copying of instances of this class
FileAppenderBase(const FileAppenderBase&);
FileAppenderBase& operator=(const FileAppenderBase&);
};
class LOG4CPLUS_EXPORT FileAppender : public FileAppenderBase {
public:
// Ctors
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);
// Dtor
virtual ~FileAppender();
protected:
void init();
};
typedef helpers::SharedObjectPtr<FileAppender> SharedFileAppenderPtr;
class LOG4CPLUS_EXPORT RollingFileAppender : public FileAppender {
public:
// Ctors
RollingFileAppender(const log4cplus::tstring& filename,
long maxFileSize = 10*1024*1024, // 10 MB
int maxBackupIndex = 1,
bool immediateFlush = true,
bool createDirs = false);
RollingFileAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~RollingFileAppender();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
void rollover(bool alreadyLocked = false);
// Data
long maxFileSize;
int maxBackupIndex;
private:
LOG4CPLUS_PRIVATE void init(long maxFileSize, int maxBackupIndex);
};
typedef helpers::SharedObjectPtr<RollingFileAppender>
SharedRollingFileAppenderPtr;
enum DailyRollingFileSchedule { MONTHLY, WEEKLY, DAILY,
TWICE_DAILY, HOURLY, MINUTELY};
class LOG4CPLUS_EXPORT DailyRollingFileAppender : public FileAppender {
public:
// Ctors
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());
DailyRollingFileAppender(const log4cplus::helpers::Properties& properties);
// Dtor
virtual ~DailyRollingFileAppender();
// Methods
virtual void close();
protected:
virtual void append(const spi::InternalLoggingEvent& event);
void rollover(bool alreadyLocked = false);
log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time& t) const;
log4cplus::tstring getFilename(const log4cplus::helpers::Time& t) const;
// Data
DailyRollingFileSchedule schedule;
log4cplus::tstring scheduledFilename;
log4cplus::helpers::Time nextRolloverTime;
int maxBackupIndex;
bool rollOnClose;
log4cplus::tstring datePattern;
private:
LOG4CPLUS_PRIVATE void init(DailyRollingFileSchedule schedule);
};
typedef helpers::SharedObjectPtr<DailyRollingFileAppender>
SharedDailyRollingFileAppenderPtr;
class LOG4CPLUS_EXPORT TimeBasedRollingFileAppender : public FileAppenderBase {
public:
// Ctors
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);
TimeBasedRollingFileAppender(const helpers::Properties& properties);
// Dtor
~TimeBasedRollingFileAppender();
protected:
void append(const spi::InternalLoggingEvent& event);
void open(std::ios_base::openmode mode);
void close();
void rollover(bool alreadyLocked = false);
void clean(helpers::Time time);
helpers::Time::duration getRolloverPeriodDuration() const;
helpers::Time calculateNextRolloverTime(const helpers::Time& t) const;
// Data
tstring filenamePattern;
DailyRollingFileSchedule schedule;
tstring scheduledFilename;
int maxHistory;
bool cleanHistoryOnStart;
log4cplus::helpers::Time lastHeartBeat;
log4cplus::helpers::Time nextRolloverTime;
bool rollOnClose;
private:
LOG4CPLUS_PRIVATE void init();
};
typedef helpers::SharedObjectPtr<TimeBasedRollingFileAppender>
SharedTimeBasedRollingFileAppenderPtr;
} // end namespace log4cplus
#endif // LOG4CPLUS_FILE_APPENDER_HEADER_
appender.h
log4cplus::Appender::Appender
Appender()
log4cplus::DailyRollingFileAppender::~DailyRollingFileAppender
virtual ~DailyRollingFileAppender()
log4cplus::DailyRollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::DailyRollingFileAppender::DailyRollingFileAppender
DailyRollingFileAppender(const log4cplus::helpers::Properties &properties)
log4cplus::DailyRollingFileAppender::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::DailyRollingFileAppender::getFilename
log4cplus::tstring getFilename(const log4cplus::helpers::Time &t) const
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::DailyRollingFileAppender::datePattern
log4cplus::tstring datePattern
Definition fileappender.h:341
log4cplus::DailyRollingFileAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::DailyRollingFileAppender::rollOnClose
bool rollOnClose
Definition fileappender.h:340
log4cplus::DailyRollingFileAppender::calculateNextRolloverTime
log4cplus::helpers::Time calculateNextRolloverTime(const log4cplus::helpers::Time &t) const
log4cplus::DailyRollingFileAppender::schedule
DailyRollingFileSchedule schedule
Definition fileappender.h:336
log4cplus::DailyRollingFileAppender::nextRolloverTime
log4cplus::helpers::Time nextRolloverTime
Definition fileappender.h:338
log4cplus::DailyRollingFileAppender::scheduledFilename
log4cplus::tstring scheduledFilename
Definition fileappender.h:337
log4cplus::DailyRollingFileAppender::maxBackupIndex
int maxBackupIndex
Definition fileappender.h:339
log4cplus::FileAppenderBase::bufferSize
unsigned long bufferSize
Definition fileappender.h:177
log4cplus::FileAppenderBase::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::FileAppenderBase::reopen_time
log4cplus::helpers::Time reopen_time
Definition fileappender.h:186
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::FileAppenderBase::lockFileName
log4cplus::tstring lockFileName
Definition fileappender.h:183
log4cplus::FileAppenderBase::init
void init()
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::imbue
virtual std::locale imbue(std::locale const &loc)
log4cplus::FileAppenderBase::fileOpenMode
std::ios_base::openmode fileOpenMode
Definition fileappender.h:184
log4cplus::FileAppenderBase::out
log4cplus::tofstream out
Definition fileappender.h:180
log4cplus::FileAppenderBase::filename
log4cplus::tstring filename
Definition fileappender.h:181
log4cplus::FileAppenderBase::open
virtual void open(std::ios_base::openmode mode)
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::FileAppenderBase::localeName
log4cplus::tstring localeName
Definition fileappender.h:182
log4cplus::FileAppenderBase::FileAppenderBase
FileAppenderBase(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
log4cplus::FileAppenderBase::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::FileAppenderBase::reopen
bool reopen()
log4cplus::FileAppenderBase::buffer
std::unique_ptr< log4cplus::tchar[]> buffer
Definition fileappender.h:178
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::getloc
virtual std::locale getloc() const
log4cplus::FileAppender::~FileAppender
virtual ~FileAppender()
log4cplus::FileAppender::FileAppender
FileAppender(const log4cplus::tstring &filename, std::ios_base::openmode mode=std::ios_base::trunc, bool immediateFlush=true, bool createDirs=false)
log4cplus::FileAppender::init
void init()
log4cplus::FileAppender::FileAppender
FileAppender(const log4cplus::helpers::Properties &properties, std::ios_base::openmode mode=std::ios_base::trunc)
log4cplus::RollingFileAppender::maxBackupIndex
int maxBackupIndex
Definition fileappender.h:261
log4cplus::RollingFileAppender::RollingFileAppender
RollingFileAppender(const log4cplus::helpers::Properties &properties)
log4cplus::RollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::RollingFileAppender::RollingFileAppender
RollingFileAppender(const log4cplus::tstring &filename, long maxFileSize=10 *1024 *1024, int maxBackupIndex=1, bool immediateFlush=true, bool createDirs=false)
log4cplus::RollingFileAppender::maxFileSize
long maxFileSize
Definition fileappender.h:260
log4cplus::RollingFileAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::RollingFileAppender::~RollingFileAppender
virtual ~RollingFileAppender()
log4cplus::TimeBasedRollingFileAppender::TimeBasedRollingFileAppender
TimeBasedRollingFileAppender(const helpers::Properties &properties)
log4cplus::TimeBasedRollingFileAppender::lastHeartBeat
log4cplus::helpers::Time lastHeartBeat
Definition fileappender.h:415
log4cplus::TimeBasedRollingFileAppender::close
void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::TimeBasedRollingFileAppender::cleanHistoryOnStart
bool cleanHistoryOnStart
Definition fileappender.h:414
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::TimeBasedRollingFileAppender::rollOnClose
bool rollOnClose
Definition fileappender.h:417
log4cplus::TimeBasedRollingFileAppender::append
void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::TimeBasedRollingFileAppender::filenamePattern
tstring filenamePattern
Definition fileappender.h:410
log4cplus::TimeBasedRollingFileAppender::nextRolloverTime
log4cplus::helpers::Time nextRolloverTime
Definition fileappender.h:416
log4cplus::TimeBasedRollingFileAppender::scheduledFilename
tstring scheduledFilename
Definition fileappender.h:412
log4cplus::TimeBasedRollingFileAppender::maxHistory
int maxHistory
Definition fileappender.h:413
log4cplus::TimeBasedRollingFileAppender::schedule
DailyRollingFileSchedule schedule
Definition fileappender.h:411
log4cplus::TimeBasedRollingFileAppender::open
void open(std::ios_base::openmode mode)
log4cplus::TimeBasedRollingFileAppender::~TimeBasedRollingFileAppender
~TimeBasedRollingFileAppender()
log4cplus::TimeBasedRollingFileAppender::clean
void clean(helpers::Time time)
log4cplus::TimeBasedRollingFileAppender::calculateNextRolloverTime
helpers::Time calculateNextRolloverTime(const helpers::Time &t) const
log4cplus::TimeBasedRollingFileAppender::rollover
void rollover(bool alreadyLocked=false)
log4cplus::TimeBasedRollingFileAppender::getRolloverPeriodDuration
helpers::Time::duration getRolloverPeriodDuration() const
log4cplus::helpers::Properties
Definition property.h:43
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
LOG4CPLUS_TEXT
#define LOG4CPLUS_TEXT(STRING)
Definition clogger.h:72
config.hxx
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition config.hxx:53
fstreams.h
lockfile.h
log4cplus::helpers::Time
chrono::time_point< Clock, Duration > Time
Definition timehelper.h:54
log4cplus
Definition appender.h:46
log4cplus::SharedRollingFileAppenderPtr
helpers::SharedObjectPtr< RollingFileAppender > SharedRollingFileAppenderPtr
Definition fileappender.h:269
log4cplus::SharedDailyRollingFileAppenderPtr
helpers::SharedObjectPtr< DailyRollingFileAppender > SharedDailyRollingFileAppenderPtr
Definition fileappender.h:348
log4cplus::tofstream
std::basic_ofstream< tchar > tofstream
Definition fstreams.h:41
log4cplus::SharedTimeBasedRollingFileAppenderPtr
helpers::SharedObjectPtr< TimeBasedRollingFileAppender > SharedTimeBasedRollingFileAppenderPtr
Definition fileappender.h:424
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::DailyRollingFileSchedule
DailyRollingFileSchedule
Definition fileappender.h:272
log4cplus::MONTHLY
@ MONTHLY
Definition fileappender.h:272
log4cplus::DAILY
@ DAILY
Definition fileappender.h:272
log4cplus::WEEKLY
@ WEEKLY
Definition fileappender.h:272
log4cplus::TWICE_DAILY
@ TWICE_DAILY
Definition fileappender.h:273
log4cplus::MINUTELY
@ MINUTELY
Definition fileappender.h:273
log4cplus::HOURLY
@ HOURLY
Definition fileappender.h:273
log4cplus::SharedFileAppenderPtr
helpers::SharedObjectPtr< FileAppender > SharedFileAppenderPtr
Definition fileappender.h:218
timehelper.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141