log4cplus  2.0.5
hierarchy.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: hierarchy.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_HIERARCHY_HEADER_
25 #define LOG4CPLUS_HIERARCHY_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/logger.h>
35 #include <map>
36 #include <memory>
37 #include <vector>
38 
39 
40 namespace log4cplus {
41  // Forward Declarations
42  class HierarchyLocker;
43 
64  {
65  public:
66  // DISABLE_OFF should be set to a value lower than all possible
67  // priorities.
68  static const LogLevel DISABLE_OFF;
69  static const LogLevel DISABLE_OVERRIDE;
70 
71  // Ctors
76 
77  // Dtor
78  virtual ~Hierarchy();
79 
80  // Methods
89  virtual void clear();
90 
97  virtual bool exists(const log4cplus::tstring& name);
98 
103  virtual void disable(const log4cplus::tstring& loglevelStr);
104 
122  virtual void disable(LogLevel ll);
123 
129  virtual void disableAll();
130 
136  virtual void disableDebug();
137 
143  virtual void disableInfo();
144 
152  virtual void enableAll();
153 
164  virtual Logger getInstance(const log4cplus::tstring& name);
165 
178  virtual Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
179 
186 
190  virtual bool isDisabled(LogLevel level);
191 
195  virtual Logger getRoot() const;
196 
210  virtual void resetConfiguration();
211 
215  virtual void setLoggerFactory(std::unique_ptr<spi::LoggerFactory> factory);
216 
221 
235  virtual void shutdown();
236 
237  private:
238  // Types
239  typedef std::vector<Logger> ProvisionNode;
240  typedef std::map<log4cplus::tstring, ProvisionNode> ProvisionNodeMap;
241  typedef std::map<log4cplus::tstring, Logger> LoggerMap;
242 
243  // Methods
249  Logger getInstanceImpl(const log4cplus::tstring& name,
250  spi::LoggerFactory& factory);
251 
257  void initializeLoggerList(LoggerList& list) const;
258 
279  LOG4CPLUS_PRIVATE void updateParents(Logger const & logger);
280 
295  LOG4CPLUS_PRIVATE void updateChildren(ProvisionNode& pn,
296  Logger const & logger);
297 
298  // Data
299  thread::Mutex hashtable_mutex;
300  std::unique_ptr<spi::LoggerFactory> defaultFactory;
301  ProvisionNodeMap provisionNodes;
302  LoggerMap loggerPtrs;
303  Logger root;
304 
305  int disableValue;
306 
307  bool emittedNoAppenderWarning;
308 
309  // Disallow copying of instances of this class
310  Hierarchy(const Hierarchy&);
311  Hierarchy& operator=(const Hierarchy&);
312 
313  // Friends
316  };
317 
318 
320 
321 
322 } // end namespace log4cplus
323 
324 #endif // LOG4CPLUS_HIERARCHY_HEADER_
log4cplus::Hierarchy::shutdown
virtual void shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all loggers including the roo...
log4cplus::Hierarchy::getCurrentLoggers
virtual LoggerList getCurrentLoggers()
Returns all the currently defined loggers in this hierarchy.
log4cplus::Hierarchy::DISABLE_OFF
static const LogLevel DISABLE_OFF
Definition: hierarchy.h:68
log4cplus
Definition: appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::Hierarchy::~Hierarchy
virtual ~Hierarchy()
logger.h
This header defines the Logger class and the logging macros.
log4cplus::spi::LoggerImpl
This is the central class in the log4cplus package.
Definition: loggerimpl.h:54
log4cplus::Hierarchy::disableDebug
virtual void disableDebug()
Disable all Debug logging requests regardless of logger.
log4cplus::HierarchyLocker
This is used to lock a Hierarchy.
Definition: hierarchylocker.h:47
log4cplus::Hierarchy::isDisabled
virtual bool isDisabled(LogLevel level)
Is the LogLevel specified by level enabled?
log4cplus::Hierarchy::Hierarchy
Hierarchy()
Create a new Logger hierarchy.
log4cplus::Hierarchy::getInstance
virtual Logger getInstance(const log4cplus::tstring &name)
Return a new logger instance named as the first parameter using the default factory.
config.hxx
log4cplus::Hierarchy::enableAll
virtual void enableAll()
Undoes the effect of calling any of disable, {}, #disableDebug} and #disableInfo} methods.
log4cplus::Hierarchy::disableInfo
virtual void disableInfo()
Disable all Info logging requests regardless of logger.
log4cplus::Hierarchy::disableAll
virtual void disableAll()
Disable all logging requests regardless of logger and LogLevel.
log4cplus::Hierarchy::setLoggerFactory
virtual void setLoggerFactory(std::unique_ptr< spi::LoggerFactory > factory)
Set the default LoggerFactory instance.
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
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
log4cplus::getDefaultHierarchy
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy()
log4cplus::Hierarchy::getLoggerFactory
virtual spi::LoggerFactory * getLoggerFactory()
Returns the default LoggerFactory instance.
log4cplus::spi::LoggerFactory
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition: loggerfactory.h:48
log4cplus::Hierarchy::getRoot
virtual Logger getRoot() const
Get the root of this hierarchy.
log4cplus::LoggerList
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition: logger.h:61
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::Hierarchy::resetConfiguration
virtual void resetConfiguration()
Reset all values contained in this hierarchy instance to their default.
log4cplus::Hierarchy::disable
virtual void disable(LogLevel ll)
Disable all logging requests of LogLevel equal to or below the ll parameter p, for all loggers in thi...
log4cplus::Hierarchy::DISABLE_OVERRIDE
static const LogLevel DISABLE_OVERRIDE
Definition: hierarchy.h:69
log4cplus::Hierarchy::clear
virtual void clear()
This call will clear all logger definitions from the internal hashtable.
log4cplus::Hierarchy::exists
virtual bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
log4cplus::Hierarchy::disable
virtual void disable(const log4cplus::tstring &loglevelStr)
Similar to disable(LogLevel) except that the LogLevel argument is given as a log4cplus::tstring.
log4cplus::thread::Mutex
Definition: syncprims.h:64
log4cplus::Hierarchy::getInstance
virtual Logger getInstance(const log4cplus::tstring &name, spi::LoggerFactory &factory)
Return a new logger instance named as the first parameter using factory.
syncprims.h
log4cplus::Logger
This is the central class in the log4cplus package.
Definition: logger.h:71