log4cplus  2.0.5
logger.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: logger.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 
25 #ifndef LOG4CPLUS_LOGGERHEADER_
26 #define LOG4CPLUS_LOGGERHEADER_
27 
28 #include <log4cplus/config.hxx>
29 
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
31 #pragma once
32 #endif
33 
34 #include <log4cplus/loglevel.h>
35 #include <log4cplus/tstring.h>
38 
39 #include <vector>
40 
41 
42 namespace log4cplus
43 {
44  // Forward declarations
45 
46  class Appender;
47  class Hierarchy;
48  class HierarchyLocker;
49  class DefaultLoggerFactory;
50 
51  namespace spi
52  {
53 
54  class LoggerImpl;
55 
56  }
57 
58 
61  typedef std::vector<Logger> LoggerList;
62 
63 
71  {
72  public:
73  // Static Methods
80  static bool exists(const log4cplus::tstring& name);
81 
82  /*
83  * Returns all the currently defined loggers in the default
84  * hierarchy.
85  *
86  * The root logger is <em>not</em> included in the returned
87  * list.
88  */
90 
95 
107  static Logger getInstance(const log4cplus::tstring& name);
108 
122  spi::LoggerFactory& factory);
123 
134  static Logger getRoot();
135 
150  static void shutdown();
151 
152  // Non-Static Methods
161  void assertion(bool assertionVal, const log4cplus::tstring& msg) const;
162 
167  void closeNestedAppenders() const;
168 
175  bool isEnabledFor(LogLevel ll) const;
176 
180  void log(LogLevel ll, const log4cplus::tstring& message,
181  const char* file = LOG4CPLUS_CALLER_FILE (),
182  int line = LOG4CPLUS_CALLER_LINE (),
183  const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const;
184 
185  void log(spi::InternalLoggingEvent const &) const;
186 
191  void forcedLog(LogLevel ll, const log4cplus::tstring& message,
192  const char* file = LOG4CPLUS_CALLER_FILE (),
193  int line = LOG4CPLUS_CALLER_LINE (),
194  const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const;
195 
197 
209  void callAppenders(const spi::InternalLoggingEvent& event) const;
210 
220 
227 
232 
238 
242  log4cplus::tstring const & getName() const;
243 
247  bool getAdditivity() const;
248 
252  void setAdditivity(bool additive);
253 
254  // AppenderAttachable Methods
255  virtual void addAppender(SharedAppenderPtr newAppender);
256 
258 
260 
261  virtual void removeAllAppenders();
262 
263  virtual void removeAppender(SharedAppenderPtr appender);
264 
265  virtual void removeAppender(const log4cplus::tstring& name);
266 
269  Logger& operator=(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
271  Logger & operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT;
272  virtual ~Logger();
273 
274  void swap (Logger &) LOG4CPLUS_NOEXCEPT;
275 
280  Logger getParent() const;
281 
282  protected:
283  // Data
285  spi::LoggerImpl * value = nullptr;
286 
287  private:
288  // Ctors
298  Logger(spi::LoggerImpl * ptr) LOG4CPLUS_NOEXCEPT;
299 
300  // Friends
301  friend class log4cplus::spi::LoggerImpl;
302  friend class log4cplus::Hierarchy;
303  friend class log4cplus::HierarchyLocker;
305  };
306 
307 
312  class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory {
313  public:
315 
316  protected:
318  const log4cplus::tstring& name, Hierarchy& h);
319  };
320 
321 
322 } // end namespace log4cplus
323 
324 
325 #endif // LOG4CPLUS_LOGGERHEADER_
log4cplus::Logger::getAppender
virtual SharedAppenderPtr getAppender(const log4cplus::tstring &name)
Get an appender by name.
tstring.h
log4cplus::Logger::forcedLog
void forcedLog(LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
This method creates a new logging event and logs the event without further checks.
log4cplus::Logger::getName
log4cplus::tstring const & getName() const
Return the logger name.
log4cplus
Definition: appender.h:46
log4cplus::DefaultLoggerFactory::makeNewLoggerImplInstance
virtual spi::LoggerImpl * makeNewLoggerImplInstance(const log4cplus::tstring &name, Hierarchy &h)
log4cplus::Logger::forcedLog
void forcedLog(spi::InternalLoggingEvent const &) const
log4cplus::Logger::getAdditivity
bool getAdditivity() const
Get the additivity flag for this Logger instance.
log4cplus::Logger::setAdditivity
void setAdditivity(bool additive)
Set the additivity flag for this Logger instance.
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::Logger::getHierarchy
Hierarchy & getHierarchy() const
Return the the Hierarchy where this Logger instance is attached.
log4cplus::Logger::addAppender
virtual void addAppender(SharedAppenderPtr newAppender)
Add an appender.
log4cplus::helpers::SharedObjectPtr
Definition: pointer.h:101
log4cplus::spi::LoggerImpl
This is the central class in the log4cplus package.
Definition: loggerimpl.h:54
log4cplus::Logger::isEnabledFor
bool isEnabledFor(LogLevel ll) const
Check whether this logger is enabled for a given LogLevel passed as parameter.
log4cplus::Logger::getRoot
static Logger getRoot()
Return the root of the default logger hierrachy.
log4cplus::HierarchyLocker
This is used to lock a Hierarchy.
Definition: hierarchylocker.h:47
log4cplus::Logger::assertion
void assertion(bool assertionVal, const log4cplus::tstring &msg) const
If assertionVal parameter is false, then logs msg with FATAL_LOG_LEVEL log level.
loggerfactory.h
log4cplus::Logger::closeNestedAppenders
void closeNestedAppenders() const
Close all attached appenders implementing the AppenderAttachable interface.
LOG4CPLUS_CALLER_FUNCTION
#define LOG4CPLUS_CALLER_FUNCTION()
Definition: config.hxx:123
loglevel.h
log4cplus::Logger::setLogLevel
void setLogLevel(LogLevel ll)
Set the LogLevel of this Logger.
log4cplus::Logger::Logger
Logger() LOG4CPLUS_NOEXCEPT
log4cplus::Logger::getChainedLogLevel
LogLevel getChainedLogLevel() const
Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.
config.hxx
log4cplus::Logger::removeAppender
virtual void removeAppender(SharedAppenderPtr appender)
Remove the appender passed as parameter from the list of appenders.
log4cplus::Logger::exists
static bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
log4cplus::DefaultLoggerFactory::makeNewLoggerInstance
Logger makeNewLoggerInstance(const log4cplus::tstring &name, Hierarchy &h)
Creates a new Logger object.
LOG4CPLUS_CALLER_LINE
#define LOG4CPLUS_CALLER_LINE()
Definition: config.hxx:122
log4cplus::Logger::removeAllAppenders
virtual void removeAllAppenders()
Remove all previously added appenders.
log4cplus::Hierarchy
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:64
log4cplus::LogLevel
int LogLevel
Definition: loglevel.h:48
log4cplus::Logger::removeAppender
virtual void removeAppender(const log4cplus::tstring &name)
Remove the appender with the name passed as parameter from the list of appenders.
appenderattachable.h
log4cplus::spi::LoggerFactory
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition: loggerfactory.h:48
log4cplus::Logger::log
void log(spi::InternalLoggingEvent const &) const
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
log4cplus::spi::AppenderAttachable
This Interface is for attaching Appenders to objects.
Definition: appenderattachable.h:47
log4cplus::Logger::callAppenders
void callAppenders(const spi::InternalLoggingEvent &event) const
Call the appenders in the hierrachy starting at this.
LOG4CPLUS_CALLER_FILE
#define LOG4CPLUS_CALLER_FILE()
Definition: config.hxx:121
log4cplus::LoggerList
std::vector< Logger > LoggerList
Definition: logger.h:61
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::Logger::getAllAppenders
virtual SharedAppenderPtrList getAllAppenders()
Get all previously added appenders as an Enumeration.
log4cplus::Logger::shutdown
static void shutdown()
Calling this method will safely close and remove all appenders in all the loggers including root cont...
log4cplus::Logger::getLogLevel
LogLevel getLogLevel() const
Returns the assigned LogLevel, if any, for this Logger.
log4cplus::Logger::getInstance
static Logger getInstance(const log4cplus::tstring &name, spi::LoggerFactory &factory)
Like getInstance() except that the type of logger instantiated depends on the type returned by the {}...
log4cplus::Logger::getCurrentLoggers
static LoggerList getCurrentLoggers()
log4cplus::Logger::getDefaultHierarchy
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
log4cplus::SharedAppenderPtrList
std::vector< log4cplus::SharedAppenderPtr > SharedAppenderPtrList
Definition: appenderattachable.h:40
log4cplus::Logger::log
void log(LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
This generic form is intended to be used by wrappers.
LOG4CPLUS_NOEXCEPT
#define LOG4CPLUS_NOEXCEPT
Definition: config.hxx:101
log4cplus::Logger::getInstance
static Logger getInstance(const log4cplus::tstring &name)
Retrieve a logger with name name.
log4cplus::DefaultLoggerFactory
This class is used to create the default implementation of the Logger class.
Definition: logger.h:312
log4cplus::Logger
This is the central class in the log4cplus package.
Definition: logger.h:71