Enable debug log level on OpenSource package(Apache Commons Logging)Tag(s): Environment


Typically, Apache products are using the Apache Commons Logging.

You can enable the logging at the DEBUG level by simply setting 2 environment variable.

For example, if you have something using the Axis library to do a Web Service call, then

java.exe -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
         -Dorg.apache.commons.logging.simplelog.defaultlog=debug
         MyClassUsingAxis
will launch the program and output to stdout the debugging information.
[DEBUG] ProjectResourceBundle - -getBundle(org.apache.axis,org.apache.axis.i18n,resource,null,...)
[DEBUG] ProjectResourceBundle - -loadBundle: Ignoring MissingResourceException: Can't find bundle for base name org.apache.axis.resource, locale fr_CA
[DEBUG] ProjectResourceBundle - -Created org.apache.axis.i18n.resource, linked to parent null
[DEBUG] ProjectResourceBundle - -getBundle(org.apache.axis,org.apache.axis.utils,resource,null,...)
[DEBUG] ProjectResourceBundle - -loadBundle: Ignoring MissingResourceException: Can't find bundle for base name org.apache.axis.utils.resource, locale fr_CA
[DEBUG] ProjectResourceBundle - -org.apache.axis.i18n.resource::handleGetObject(setMsgForm)
[DEBUG] SOAPPart - -Setting current message form to: FORM_STRING (currentMessage is now <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:biBusHeader soapenv:mustUnderstand="0" xmlns:ns1="http://developer.cognos.com/schemas/bibus/3/"/>
 </soapenv:Header>
 <soapenv:Body>
  <ns2:logon soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://developer.cognos.com/schemas/contentManagerService/1">

 ...

 [DEBUG] HTTPSender - -HTTP/1.1 405 Method Not Allowed
 [DEBUG] HTTPSender - -Allow OPTIONS, TRACE, GET, HEAD
 [DEBUG] HTTPSender - -Content-Length 1564
 [DEBUG] HTTPSender - -Content-Type text/html
 [DEBUG] HTTPSender - -Server Microsoft-IIS/6.0

 ...

 
It's possible to enable only the logging for HTTP activities.
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug
-Dorg.apache.commons.logging.simplelog.log.org.apache.commons.httpclient=debug

2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "SOAPAction: urn:GeteBayOfficialTime[\r][\n]"
2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "User-Agent: Axis2[\r][\n]"
2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "Host: api.sandbox.ebay.com[\r][\n]"
2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "Content-Length: 1546[\r][\n]"
2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "Content-Type: text/xml; charset=UTF-8[\r][\n]"
2009/08/21 12:15:56:109 EDT [DEBUG] header - >> "[\r][\n]"

Apache PDFBox emits a lot of infos in debug mode.

To remove the debug mode for PDFBox :

 if (logger.isDebugEnabled()) {
    Logger logpdfengine = Logger.getLogger("org.apache.pdfbox.util.PDFStreamEngine");
    logpdfengine.setLevel(org.apache.log4j.Level.OFF);
 }

blog comments powered by Disqus