Update of /cvsroot/objecthandler/log4cxx-0.9.7/include/log4cxx/xml
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25784/include/log4cxx/xml
Added Files:
Makefile.am domconfigurator.h xmllayout.h
Log Message:
--- NEW FILE: domconfigurator.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_XML_DOM_CONFIGURATOR_H
#define _LOG4CXX_XML_DOM_CONFIGURATOR_H
#include <log4cxx/config.h>
#ifdef HAVE_XML
#include <log4cxx/helpers/tchar.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/objectimpl.h>
#include <map>
#include <log4cxx/appender.h>
#include <log4cxx/layout.h>
#include <log4cxx/logger.h>
#include <log4cxx/helpers/properties.h>
#include <log4cxx/spi/configurator.h>
namespace log4cxx
{
namespace spi
{
class LoggerRepository;
typedef helpers::ObjectPtrT<LoggerRepository> LoggerRepositoryPtr;
class Filter;
typedef helpers::ObjectPtrT<Filter> FilterPtr;
class AppenderAttachable;
typedef helpers::ObjectPtrT<AppenderAttachable> AppenderAttachablePtr;
class OptionHandler;
typedef helpers::ObjectPtrT<OptionHandler> OptionHandlerPtr;
}
namespace helpers
{
class XMLDOMDocument;
typedef helpers::ObjectPtrT<XMLDOMDocument> XMLDOMDocumentPtr;
class XMLDOMElement;
typedef helpers::ObjectPtrT<XMLDOMElement> XMLDOMElementPtr;
}
namespace config
{
class PropertySetter;
}
namespace xml
{
class AppenderMap
{
public:
AppenderPtr get(const String& appenderName);
void put(const String& appenderName, AppenderPtr appender);
protected:
std::map<String, AppenderPtr> map;
};
/**
Use this class to initialize the log4cxx environment using a DOM tree.
<p>Sometimes it is useful to see how log4cxx is reading configuration
files. You can enable log4cxx internal logging by setting the
<code>debug</code> attribute in the
<code>log4cxx</code> element. As in
<pre>
<log4j:configuration <b>debug="true"</b> xmlns:log4j="http://jakarta.apache.org/log4j/">
...
</log4j:configuration>
</pre>
<p>There are sample XML files included in the package.
*/
class LOG4CXX_EXPORT DOMConfigurator :
virtual public spi::Configurator,
virtual public helpers::ObjectImpl
{
protected:
/**
Used internally to parse appenders by IDREF name.
*/
AppenderPtr findAppenderByName(helpers::XMLDOMDocumentPtr doc,
const String& appenderName);
/**
Used internally to parse appenders by IDREF element.
*/
AppenderPtr findAppenderByReference(
helpers::XMLDOMElementPtr appenderRef);
/**
Used internally to parse an appender element.
*/
AppenderPtr parseAppender(helpers::XMLDOMElementPtr appenderElement);
/**
Used internally to parse an {@link spi::ErrorHandler ErrorHandler } element.
*/
void parseErrorHandler(helpers::XMLDOMElementPtr element, AppenderPtr appender);
/**
Used internally to parse a filter element.
*/
void parseFilters(helpers::XMLDOMElementPtr element, AppenderPtr appender);
/**
Used internally to parse a logger element.
*/
void parseLogger(helpers::XMLDOMElementPtr loggerElement);
/**
Used internally to parse the logger factory element.
*/
void parseLoggerFactory(helpers::XMLDOMElementPtr factoryElement);
/**
Used internally to parse the roor category element.
*/
void parseRoot(helpers::XMLDOMElementPtr rootElement);
/**
Used internally to parse the children of a category element.
*/
void parseChildrenOfLoggerElement(helpers::XMLDOMElementPtr catElement,
LoggerPtr logger, bool isRoot);
/**
Used internally to parse a layout element.
*/
LayoutPtr parseLayout(helpers::XMLDOMElementPtr layout_element);
/**
Used internally to parse a level element.
*/
void parseLevel(helpers::XMLDOMElementPtr element,
LoggerPtr logger, bool isRoot);
void setParameter(helpers::XMLDOMElementPtr elem,
config::PropertySetter& propSetter);
/**
Used internally to configure the log4cxx framework by parsing a DOM
tree of XML elements based on <a
href="docs/log4j.dtd">log4j.dtd</a>.
*/
void parse(helpers::XMLDOMElementPtr element);
public:
DECLARE_LOG4CXX_OBJECT(DOMConfigurator)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(spi::Configurator)
END_LOG4CXX_CAST_MAP()
/**
A static version of #doConfigure.
*/
static void configure(const String& filename);
/**
Like #configureAndWatch(const String& configFilename, long delay)
except that the default delay as defined by
FileWatchdog#DEFAULT_DELAY is used.
@param configFilename A log4j configuration file in XML format.
*/
static void configureAndWatch(const String& configFilename);
/**
Read the configuration file <code>configFilename</code> if it
exists. Moreover, a thread will be created that will periodically
check if <code>configFilename</code> has been created or
modified. The period is determined by the <code>delay</code>
argument. If a change or file creation is detected, then
<code>configFilename</code> is read to configure log4cxx.
@param configFilename A log4j configuration file in XML format.
@param delay The delay in milliseconds to wait between each check.
*/
static void configureAndWatch(const String& configFilename,
long delay);
/**
Interpret the XML file pointed by <code>filename</code> and set up
log4cxx accordingly.
<p>The configuration is done relative to the hierarchy parameter.
@param filename The file to parse.
@param repository The hierarchy to operation upon.
*/
void doConfigure(const String& filename,
spi::LoggerRepositoryPtr& repository);
protected:
String DOMConfigurator::subst(const String& value);
protected:
void * appenderBag;
helpers::Properties props;
spi::LoggerRepositoryPtr repository;
spi::LoggerFactoryPtr loggerFactory;
};
} // namespace xml
}; // namespace log4cxx
#endif // HAVE_XML
#endif // _LOG4CXX_XML_DOM_CONFIGURATOR_H
--- NEW FILE: Makefile.am ---
xmlincdir = $(includedir)/log4cxx/xml
xmlinc_HEADERS= $(top_srcdir)/include/log4cxx/xml/*.h
--- NEW FILE: xmllayout.h ---
/*
* Copyright 2003,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LOG4CXX_XML_LAYOUT_H
#define _LOG4CXX_XML_LAYOUT_H
#include <log4cxx/layout.h>
namespace log4cxx
{
namespace xml
{
class XMLLayout;
typedef helpers::ObjectPtrT<XMLLayout> XMLLayoutPtr;
/**
The output of the XMLLayout consists of a series of log4j:event
elements as defined in the <a
href="doc-files/log4j.dtd">log4j.dtd</a>. It does not output a
complete well-formed XML file. The output is designed to be
included as an <em>external entity</em> in a separate file to form
a correct XML file.
<p>For example, if <code>abc</code> is the name of the file where
the XMLLayout ouput goes, then a well-formed XML file would be:
<code>
<?xml version="1.0" ?>
<!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd" [<!ENTITY data SYSTEM "abc">]>
<log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/">
@&data;
</log4j:eventSet>
</code>
<p>This approach enforces the independence of the XMLLayout and the
appender where it is embedded.
*/
class LOG4CXX_EXPORT XMLLayout : public Layout
{
private:
/**
A string constant used in naming the option for setting the the
location information flag. Current value of this string
constant is <b>LocationInfo</b>.
*/
static String LOCATION_INFO_OPTION;
// Print no location info by default
bool locationInfo; //= false
public:
DECLARE_LOG4CXX_OBJECT(XMLLayout)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(XMLLayout)
LOG4CXX_CAST_ENTRY_CHAIN(Layout)
END_LOG4CXX_CAST_MAP()
XMLLayout();
/**
The <b>LocationInfo</b> option takes a boolean value. By
default, it is set to false which means there will be no location
information output by this layout. If the the option is set to
true, then the file name and line number of the statement
at the origin of the log statement will be output.
<p>If you are embedding this layout within a SMTPAppender
then make sure to set the
<b>LocationInfo</b> option of that appender as well.
*/
inline void setLocationInfo(bool locationInfo)
{ this->locationInfo = locationInfo; }
/**
Returns the current value of the <b>LocationInfo</b> option.
*/
inline bool getLocationInfo() const
{ return locationInfo; }
/** No options to activate. */
void activateOptions() { }
/**
Set options
*/
virtual void setOption(const String& option,
const String& value);
/**
* Formats a {@link spi::LoggingEvent LoggingEvent}
* in conformance with the log4cxx.dtd.
**/
virtual void format(ostream& output, const spi::LoggingEventPtr& event) const;
/**
The XMLLayout prints and does not ignore exceptions. Hence the
return value <code>false</code>.
*/
virtual bool ignoresThrowable() const
{ return false; }
}; // class XMLLayout
} // namespace xml
}; // namespace log4cxx
#endif // _LOG4CXX_XML_LAYOUT_H
|