Apache log4cxx  Version 0.12.1
domconfigurator.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_XML_DOM_CONFIGURATOR_H
19 #define _LOG4CXX_XML_DOM_CONFIGURATOR_H
20 
21 #if defined(_MSC_VER)
22  #pragma warning (push)
23  #pragma warning ( disable: 4231 4251 4275 4786 )
24 #endif
25 
26 
27 
28 #include <log4cxx/logstring.h>
29 #include <map>
30 #include <log4cxx/appender.h>
31 #include <log4cxx/layout.h>
32 #include <log4cxx/logger.h>
36 #include <log4cxx/spi/filter.h>
39 #include <log4cxx/file.h>
41 
42 extern "C" {
43  struct apr_xml_doc;
44  struct apr_xml_elem;
45 }
46 
47 namespace log4cxx
48 {
49 
50 namespace xml
51 {
52 class XMLWatchdog;
53 
69 class LOG4CXX_EXPORT DOMConfigurator :
70  virtual public spi::Configurator,
71  virtual public helpers::Object
72 {
73  protected:
74  typedef std::map<LogString, AppenderPtr> AppenderMap;
78  AppenderPtr findAppenderByName(
80  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
81  apr_xml_elem* elem,
82  apr_xml_doc* doc,
83  const LogString& appenderName,
84  AppenderMap& appenders);
85 
89  AppenderPtr findAppenderByReference(
91  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
92  apr_xml_elem* appenderRef,
93  apr_xml_doc* doc,
94  AppenderMap& appenders);
95 
99  AppenderPtr parseAppender(
101  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
102  apr_xml_elem* appenderElement,
103  apr_xml_doc* doc,
104  AppenderMap& appenders);
105 
109  void parseErrorHandler(
111  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
112  apr_xml_elem* element,
113  AppenderPtr& appender,
114  apr_xml_doc* doc,
115  AppenderMap& appenders);
116 
120  void parseFilters(
122  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
123  apr_xml_elem* element,
124  std::vector<log4cxx::spi::FilterPtr>& filters);
125 
129  void parseLogger(
131  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
132  apr_xml_elem* loggerElement,
133  apr_xml_doc* doc,
134  AppenderMap& appenders);
135 
139  void parseLoggerFactory(
141  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
142  apr_xml_elem* factoryElement);
143 
147  log4cxx::helpers::ObjectPtr parseTriggeringPolicy(
149  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
150  apr_xml_elem* factoryElement);
151 
155  log4cxx::rolling::RollingPolicyPtr parseRollingPolicy(
157  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
158  apr_xml_elem* factoryElement);
159 
163  void parseRoot(log4cxx::helpers::Pool& p,
164  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
165  apr_xml_elem* rootElement, apr_xml_doc* doc, AppenderMap& appenders);
166 
170  void parseChildrenOfLoggerElement(
172  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
173  apr_xml_elem* catElement,
174  LoggerPtr logger, bool isRoot,
175  apr_xml_doc* doc,
176  AppenderMap& appenders );
177 
181  LayoutPtr parseLayout(
183  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
184  apr_xml_elem* layout_element);
185 
189  void parseLevel(
191  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
192  apr_xml_elem* element,
193  LoggerPtr logger, bool isRoot);
194 
195  void setParameter(
197  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
198  apr_xml_elem* elem,
199  log4cxx::config::PropertySetter& propSetter);
200 
205  void parse(
207  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
208  apr_xml_elem* element,
209  apr_xml_doc* doc,
210  AppenderMap& appenders);
211 
212  public:
213  DOMConfigurator();
214 
217  LOG4CXX_CAST_ENTRY(spi::Configurator)
219 
220  DOMConfigurator(log4cxx::helpers::Pool& p);
221 
225  static void configure(const std::string& filename);
226 #if LOG4CXX_WCHAR_T_API
227  static void configure(const std::wstring& filename);
228 #endif
229 #if LOG4CXX_UNICHAR_API
230  static void configure(const std::basic_string<UniChar>& filename);
231 #endif
232 #if LOG4CXX_CFSTRING_API
233  static void configure(const CFStringRef& filename);
234 #endif
235 
241  static void configureAndWatch(const std::string& configFilename);
242 #if LOG4CXX_WCHAR_T_API
243  static void configureAndWatch(const std::wstring& configFilename);
244 #endif
245 #if LOG4CXX_UNICHAR_API
246  static void configureAndWatch(const std::basic_string<UniChar>& configFilename);
247 #endif
248 #if LOG4CXX_CFSTRING_API
249  static void configureAndWatch(const CFStringRef& configFilename);
250 #endif
251 
262  static void configureAndWatch(const std::string& configFilename,
263  long delay);
264 #if LOG4CXX_WCHAR_T_API
265  static void configureAndWatch(const std::wstring& configFilename,
266  long delay);
267 #endif
268 #if LOG4CXX_UNICHAR_API
269  static void configureAndWatch(const std::basic_string<UniChar>& configFilename,
270  long delay);
271 #endif
272 #if LOG4CXX_CFSTRING_API
273  static void configureAndWatch(const CFStringRef& configFilename,
274  long delay);
275 #endif
276 
284  void doConfigure(const File& filename,
285  spi::LoggerRepositoryPtr repository);
286 
287  protected:
288  static LogString getAttribute(
289  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
290  apr_xml_elem*,
291  const std::string& attrName);
292 
293  LogString subst(const LogString& value);
294 
295  protected:
299 
300  private:
301  // prevent assignment or copy statements
303  DOMConfigurator& operator=(const DOMConfigurator&);
304  static XMLWatchdog* xdog;
305 };
307 } // namespace xml
308 } // namespace log4cxx
309 
310 #if defined(_MSC_VER)
311  #pragma warning (pop)
312 #endif
313 
314 #endif // _LOG4CXX_XML_DOM_CONFIGURATOR_H
std::map< LogString, AppenderPtr > AppenderMap
Definition: domconfigurator.h:74
General purpose Object property setter.
Definition: propertysetter.h:53
#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
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
const struct __CFString * CFStringRef
Definition: logstring.h:36
spi::LoggerFactoryPtr loggerFactory
Definition: domconfigurator.h:298
spi::LoggerRepositoryPtr repository
Definition: domconfigurator.h:297
Use this class to initialize the log4cxx environment using a DOM tree.
Definition: domconfigurator.h:69
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
base class for java-like objects.
Definition: object.h:101
std::shared_ptr< LoggerRepository > LoggerRepositoryPtr
Definition: defaultconfigurator.h:27
std::shared_ptr< Layout > LayoutPtr
Definition: appender.h:47
std::shared_ptr< Object > ObjectPtr
Definition: propertysetter.h:28
std::shared_ptr< Appender > AppenderPtr
Definition: basicconfigurator.h:28
Definition: properties.h:38
Definition: pool.h:32
LOG4CXX_PTR_DEF(DOMConfigurator)
Implemented by classes capable of configuring log4j using a URL.
Definition: configurator.h:32
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:26
An abstract representation of file and directory path names.
Definition: file.h:45
helpers::Properties props
Definition: domconfigurator.h:296
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66