appender.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: appender.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_APPENDER_HEADER_
#define LOG4CPLUS_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/layout.h>
#include <log4cplus/loglevel.h>
#include <log4cplus/tstring.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/spi/filter.h>
#include <log4cplus/helpers/lockfile.h>
#include <memory>
#include <mutex>
#include <atomic>
#include <condition_variable>
namespace log4cplus {
namespace helpers
{
class Properties;
}
class LOG4CPLUS_EXPORT ErrorHandler
{
public:
ErrorHandler ();
virtual ~ErrorHandler() = 0;
virtual void error(const log4cplus::tstring& err) = 0;
virtual void reset() = 0;
};
class LOG4CPLUS_EXPORT OnlyOnceErrorHandler
: public ErrorHandler
{
public:
// Ctor
OnlyOnceErrorHandler();
virtual ~OnlyOnceErrorHandler ();
virtual void error(const log4cplus::tstring& err);
virtual void reset();
private:
bool firstTime;
};
class LOG4CPLUS_EXPORT Appender
: public virtual log4cplus::helpers::SharedObject
{
public:
// Ctor
Appender();
Appender(const log4cplus::helpers::Properties & properties);
// Dtor
virtual ~Appender();
void destructorImpl();
// Methods
virtual void close() = 0;
bool isClosed() const;
void syncDoAppend(const log4cplus::spi::InternalLoggingEvent& event);
void asyncDoAppend(const log4cplus::spi::InternalLoggingEvent& event);
void doAppend(const log4cplus::spi::InternalLoggingEvent& event);
virtual log4cplus::tstring getName();
virtual void setName(const log4cplus::tstring& name);
virtual void setErrorHandler(std::unique_ptr<ErrorHandler> eh);
virtual ErrorHandler* getErrorHandler();
virtual void setLayout(std::unique_ptr<Layout> layout);
virtual Layout* getLayout();
void setFilter(log4cplus::spi::FilterPtr f);
log4cplus::spi::FilterPtr getFilter() const;
void addFilter (log4cplus::spi::FilterPtr f);
void addFilter (std::function<
spi::FilterResult (const log4cplus::spi::InternalLoggingEvent &)>);
LogLevel getThreshold() const { return threshold; }
void setThreshold(LogLevel th) { threshold = th; }
bool isAsSevereAsThreshold(LogLevel ll) const {
return ((ll != NOT_SET_LOG_LEVEL) && (ll >= threshold));
}
void waitToFinishAsyncLogging();
protected:
// Methods
virtual void append(const log4cplus::spi::InternalLoggingEvent& event) = 0;
tstring & formatEvent (const log4cplus::spi::InternalLoggingEvent& event) const;
// Data
std::unique_ptr<Layout> layout;
log4cplus::tstring name;
LogLevel threshold;
log4cplus::spi::FilterPtr filter;
std::unique_ptr<ErrorHandler> errorHandler;
std::unique_ptr<helpers::LockFile> lockFile;
bool useLockFile;
bool async;
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
std::atomic<std::size_t> in_flight;
std::mutex in_flight_mutex;
std::condition_variable in_flight_condition;
#endif
bool closed;
private:
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
void subtract_in_flight();
#endif
};
typedef helpers::SharedObjectPtr<Appender> SharedAppenderPtr;
} // end namespace log4cplus
#endif // LOG4CPLUS_APPENDER_HEADER_
log4cplus::Appender::in_flight_mutex
std::mutex in_flight_mutex
Definition appender.h:322
log4cplus::Appender::setThreshold
void setThreshold(LogLevel th)
Set the threshold LogLevel.
Definition appender.h:265
log4cplus::Appender::close
virtual void close()=0
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::Appender::in_flight
std::atomic< std::size_t > in_flight
Definition appender.h:321
log4cplus::Appender::asyncDoAppend
void asyncDoAppend(const log4cplus::spi::InternalLoggingEvent &event)
This method performs book keeping related to asynchronous logging and executes syncDoAppend() to do t...
log4cplus::Appender::isClosed
bool isClosed() const
Check if this appender is in closed state.
log4cplus::Appender::getThreshold
LogLevel getThreshold() const
Returns this appenders threshold LogLevel.
Definition appender.h:255
log4cplus::Appender::async
bool async
Asynchronous append.
Definition appender.h:319
log4cplus::Appender::getName
virtual log4cplus::tstring getName()
Get the name of this appender.
log4cplus::Appender::filter
log4cplus::spi::FilterPtr filter
The first filter in the filter chain.
Definition appender.h:306
log4cplus::Appender::addFilter
void addFilter(log4cplus::spi::FilterPtr f)
Add filter at the end of the filters chain.
log4cplus::Appender::syncDoAppend
void syncDoAppend(const log4cplus::spi::InternalLoggingEvent &event)
This method performs threshold checks and invokes filters before delegating actual logging to the sub...
log4cplus::Appender::setErrorHandler
virtual void setErrorHandler(std::unique_ptr< ErrorHandler > eh)
Set the ErrorHandler for this Appender.
log4cplus::Appender::formatEvent
tstring & formatEvent(const log4cplus::spi::InternalLoggingEvent &event) const
log4cplus::Appender::Appender
Appender()
log4cplus::Appender::useLockFile
bool useLockFile
Definition appender.h:316
log4cplus::Appender::getErrorHandler
virtual ErrorHandler * getErrorHandler()
Return the currently set ErrorHandler for this Appender.
log4cplus::Appender::errorHandler
std::unique_ptr< ErrorHandler > errorHandler
It is assumed and enforced that errorHandler is never null.
Definition appender.h:309
log4cplus::Appender::in_flight_condition
std::condition_variable in_flight_condition
Definition appender.h:323
log4cplus::Appender::layout
std::unique_ptr< Layout > layout
The layout variable does not need to be set if the appender implementation has its own layout.
Definition appender.h:296
log4cplus::Appender::setLayout
virtual void setLayout(std::unique_ptr< Layout > layout)
Set the layout for this appender.
log4cplus::Appender::doAppend
void doAppend(const log4cplus::spi::InternalLoggingEvent &event)
This function checks async flag.
log4cplus::Appender::getLayout
virtual Layout * getLayout()
Returns the layout of this appender.
log4cplus::Appender::name
log4cplus::tstring name
Appenders are named.
Definition appender.h:299
log4cplus::Appender::closed
bool closed
Is this appender closed?
Definition appender.h:327
log4cplus::Appender::Appender
Appender(const log4cplus::helpers::Properties &properties)
log4cplus::Appender::setName
virtual void setName(const log4cplus::tstring &name)
Set the name of this appender.
log4cplus::Appender::append
virtual void append(const log4cplus::spi::InternalLoggingEvent &event)=0
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::Appender::isAsSevereAsThreshold
bool isAsSevereAsThreshold(LogLevel ll) const
Check whether the message LogLevel is below the appender's threshold.
Definition appender.h:272
log4cplus::Appender::waitToFinishAsyncLogging
void waitToFinishAsyncLogging()
This method waits for all events that are being asynchronously logged to finish.
log4cplus::Appender::lockFile
std::unique_ptr< helpers::LockFile > lockFile
Optional system wide synchronization lock.
Definition appender.h:312
log4cplus::Appender::~Appender
virtual ~Appender()
log4cplus::Appender::threshold
LogLevel threshold
There is no LogLevel threshold filtering by default.
Definition appender.h:302
log4cplus::Appender::addFilter
void addFilter(std::function< spi::FilterResult(const log4cplus::spi::InternalLoggingEvent &)>)
Add filter at the end of the filters chain.
log4cplus::Appender::getFilter
log4cplus::spi::FilterPtr getFilter() const
Get the filter chain on this Appender.
log4cplus::Appender::setFilter
void setFilter(log4cplus::spi::FilterPtr f)
Set the filter chain on this Appender.
log4cplus::Appender::destructorImpl
void destructorImpl()
This function is for derived appenders to call from their destructors.
log4cplus::ErrorHandler
This class is used to "handle" errors encountered in an log4cplus::Appender.
Definition appender.h:62
log4cplus::ErrorHandler::ErrorHandler
ErrorHandler()
log4cplus::ErrorHandler::error
virtual void error(const log4cplus::tstring &err)=0
log4cplus::ErrorHandler::reset
virtual void reset()=0
log4cplus::ErrorHandler::~ErrorHandler
virtual ~ErrorHandler()=0
log4cplus::Layout
This class is used to layout strings sent to an log4cplus::Appender.
Definition layout.h:74
log4cplus::OnlyOnceErrorHandler::reset
virtual void reset()
log4cplus::OnlyOnceErrorHandler::~OnlyOnceErrorHandler
virtual ~OnlyOnceErrorHandler()
log4cplus::OnlyOnceErrorHandler::OnlyOnceErrorHandler
OnlyOnceErrorHandler()
log4cplus::OnlyOnceErrorHandler::error
virtual void error(const log4cplus::tstring &err)
log4cplus::helpers::Properties
Definition property.h:43
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::helpers::SharedObject
Definition pointer.h:54
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
config.hxx
filter.h
This header defines Filter and all of it's subclasses.
layout.h
lockfile.h
loglevel.h
This header defines the LogLevel type.
log4cplus::helpers
Definition appender.h:50
log4cplus::spi::FilterResult
FilterResult
Definition filter.h:52
log4cplus::spi::FilterPtr
helpers::SharedObjectPtr< Filter > FilterPtr
Definition filter.h:77
log4cplus
Definition appender.h:46
log4cplus::SharedAppenderPtr
helpers::SharedObjectPtr< Appender > SharedAppenderPtr
This is a pointer to an Appender.
Definition appender.h:336
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::NOT_SET_LOG_LEVEL
const LogLevel NOT_SET_LOG_LEVEL
The NOT_SET_LOG_LEVEL LogLevel is used to indicated that no particular LogLevel is desired and that t...
Definition loglevel.h:95
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition loglevel.h:48
pointer.h
tstring.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141