Location: JWare Software » Log4Ant » Documents » How Tos » Debug Log4Ant
Debug Log4Ant
Q: How do I debug Log4Ant itself?
What happens when Log4Ant itself seems to be broken and you need to get additional information about what it’s doing? In addition to the usual Ant debugging facilities (-debug etc.), you can tell Log4Ant to write additional information to a specific file. Because Log4Ant is itself part of the Ant logging facility, it’s use of that facility to report on its internals is limited. Instead, Log4Ant has to do its low-level tracing against something outside the Ant and SLF4J system completely.
To activate Log4Ant’s low level logging you need to use the system property “jware.antxtras.defaults.log4ant.debugging.logfile” to define the file where Log4Ant can write its information. Log4Ant will try to write information to this file, creating the file if necessary. Note that Log4Ant will write copious amounts of information (including EACH received Ant event, EACH broadcast SLF4J event, etc.), so you should not use this option as a standard setting for your scripts– it can slow down the script's execution significantly even if the script is small.
Turn on custom Log4Ant logging
The following snippet shows the Ant parameters to activate and define Log4Ant internal logging. In this example, Log4Ant will write additional information to the /var/logs/log4ant-debug.log file.
ant -Djware.antxtras.defaults.log4ant.debugging.logfile=/var/logs/log4ant-debug.log ...
Log4Ant logging event feedback
The vast majority of the Log4Ant debug messages you will get are recording the Ant logging messages that the system has received from Ant and passed through to SLF4J (and presumably to your chosen logging system). These Log4Ant diagnostic messages will look like the snippet below. If everything is working in Log4Ant, there are always two messages for each Ant logging event: first is the received event (E@<id>: Captured(<n>,<level>)⇒ <message>), and second is the broadcast event to SLF4J (Broadcasting to ‘<logger>’ ⇒ <message>). From this logged information you can determine what Ant has given to Log4Ant, and how Log4Ant has mapped that event into a logger based on your configuration (or lack thereof). If you see your expected message broadcast by Ant and Log4Ant– but it’s not showing up in your logging system, then you need to check your logging system configuration; most likely, the message is being filtered or there is some other configuration mis-match.
... E@12539221: Captured(0,verbose)=> Complete build sequence is [doHelloWorld, ] Broadcasting to 'Trace.AntToSlf4jTest' => Complete build sequence is [doHelloWorld, ] E@3865497: Captured(0,info)=> HELLO WORLD! Broadcasting to 'Build.AntToSlf4jTest.doHelloWorld' => HELLO WORLD! E@21467514: Captured(0,info)=> Target name = doHelloWorld Broadcasting to 'Build.AntToSlf4jTest.doHelloWorld' => Target name = doHelloWorld ...
Log4Ant execution listener feedback
If you’re using Log4Ant as a standard Ant execution listener (wrapping pre-existing Ant scripts for instance), you will also see information about configuration lookup and parsing that the Log4Ant listener performs. That information looks like the the output shown below. If Log4Ant is not finding your configuration, or is having problems reading and/or parsing the file, it will record this information here.
[DEBUG] Initializing AntToSlf4jConduit configuration [DEBUG] Looking for default configuration file 'log4ant-listener.conf' in classpath [DEBUG] [!] FOUND... [DEBUG] Parsing JSON formatted file [DEBUG] [!] Reading listener configuration [DEBUG] Setting listener 'to' logger as JWare.Log4Ant [DEBUG] [!] Finished reading configuration [DEBUG] [!] Reading listener mappings [DEBUG] Setting mappings id to Standard [DEBUG] Found mappings items [size= 3] [DEBUG] Reading item[0] type = indicator [DEBUG] + Added item[0] OK [DEBUG] Reading item[1] type = indicator [DEBUG] + Added item[1] OK [DEBUG] Reading item[2] type = target [DEBUG] + Added item[2] OK [DEBUG] [!] Finished reading mappings