Ehcache uses the Apache Commons Logging library for logging.
It acts as a thin bridge between logging statements in the code and logging infrastructure detected in the classpath. It will use in order of preference:
This enables ehcache to use logging infrastructures compatible with Java versions from JDK1.2 to JDK5. It does create a dependency on Apache Commons Logging, however many projects, including Hibernate, share the same dependency.
For normal production use, use the WARN level in log4J and the WARNING level for JDK1.4 logging.
Unfortunately, if Commons Logging finds the log4j library in the classpath but not configuration it will use log4j which then reports a missing configuration error message.
A simple example logging file for Log4J that will work for ehcache logging is shown below. Put it in a file called log4j.xml and put that in the root of your classpath.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="${catalina.home}/logs/hotels.log"/>
<param name="datePattern" value="'.'yyyy-MM-dd"/>
<param name="append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<logger name="net.sf.ehcache">
<!-- Other levels are: ALL, DEBUG, INFO, WARN, ERROR -->
<level value="WARN"/>
</logger>
<root>
<level value="INFO"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
Ehcache seeks to trade off informing production support developers or important messages and cluttering the log.
ERROR (JDK logging SEVERE_ messages should not occur in normal production and indicate that action should be taken.
WARNING (JDK logging WARN) messages generally indicate a configuration change should be made or an unusual event has occurred.
DEBUG (JDK logging FINE) messages are for development use. All DEBUG level statements are surrounded with a guard so that they are not executed unless the level is DEBUG.
Setting the logging level to DEBUG (JDK level FINE) should provide more information on the source of any problems. Many logging systems enable a logging level change to be made without restarting the application.