Apache Log4cxx  Version 1.7.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 
24 #include <log4cxx/provisionnode.h>
26 
27 namespace LOG4CXX_NS
28 {
29 
30 class Hierarchy;
32 
51 class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository
52 {
53  private:
54  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(HierarchyPrivate, m_priv)
55 
56  public:
59 #if 15 < LOG4CXX_ABI_VERSION
62 #else
64 #endif
66 
67  private:
71  Hierarchy();
72 
73  public:
74  static HierarchyPtr create();
75 
77 
78  void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override;
79 
84 #if LOG4CXX_ABI_VERSION <= 15
85  void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);
86 #else
87  void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override;
88 #endif
89 
96  void ensureIsConfigured(std::function<void()> configurator) override;
97 
106  void clear();
107 
108  void emitNoAppenderWarning(const Logger* logger) override;
109 
117  LoggerPtr exists(const LogString& name) override;
118 
122  void setThreshold(const LogString& levelStr) override;
123 
130  void setThreshold(const LevelPtr& newLevel) override;
131 
132  void fireAddAppenderEvent(const Logger* logger, const Appender* appender) override;
133 
134  void fireRemoveAppenderEvent(const Logger* logger, const Appender* appender) override;
135 
140  LevelPtr getThreshold() const override;
141 
153  LoggerPtr getLogger(const LogString& name) override;
154 
169  const spi::LoggerFactoryPtr& factory) override;
170 
177  LoggerList getCurrentLoggers() const override;
178 
182  LoggerPtr getRootLogger() const override;
183 
189  bool isDisabled(int level) const override;
190 
204  void resetConfiguration() override;
205 
223  void shutdown() override;
224 
225 
226  virtual bool isConfigured() override;
227  virtual void setConfigured(bool configured) override;
228 
232  void updateChildren(const Logger* parent);
233 
234 #if LOG4CXX_ABI_VERSION <= 15
238  [[ deprecated( "Storing appenders is longer supported" ) ]]
240 
244  [[ deprecated( "Storing appenders is longer supported" ) ]]
245  void addAppender(AppenderPtr appender);
246 #endif
258 #if LOG4CXX_ABI_VERSION <= 15
259  bool removeLogger(const LogString& name, bool ifNotUsed = true);
260 #else
261  bool removeLogger(const LogString& name, bool ifNotUsed = true) override;
262 #endif
263 
264  private:
265 
269  void setThresholdInternal(const LevelPtr& l);
270 
274  void shutdownInternal();
275 
299  void updateParents(const LoggerPtr& logger, const LoggerPtr& root);
300 
315  void updateChildren(ProvisionNode& pn, const LoggerPtr& logger);
316 
317  Hierarchy(const Hierarchy&);
318  Hierarchy& operator=(const Hierarchy&);
319 
320 };
321 
322 } //namespace log4cxx
323 
324 #endif //_LOG4CXX_HIERARCHY_H
Implement this interface for your own strategies for outputting log statements.
Definition: appender.h:51
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:52
void ensureIsConfigured(std::function< void()> configurator) override
Call configurator if not yet configured and configurator has not already been tried.
LoggerList getCurrentLoggers() const override
Returns all the currently defined loggers in this hierarchy as a LoggerList.
void emitNoAppenderWarning(const Logger *logger) override
LoggerPtr getRootLogger() const override
Get the root of this hierarchy.
void resetConfiguration() override
Reset all values contained in this hierarchy instance to their default.
void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr &listener)
Remove a previously added HierarchyEventListener.
LevelPtr getThreshold() const override
Returns a Level representation of the enable state.
LoggerPtr exists(const LogString &name) override
Check if the named logger exists in the hierarchy.
LoggerPtr getLogger(const LogString &name) override
Retrieve the name Logger instance using the default factory to create it if required.
void addAppender(AppenderPtr appender)
void setThreshold(const LevelPtr &newLevel) override
Enable logging for logging requests with level newLevel or higher.
bool removeLogger(const LogString &name, bool ifNotUsed=true)
Remove the name Logger from the hierarchy.
virtual void setConfigured(bool configured) override
void fireAddAppenderEvent(const Logger *logger, const Appender *appender) override
static HierarchyPtr create()
bool isDisabled(int level) const override
This method will return true if this repository is disabled for level object passed as parameter and ...
void updateChildren(const Logger *parent)
Refresh the threshold in children of parent.
virtual bool isConfigured() override
void addHierarchyEventListener(const spi::HierarchyEventListenerPtr &listener) override
void clear()
This call will clear all logger definitions from the internal hashtable.
void setThreshold(const LogString &levelStr) override
The string form of setThreshold.
LoggerPtr getLogger(const LogString &name, const spi::LoggerFactoryPtr &factory) override
Retrieve the name Logger instance using factory to create it if required.
void fireRemoveAppenderEvent(const Logger *logger, const Appender *appender) override
void shutdown() override
Used by subclasses to add a renderer to the hierarchy passed as parameter.
This is the central class in the log4cxx package.
Definition: log4cxx/logger.h:52
A LoggerRepository is used to create and retrieve Loggers.
Definition: loggerrepository.h:43
std::shared_ptr< LoggerFactory > LoggerFactoryPtr
Definition: logmanager.h:33
LOG4CXX_PTR_DEF(Hierarchy)
std::vector< LoggerPtr > ProvisionNode
Definition: provisionnode.h:31
std::basic_string< logchar > LogString
Definition: logstring.h:60
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
std::shared_ptr< Appender > AppenderPtr
Definition: basicconfigurator.h:28
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:26
std::vector< LoggerPtr > LoggerList
Definition: logmanager.h:29
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:154
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:37
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:148
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:160
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:142