Apache log4cxx  Version 0.12.0
hierarchy.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_HIERARCHY_H
19 #define _LOG4CXX_HIERARCHY_H
20 
21 #if defined(_MSC_VER)
22  #pragma warning (push)
23  #pragma warning ( disable: 4231 4251 4275 4786 )
24 #endif
25 
28 #include <vector>
29 #include <map>
30 #include <log4cxx/provisionnode.h>
31 #include <log4cxx/helpers/object.h>
33 #include <log4cxx/helpers/pool.h>
34 
35 namespace log4cxx
36 {
37 
38 class Hierarchy;
39 LOG4CXX_PTR_DEF(Hierarchy);
40 
59 class LOG4CXX_EXPORT Hierarchy :
60  public virtual spi::LoggerRepository,
61  public virtual helpers::Object,
62  public std::enable_shared_from_this<Hierarchy>
63 {
64  private:
66  mutable std::mutex mutex;
67  bool configured;
68 
69  spi::LoggerFactoryPtr defaultFactory;
70  spi::HierarchyEventListenerList listeners;
71 
72  typedef std::map<LogString, LoggerPtr> LoggerMap;
73  std::unique_ptr<LoggerMap> loggers;
74 
75  typedef std::map<LogString, ProvisionNode> ProvisionNodeMap;
76  std::unique_ptr<ProvisionNodeMap> provisionNodes;
77 
78  LoggerPtr root;
79 
80  int thresholdInt;
81  LevelPtr threshold;
82 
83  bool emittedNoAppenderWarning;
84  bool emittedNoResourceBundleWarning;
85 
86  public:
91 
92  private:
96  Hierarchy();
97 
98  public:
99  static HierarchyPtr create();
100 
101  ~Hierarchy();
102 
103  void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);
104 
113  void clear();
114 
115  void emitNoAppenderWarning(const Logger* logger);
116 
124  LoggerPtr exists(const LogString& name);
125 
129  void setThreshold(const LogString& levelStr);
130 
137  void setThreshold(const LevelPtr& l);
138 
139  void fireAddAppenderEvent(const Logger* logger, const Appender* appender);
140 
141  void fireRemoveAppenderEvent(const Logger* logger,
142  const Appender* appender);
143 
148  const LevelPtr& getThreshold() const;
149 
161  LoggerPtr getLogger(const LogString& name);
162 
176  LoggerPtr getLogger(const LogString& name,
177  const spi::LoggerFactoryPtr& factory);
178 
185  LoggerList getCurrentLoggers() const;
186 
190  LoggerPtr getRootLogger() const;
191 
197  bool isDisabled(int level) const;
198 
212  void resetConfiguration();
213 
231  void shutdown();
232 
233 
234  virtual bool isConfigured();
235  virtual void setConfigured(bool configured);
236 
237 
238  private:
239 
243  void setThresholdInternal(const LevelPtr& l);
244 
248  void shutdownInternal();
249 
270  void updateParents(LoggerPtr logger);
271 
286  Hierarchy(const Hierarchy&);
287  Hierarchy& operator=(const Hierarchy&);
288 
289  void updateChildren(ProvisionNode& pn, LoggerPtr logger);
290 
291  void configureRoot();
292 };
293 
294 } //namespace log4cxx
295 
296 
297 #if defined(_MSC_VER)
298  #pragma warning (pop)
299 #endif
300 
301 #endif //_LOG4CXX_HIERARCHY_H
A LoggerRepository is used to create and retrieve Loggers.
Definition: loggerrepository.h:47
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:26
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
std::shared_ptr< LoggerFactory > LoggerFactoryPtr
Definition: logmanager.h:38
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
std::vector< LoggerPtr > ProvisionNode
Definition: provisionnode.h:31
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
std::vector< LoggerPtr > LoggerList
Definition: logmanager.h:34
LOG4CXX_PTR_DEF(Appender)
base class for java-like objects.
Definition: object.h:101
Implement this interface for your own strategies for outputting log statements.
Definition: appender.h:55
Definition: pool.h:32
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy...
Definition: hierarchy.h:59
This is the central class in the log4cxx package.
Definition: logger.h:63
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:26
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66