Breaking News
Home / Java / Java Snippets / How do disable low level logging for Apache Common Packages?

How do disable low level logging for Apache Common Packages?

Answer

Log4j can be configured via a properties file or an xml file. The below is an example of configuring Log4j using a properties file. Generally for simplicity the file name is called as log4j.properties but can be anything.

Typical Configuration

log4j.rootLogger=trace,R

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=../logs/server.log
log4j.appender.R.MaxFileSize=1024KB
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d[%t]%-5p%c{1}%x-%m%n

Disable Apache Low Level Logging

Adding the following in above log4j.properties to disable DEBUG or TRACE level logging originating from these Apache common packages.

log4j.category.org.apache.commons.httpclient=INFO
log4j.category.org.apache.commons=INFO
log4j.category.org.apache.commons.digester=INFO
log4j.category.org.apache.commons.httpclient=INFO

To disable Apache Axis logging further add:

log4j.category.org.apache.axis=INFO

Like wise to disable Apache Struts logging you can add:

log4j.category.org.apache.struts=ERROR

Please make sure this file log4j.properties is in the class path and specify the file name as a value to environment variable -Dlog4j.properties=log4j.properties in your startup script , rest it will configure automatically.[pb_builder]

Check Also

How to progamatically get the Java version?

Snippet The key here is to use the system property java.version and get minor and …

Leave a Reply