Apache log4cxx  Version 0.11.0
domconfigurator.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_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>
33 #include <log4cxx/helpers/properties.h>
34 #include <log4cxx/spi/configurator.h>
35 #include <log4cxx/helpers/charsetdecoder.h>
36 #include <log4cxx/spi/filter.h>
37 #include <log4cxx/rolling/triggeringpolicy.h>
38 #include <log4cxx/rolling/rollingpolicy.h>
39 #include <log4cxx/file.h>
40 #include <log4cxx/config/propertysetter.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::ObjectImpl
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 
215  DECLARE_LOG4CXX_OBJECT(DOMConfigurator)
216  BEGIN_LOG4CXX_CAST_MAP()
217  LOG4CXX_CAST_ENTRY(spi::Configurator)
218  END_LOG4CXX_CAST_MAP()
219 
221 
222  void addRef() const;
223  void releaseRef() const;
224 
228  static void configure(const std::string& filename);
229 #if LOG4CXX_WCHAR_T_API
230  static void configure(const std::wstring& filename);
231 #endif
232 #if LOG4CXX_UNICHAR_API
233  static void configure(const std::basic_string<UniChar>& filename);
234 #endif
235 #if LOG4CXX_CFSTRING_API
236  static void configure(const CFStringRef& filename);
237 #endif
238 
244  static void configureAndWatch(const std::string& configFilename);
245 #if LOG4CXX_WCHAR_T_API
246  static void configureAndWatch(const std::wstring& configFilename);
247 #endif
248 #if LOG4CXX_UNICHAR_API
249  static void configureAndWatch(const std::basic_string<UniChar>& configFilename);
250 #endif
251 #if LOG4CXX_CFSTRING_API
252  static void configureAndWatch(const CFStringRef& configFilename);
253 #endif
254 
265  static void configureAndWatch(const std::string& configFilename,
266  long delay);
267 #if LOG4CXX_WCHAR_T_API
268  static void configureAndWatch(const std::wstring& configFilename,
269  long delay);
270 #endif
271 #if LOG4CXX_UNICHAR_API
272  static void configureAndWatch(const std::basic_string<UniChar>& configFilename,
273  long delay);
274 #endif
275 #if LOG4CXX_CFSTRING_API
276  static void configureAndWatch(const CFStringRef& configFilename,
277  long delay);
278 #endif
279 
287  void doConfigure(const File& filename,
288  spi::LoggerRepositoryPtr& repository);
289 
290  protected:
291  static LogString getAttribute(
292  log4cxx::helpers::CharsetDecoderPtr& utf8Decoder,
293  apr_xml_elem*,
294  const std::string& attrName);
295 
296  LogString subst(const LogString& value);
297 
298  protected:
299  helpers::Properties props;
300  spi::LoggerRepositoryPtr repository;
301  spi::LoggerFactoryPtr loggerFactory;
302 
303  private:
304  // prevent assignment or copy statements
306  DOMConfigurator& operator=(const DOMConfigurator&);
307  static XMLWatchdog* xdog;
308 };
309 LOG4CXX_PTR_DEF(DOMConfigurator);
310 } // namespace xml
311 } // namespace log4cxx
312 
313 #if defined(_MSC_VER)
314  #pragma warning (pop)
315 #endif
316 
317 #endif // _LOG4CXX_XML_DOM_CONFIGURATOR_H
General purpose Object property setter.
Definition: propertysetter.h:53
Use this class to initialize the log4cxx environment using a DOM tree.
Definition: domconfigurator.h:69
Implementation class for Object.
Definition: objectimpl.h:28
Definition: properties.h:39
Definition: pool.h:32
Implemented by classes capable of configuring log4j using a URL.
Definition: configurator.h:32
An abstract representation of file and directory path names.
Definition: file.h:45
Definition: appender.h:33