log4cplus  2.0.5
appender.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: appender.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_APPENDER_HEADER_
25 #define LOG4CPLUS_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/layout.h>
34 #include <log4cplus/loglevel.h>
35 #include <log4cplus/tstring.h>
37 #include <log4cplus/spi/filter.h>
39 
40 #include <memory>
41 #include <mutex>
42 #include <atomic>
43 #include <condition_variable>
44 
45 
46 namespace log4cplus {
47 
48 
49  namespace helpers
50  {
51 
52  class Properties;
53 
54  }
55 
56 
62  {
63  public:
65  virtual ~ErrorHandler() = 0;
66  virtual void error(const log4cplus::tstring& err) = 0;
67  virtual void reset() = 0;
68  };
69 
70 
72  : public ErrorHandler
73  {
74  public:
75  // Ctor
78  virtual void error(const log4cplus::tstring& err);
79  virtual void reset();
80 
81  private:
82  bool firstTime;
83  };
84 
85 
138  : public virtual log4cplus::helpers::SharedObject
139  {
140  public:
141  // Ctor
144 
145  // Dtor
146  virtual ~Appender();
147 
157 
158  // Methods
165  virtual void close() = 0;
166 
170  bool isClosed() const;
171 
178 
185 
192 
198 
203  virtual void setName(const log4cplus::tstring& name);
204 
208  virtual void setErrorHandler(std::unique_ptr<ErrorHandler> eh);
209 
215 
221  virtual void setLayout(std::unique_ptr<Layout> layout);
222 
228  virtual Layout* getLayout();
229 
234 
239 
244 
248  void addFilter (std::function<
250 
255  LogLevel getThreshold() const { return threshold; }
256 
265  void setThreshold(LogLevel th) { threshold = th; }
266 
273  return ((ll != NOT_SET_LOG_LEVEL) && (ll >= threshold));
274  }
275 
281 
282  protected:
283  // Methods
289  virtual void append(const log4cplus::spi::InternalLoggingEvent& event) = 0;
290 
292 
293  // Data
296  std::unique_ptr<Layout> layout;
297 
300 
303 
307 
309  std::unique_ptr<ErrorHandler> errorHandler;
310 
312  std::unique_ptr<helpers::LockFile> lockFile;
313 
317 
319  bool async;
320 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
321  std::atomic<std::size_t> in_flight;
322  std::mutex in_flight_mutex;
323  std::condition_variable in_flight_condition;
324 #endif
325 
327  bool closed;
328 
329  private:
330 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
331  void subtract_in_flight();
332 #endif
333  };
334 
337 
338 } // end namespace log4cplus
339 
340 #endif // LOG4CPLUS_APPENDER_HEADER_
tstring.h
log4cplus::Appender::useLockFile
bool useLockFile
Use lock file for inter-process synchronization of access to log file.
Definition: appender.h:316
log4cplus::ErrorHandler::ErrorHandler
ErrorHandler()
filter.h
This header defines Filter and all of it's subclasses.
log4cplus
Definition: appender.h:46
log4cplus::Appender::closed
bool closed
Is this appender closed?
Definition: appender.h:327
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::Appender::async
bool async
Asynchronous append.
Definition: appender.h:319
log4cplus::helpers::SharedObjectPtr< Filter >
log4cplus::Appender::getErrorHandler
virtual ErrorHandler * getErrorHandler()
Return the currently set ErrorHandler for this Appender.
log4cplus::Appender::Appender
Appender(const log4cplus::helpers::Properties &properties)
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::in_flight
std::atomic< std::size_t > in_flight
Definition: appender.h:321
log4cplus::ErrorHandler::reset
virtual void reset()=0
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::setFilter
void setFilter(log4cplus::spi::FilterPtr f)
Set the filter chain on this Appender.
log4cplus::Appender::isClosed
bool isClosed() const
Check if this appender is in closed state.
log4cplus::OnlyOnceErrorHandler
Definition: appender.h:73
log4cplus::Appender::close
virtual void close()=0
Release any resources allocated within the appender such as file handles, network connections,...
lockfile.h
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::ErrorHandler
This class is used to "handle" errors encountered in an {}.
Definition: appender.h:62
loglevel.h
This header defines the LogLevel type.
log4cplus::Appender::getThreshold
LogLevel getThreshold() const
Returns this appenders threshold LogLevel.
Definition: appender.h:255
log4cplus::Appender::getFilter
log4cplus::spi::FilterPtr getFilter() const
Get the filter chain on this Appender.
log4cplus::SharedAppenderPtr
helpers::SharedObjectPtr< Appender > SharedAppenderPtr
This is a pointer to an Appender.
Definition: appender.h:336
log4cplus::Appender::setLayout
virtual void setLayout(std::unique_ptr< Layout > layout)
Set the layout for this appender.
log4cplus::Appender::destructorImpl
void destructorImpl()
This function is for derived appenders to call from their destructors.
log4cplus::Appender::threshold
LogLevel threshold
There is no LogLevel threshold filtering by default.
Definition: appender.h:302
log4cplus::Appender::~Appender
virtual ~Appender()
log4cplus::OnlyOnceErrorHandler::OnlyOnceErrorHandler
OnlyOnceErrorHandler()
log4cplus::Appender::doAppend
void doAppend(const log4cplus::spi::InternalLoggingEvent &event)
This function checks async flag.
config.hxx
log4cplus::helpers::Properties
Definition: property.h:43
log4cplus::Appender::in_flight_mutex
std::mutex in_flight_mutex
Definition: appender.h:322
pointer.h
log4cplus::OnlyOnceErrorHandler::reset
virtual void reset()
log4cplus::Appender::waitToFinishAsyncLogging
void waitToFinishAsyncLogging()
This method waits for all events that are being asynchronously logged to finish.
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::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::Layout
This class is used to layout strings sent to an {}.
Definition: layout.h:74
log4cplus::spi::FilterResult
FilterResult
Definition: filter.h:52
log4cplus::OnlyOnceErrorHandler::error
virtual void error(const log4cplus::tstring &err)
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
log4cplus::Appender::getName
virtual log4cplus::tstring getName()
Get the name of this appender.
log4cplus::Appender::setThreshold
void setThreshold(LogLevel th)
Set the threshold LogLevel.
Definition: appender.h:265
log4cplus::Appender::getLayout
virtual Layout * getLayout()
Returns the layout of this appender.
log4cplus::Appender::addFilter
void addFilter(std::function< spi::FilterResult(const log4cplus::spi::InternalLoggingEvent &)>)
Add filter at the end of the filters chain.
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::Appender::addFilter
void addFilter(log4cplus::spi::FilterPtr f)
Add filter at the end of the filters chain.
layout.h
log4cplus::Appender::setErrorHandler
virtual void setErrorHandler(std::unique_ptr< ErrorHandler > eh)
Set the ErrorHandler for this Appender.
log4cplus::Appender::Appender
Appender()
log4cplus::ErrorHandler::~ErrorHandler
virtual ~ErrorHandler()=0
log4cplus::Appender::lockFile
std::unique_ptr< helpers::LockFile > lockFile
Optional system wide synchronization lock.
Definition: appender.h:312
log4cplus::OnlyOnceErrorHandler::~OnlyOnceErrorHandler
virtual ~OnlyOnceErrorHandler()
log4cplus::Appender::in_flight_condition
std::condition_variable in_flight_condition
Definition: appender.h:323
log4cplus::Appender::errorHandler
std::unique_ptr< ErrorHandler > errorHandler
It is assumed and enforced that errorHandler is never null.
Definition: appender.h:309
log4cplus::helpers::SharedObject
Definition: pointer.h:54
log4cplus::Appender::name
log4cplus::tstring name
Appenders are named.
Definition: appender.h:299
log4cplus::Appender::setName
virtual void setName(const log4cplus::tstring &name)
Set the name of this appender.
log4cplus::Appender
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
log4cplus::ErrorHandler::error
virtual void error(const log4cplus::tstring &err)=0
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::filter
log4cplus::spi::FilterPtr filter
The first filter in the filter chain.
Definition: appender.h:306
log4cplus::Appender::formatEvent
tstring & formatEvent(const log4cplus::spi::InternalLoggingEvent &event) const