log4cplus  2.0.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
75  Hierarchy();
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 
185  virtual LoggerList getCurrentLoggers();
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 
220  virtual spi::LoggerFactory* getLoggerFactory();
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 the central class in the log4cplus package.
Definition: loggerimpl.h:51
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
This is the central class in the log4cplus package.
Definition: logger.h:69
This is used to lock a Hierarchy.
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy()
static const LogLevel DISABLE_OFF
Definition: hierarchy.h:68
std::basic_string< tchar > tstring
Definition: tstring.h:39
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:63
This header defines the Logger class and the logging macros.
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition: loggerfactory.h:46
static const LogLevel DISABLE_OVERRIDE
Definition: hierarchy.h:69
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition: logger.h:61