Location: JWare Software » Log4Ant » Documents » How Tos » Setup Build Listeners
Setup Build Listeners
Q: How do I setup a Log4Ant Ant listener?
Using the Log4Ant Ant (build) listener is straightforward; you need to set the Log4Ant listener’s class name as the standard Ant -listener parameter. To use Log4Ant in this manner you need to ensure all of the Log4Ant libraries, including dependencies like SLF4J, are in your Ant classpath; this differs from using Log4Ant components within Ant script where you can specify the location of the Log4Ant libraries explicitly and independent of the Ant runtime’s classpath. The following snippet shows the Ant parameters you need to invoke Ant with Log4Ant as a standard listener:
ant -listener org.jwaresoftware.log4ant.listener.AntToSlf4jConduit ...
Configuring a Log4Ant listener
You can configure the Log4Ant listener just as you can configure the Log4Ant Ant components; however, the way you tell Log4Ant about your preferences is slightly different for the listener. Instead of setting the attributes of the Log4Ant components directly as you would in script, to configure the listener you must supply your attribute values in an external configuration file and then tell Log4Ant where to find that file using a special system property “jware.antxtras.defaults.log4ant.listener.conf”. Note that if you do not supply the location of the configuration file, the Log4Ant listener will look for a file named “log4ant-listener.conf” in the Ant classpath. If it finds such a file, it will load that file as its configuration.
The following snippet shows the Ant parameters you need to invoke Ant with Log4Ant as a standard listener and a custom listener configuration file located in a ‘/staging’ directory:
ant -listener org.jwaresoftware.log4ant.listener.AntToSlf4jConduit
-Djware.antxtras.defaults.log4ant.listener.conf=/staging/log4ant-listener.conf
...
Below is part of a sample Log4Ant listener configuration file. A couple of things to note: the data is described using a simple JSON format and the indentation is not important (although it’s used here to demonstrate the configuration structure). Read Listener Configuration File Format for the full description of the configuration file format.
{
"id": "Nightly",
"type": "Log4Ant.Listener",
"configuration" : {
"id": "Nightly",
"to": "MyApp.NightlyBuilds"
},
"mappings": {
"id": "Standard",
"items": [
{
"type": "indicator",
"like": "problems",
"logger": "Problems"
},
{
"type": "indicator",
"like": ".*",
"logger": "Log"
},
{
"type": "target"
"like": "^(.*)\-library$",
"loggermatch": "Libraries\.\1"
}
]
}
}
Debugging your configuration
If Log4Ant does not find or does not interpret your configuration file as you think it should, you can define the general Log4Ant “internal diagnostics” file using the system property “jware.antxtras.defaults.log4ant.debugging.logfile” to a local output file location. The listener will log information and issues to this file as it looks for and parses the file’s contents.