log4j.properties vs log4j.xml

Have a look at the JavaDoc. The documentation of the PropertyConfiguratorClass (log4j.properties) points out that The PropertyConfigurator does not handle the advanced configuration features supported by the DOMConfigurator such as support custom ErrorHandlers, nested appenders such as the AsyncAppender, etc. So the DOMConfigurator (log4j.xml) offers advanced options. Beside that you can have (at least a … Read more

Where to place log4j.xml

It finds the log4j.xml using the CLASSPATH. If log4j doesn’t find any config file, it will send an error to the console. If you don’t see any such error then it is likely that it is finding a config file which may not be the one you are editing. There is a command-line option to … Read more

Log4j : Multiple loggers, levels and appenders

This problem can be solved in two parts. 1. Prevent duplicate log messages The log messages were written twice because we listed the FOO appender in both the rootLogger and the log4j.logger.foobar category. So we must remove the appender and only define the logging level in category: log4j.rootLogger = WARN, FOO, BAR log4j.logger.foobar = INFO … Read more

How to log Apache CXF Soap Request and Soap Response using Log4j?

You need to create a file named org.apache.cxf.Logger (that is: org.apache.cxf file with Logger extension) under /META-INF/cxf/ with the following contents: org.apache.cxf.common.logging.Log4jLogger Reference: Using Log4j Instead of java.util.logging. Also if you replace standard: <cxf:bus> <cxf:features> <cxf:logging/> </cxf:features> </cxf:bus> with much more verbose: <bean id=”abstractLoggingInterceptor” abstract=”true”> <property name=”prettyLogging” value=”true”/> </bean> <bean id=”loggingInInterceptor” class=”org.apache.cxf.interceptor.LoggingInInterceptor” parent=”abstractLoggingInterceptor”/> <bean id=”loggingOutInterceptor” … Read more

How to initialize log4j properly?

Log4j by default looks for a file called log4j.properties or log4j.xml on the classpath. You can control which file it uses to initialize itself by setting system properties as described here (Look for the “Default Initialization Procedure” section). For example: java -Dlog4j.configuration=customName …. Will cause log4j to look for a file called customName on the … Read more