LogConfigurationParser
XmlLogConfigurationParser parses log configuration files in XML format.
The root node of the configuration file must be "<logging>". Its child
nodes must correspond to set* or add* methods on the given or
default log manager: XmlLogConfigurationParser. There is one exception
to this rule.
The register-node in the root-node is treated in a special way. It can be used to register node names with specific classes. This way you do not have to specify the class-attribute multiple times for nodes with the same name.
Every node except the register- and root-nodes are beans. A bean is in this
case an instance defined in an XML format. To be able to instantiate a bean the
bean class must be set. It is thus necessary to either register node names with
bean classes:
<register name="logger" class="org.as2lib.env.log.logger.SimpleHierarchicalLogger"/>
or to specify the class-attribute in beans:
<logger class="org.as2lib.env.log.logger.TraceLogger"/>
It is also possible to set properties. Properties are basically methods that
follow a specific naming convention. If you specify an attribute named "name"
your bean class must provide a setName method. If you specify a child
node named "handler", the bean class must provide a addHandler
or setHandler method. Child nodes can themselves be beans.
The level-attribute is treated in a special way. The level corresponding to the level name is resolved with the AbstractLogLevel.forName method.
It is also possible to pass constructor arguments. You do this with the
constructor-arg-tag. Note that the order matters! As you can see in the
following example, the constructor-arg can itself be a bean.
<handler class="org.as2lib.env.log.handler.TraceHandler">
<constructor-arg class="org.as2lib.env.log.stringifier.SimpleLogMessageStringifier"/>
</handler>
If a node- or attribute-value is a primitive type it will automatically
be converted. This means the strings "true" and "false" are
converted to the booleans true and false respectively. The
strings "1", "2", ... are converted to numbers. Only if the
node- or attribute-value is non of the above 'special cases' it is used as
string.
<handler class="org.as2lib.env.log.handler.TraceHandler">
<constructor-arg class="org.as2lib.env.log.stringifier.PatternLogMessageStringifier">
<constructor-arg>false</contructor-arg>
<constructor-arg>true</contructor-arg>
<constructor-arg>HH:nn:ss.S</contructor-arg>
</constructor-arg>
</handler>
Your complete log configuration may look something like this:
<logging>
<register name="logger" class="org.as2lib.env.log.logger.SimpleHierarchicalLogger"/>
<loggerRepository class="org.as2lib.env.log.repository.LoggerHierarchy">
<logger name="com.simonwacker" level="INFO">
<handler class="org.as2lib.env.log.handler.DebugItHandler"/>
<handler class="org.as2lib.env.log.handler.TraceHandler"/>
</logger>
<logger name="com.simonwacker.MyClass" level="ERROR">
<handler class="org.as2lib.env.log.handler.SosHandler"/>
</logger>
</repository>
</logging>
or this:
<logging>
<logger level="INFO" class="org.as2lib.env.log.logger.TraceLogger"/>
</logging>
public function XmlLogConfigurationParser(logManager)
Constructs a new XmlLogConfigurationParser instance.
If logManager is null or undefined, LogManager
will be used by default.
logManager | (optional) the manager to configure with the beans specified in the log configuration XML-file |
public function parse(xmlLogConfiguration:String):Void
Parses the given xmlLogConfiguration.
xmlLogConfiguration | the XML log configuration to parse |
| IllegalArgumentException | if argument xmlLogConfiguration is
null or undefined
|
| LogConfigurationParseException | if the bean definition could not be parsed because of a malformed xml |
| ClassNotFoundException | if a class corresponding to a given class name could not be found |
| NoSuchMethodException | if a method with a given name does not exist on the bean to create |