log4cplus  2.1.0
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_
This is used to lock a Hierarchy.
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:64
virtual LoggerList getCurrentLoggers()
Returns all the currently defined loggers in this hierarchy.
virtual void clear()
This call will clear all logger definitions from the internal hashtable.
virtual Logger getInstance(const log4cplus::tstring &name, spi::LoggerFactory &factory)
Return a new logger instance named as the first parameter using factory.
virtual void setLoggerFactory(std::unique_ptr< spi::LoggerFactory > factory)
Set the default LoggerFactory instance.
virtual void disableDebug()
Disable all Debug logging requests regardless of logger.
virtual void disableInfo()
Disable all Info logging requests regardless of logger.
virtual void shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all loggers including the roo...
virtual void disable(LogLevel ll)
Disable all logging requests of LogLevel equal to or below the ll parameter p, for all loggers in thi...
virtual Logger getRoot() const
Get the root of this hierarchy.
virtual void resetConfiguration()
Reset all values contained in this hierarchy instance to their default.
static const LogLevel DISABLE_OFF
Definition: hierarchy.h:68
virtual spi::LoggerFactory * getLoggerFactory()
Returns the default LoggerFactory instance.
virtual void enableAll()
Undoes the effect of calling any of disable, {}, #disableDebug} and #disableInfo} methods.
virtual bool isDisabled(LogLevel level)
Is the LogLevel specified by level enabled?
virtual void disableAll()
Disable all logging requests regardless of logger and LogLevel.
virtual void disable(const log4cplus::tstring &loglevelStr)
Similar to disable(LogLevel) except that the LogLevel argument is given as a log4cplus::tstring.
Hierarchy()
Create a new Logger hierarchy.
virtual Logger getInstance(const log4cplus::tstring &name)
Return a new logger instance named as the first parameter using the default factory.
static const LogLevel DISABLE_OVERRIDE
Definition: hierarchy.h:69
virtual bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
This is the central class in the log4cplus package.
Definition: logger.h:71
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition: loggerfactory.h:48
This is the central class in the log4cplus package.
Definition: loggerimpl.h:54
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
This header defines the Logger class and the logging macros.
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition: logger.h:61
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy()
#define LOG4CPLUS_EXPORT
Definition: win32.h:141