Config::DOMConfigurator(3) User Contributed Perl Documentation NAME Log::Log4perl::Config::DOMConfigurator - reads xml config files SYNOPSIS -------------------------- --using the log4j DTD-- -------------------------- -------------------------- --using the log4perl DTD-- -------------------------- mary@another.jabber.server sub { return sprintf "%1x", $$} sub {return 'thisistheGcspec'} INSERT INTO log4perltest (loglevel, message, shortcaller, thingid, category, pkg, runtime1, runtime2) VALUES (?,?,?,?,?,?,?,?) DESCRIPTION This module implements an XML config, complementing the properties- style config described elsewhere. WHY "Why would I want my config in XML?" you ask. Well, there are a couple reasons you might want to. Maybe you have a personal preference for XML. Maybe you manage your config with other tools that have an affinity for XML, like XML-aware editors or automated config generators. Or maybe (and this is the big one) you don't like having to run your application just to check the syntax of your config file. By using an XML config and referencing a DTD, you can use a namespace- aware validating parser to see if your XML config at least follows the rules set in the DTD. HOW To reference a DTD, drop this in after the declaration in your config file: That tells the parser to validate your config against the DTD in "log4perl.dtd", which is available in the xml/ directory of the log4perl distribution. Note that you'll also need to grab the log4j-1.2.dtd from there as well, since the it's included by log4perl.dtd. Namespace-aware validating parsers are not the norm in Perl. But the Xerces project (http://xml.apache.org/xerces-c/index.html --lots of binaries available, even rpm's) does provide just such a parser that you can use like this: StdInParse -ns -v < my-log4perl-config.xml This module itself does not use a validating parser, the obvious one XML::DOM::ValParser doesn't seem to handle namespaces. WHY TWO DTDs The log4j DTD is from the log4j project, they designed it to handle their needs. log4perl has added some extensions to the original log4j functionality which needed some extensions to the log4j DTD. If you aren't using these features then you can validate your config against the log4j dtd and know that you're using unadulterated log4j config tags. The features added by the log4perl dtd are: 1 oneMessagePerAppender global setting log4perl.oneMessagePerAppender=1 2 globally defined user conversion specifiers log4perl.PatternLayout.cspec.G=sub { return "UID $< GID $("; } 3 appender-local custom conversion specifiers log4j.appender.appndr1.layout.cspec.K = sub {return sprintf "%1x", $$ } 4 nested options log4j.appender.jabbender = Log::Dispatch::Jabber #(note how these are nested under 'login') log4j.appender.jabbender.login.hostname = a.jabber.server log4j.appender.jabbender.login.port = 5222 log4j.appender.jabbender.login.username = bobjones 5 the log4perl-specific filters, see Log::Log4perl::Filter, lots of examples in t/044XML-Filter.t, here's a short one: sub { /and that, too/ } So we needed to extend the log4j dtd to cover these additions. Now I could have just taken a 'steal this code' approach and mixed parts of the log4j dtd into a log4perl dtd, but that would be cut-n-paste programming. So I've used namespaces and o replaced three elements: handles #1) and accepts accepts and accepts custom cspecs for #3) o added a element (complementing the element) to handle #4) o added a root element to handle #2) o added which lets you put things like perl code into escaped CDATA between the tags, so you don't have to worry about escaping characters and quotes o added See the examples up in the "SYNOPSIS" for how all that gets used. WHY NAMESPACES I liked the idea of using the log4j DTD in situ, so I used namespaces to extend it. If you really don't like having to type instead of just , you can make your own DTD combining the two DTDs and getting rid of the namespace prefixes. Then you can validate against that, and log4perl should accept it just fine. VARIABLE SUBSTITUTION This supports variable substitution like "${foobar}" in text and in attribute values except for appender-ref. If an environment variable is defined for that name, its value is substituted. So you can do stuff like ${currentsysadmin}@foo.com REQUIRES To use this module you need XML::DOM installed. To use the log4perl.dtd, you'll have to reference it in your XML config, and you'll also need to note that log4perl.dtd references the log4j dtd as "log4j-1.2.dtd", so your validator needs to be able to find that file as well. If you don't like having to schlep two files around, feel free to dump the contents of "log4j-1.2.dtd" into your "log4perl.dtd" file. CAVEATS You can't mix a multiple param-nesteds with the same name, I'm going to leave that for now, there's presently no need for a list of structs in the config. CHANGES 0.03 2/26/2003 Added support for log4perl extensions to the log4j dtd SEE ALSO t/038XML-DOM1.t, t/039XML-DOM2.t for examples xml/log4perl.dtd, xml/log4j-1.2.dtd Log::Log4perl::Config Log::Log4perl::Config::PropertyConfigurator Log::Log4perl::Config::LDAPConfigurator (coming soon!) The code is brazenly modeled on log4j's DOMConfigurator class, (by Christopher Taylor, Ceki Gulcu, and Anders Kristensen) and any perceived similarity is not coincidental. LICENSE Copyright 2002-2013 by Mike Schilli and Kevin Goess . This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR Please contribute patches to the project on Github: http://github.com/mschilli/log4perl Send bug reports or requests for enhancements to the authors via our MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net Authors (please contact them via the list above, not directly): Mike Schilli , Kevin Goess Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. perl v5.38.0 2023-07-25 Config::DOMConfigurator(3)