Apache log4cxx  Version 0.11.0
hierarchy.h
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 
26 #include <log4cxx/spi/loggerrepository.h>
27 #include <log4cxx/spi/loggerfactory.h>
28 #include <vector>
29 #include <map>
30 #include <log4cxx/provisionnode.h>
31 #include <log4cxx/helpers/objectimpl.h>
32 #include <log4cxx/spi/hierarchyeventlistener.h>
33 #include <log4cxx/helpers/pool.h>
34 
35 namespace log4cxx
36 {
55 class LOG4CXX_EXPORT Hierarchy :
56  public virtual spi::LoggerRepository,
57  public virtual helpers::ObjectImpl
58 {
59  private:
62  bool configured;
63 
64  spi::LoggerFactoryPtr defaultFactory;
65  spi::HierarchyEventListenerList listeners;
66 
67  typedef std::map<LogString, LoggerPtr> LoggerMap;
68  LoggerMap* loggers;
69 
70  typedef std::map<LogString, ProvisionNode> ProvisionNodeMap;
71  ProvisionNodeMap* provisionNodes;
72 
73  LoggerPtr root;
74 
75  int thresholdInt;
76  LevelPtr threshold;
77 
78  bool emittedNoAppenderWarning;
79  bool emittedNoResourceBundleWarning;
80 
81  public:
82  DECLARE_ABSTRACT_LOG4CXX_OBJECT(Hierarchy)
83  BEGIN_LOG4CXX_CAST_MAP()
84  LOG4CXX_CAST_ENTRY(spi::LoggerRepository)
85  END_LOG4CXX_CAST_MAP()
86 
87 
90  Hierarchy();
91 
92  ~Hierarchy();
93 
94  void addRef() const;
95  void releaseRef() const;
96 
97  void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);
98 
107  void clear();
108 
109  void emitNoAppenderWarning(const LoggerPtr& logger);
110 
118  LoggerPtr exists(const LogString& name);
119 
123  void setThreshold(const LogString& levelStr);
124 
131  void setThreshold(const LevelPtr& l);
132 
133  void fireAddAppenderEvent(const LoggerPtr& logger, const AppenderPtr& appender);
134 
135  void fireRemoveAppenderEvent(const LoggerPtr& logger,
136  const AppenderPtr& appender);
137 
142  const LevelPtr& getThreshold() const;
143 
155  LoggerPtr getLogger(const LogString& name);
156 
170  LoggerPtr getLogger(const LogString& name,
171  const spi::LoggerFactoryPtr& factory);
172 
179  LoggerList getCurrentLoggers() const;
180 
184  LoggerPtr getRootLogger() const;
185 
191  bool isDisabled(int level) const;
192 
206  void resetConfiguration();
207 
225  void shutdown();
226 
227 
228  virtual bool isConfigured();
229  virtual void setConfigured(bool configured);
230 
231 
232  private:
233 
254  void updateParents(LoggerPtr logger);
255 
270  Hierarchy(const Hierarchy&);
271  Hierarchy& operator=(const Hierarchy&);
272 
273  void updateChildren(ProvisionNode& pn, LoggerPtr logger);
274 };
275 
276 } //namespace log4cxx
277 
278 
279 #if defined(_MSC_VER)
280  #pragma warning (pop)
281 #endif
282 
283 #endif //_LOG4CXX_HIERARCHY_H
A LoggerRepository is used to create and retrieve Loggers.
Definition: loggerrepository.h:47
Implementation class for Object.
Definition: objectimpl.h:28
Definition: mutex.h:41
Definition: pool.h:32
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy...
Definition: hierarchy.h:55
Definition: appender.h:33