Thoughts on software development and other stuff

Archive for January 14th, 2009

Log file management in Coherence using Log4J

with 6 comments

By default Coherence logs to stdout, which means that Coherence applications deployed in a container will have these logs managed by said container (including rolling of the logs to keep the files from getting too large.) However, many Coherence grids contain JVMs that run the Coherence cache server process (DefaultCacheServer) which means that managing logs becomes an exercise for the developer or operations person.

An easy solution is simply to indicate the name of the file that Coherence should log to like this:


This is by far the simplest approach; unfortunately this means that the log will grow as long as the JVM is alive. For cache servers that have months (or years) of uptime, this will at best result in very large log files and at worse running out of disk space on the volume (not to mention if the volume happens to be the one the OS is running on.) To solve this problem, the most common approach is to use Log4J to manage the logs generated by Coherence.

Here is an example log4j.properties file that could be used for this purpose:

log4j.rootLogger=debug, file
  • In my example I chose to use the DailyRollingFileAppender. The RollingFileAppender which rolls logs over by size can also be used.
  • Note that the ConversionPattern is very simple; it only includes the log message and a newline character. This is because Coherence already prints out the timestamp, version, thread, and other information on each line.
  • The log file name is coherence-${pid}.log. The ${pid} is a system property that will contain the process id of the cache server (see script below.)

Here is the script that I used to launch the cache server:

exec java -Dtangosol.coherence.log.level=6 -Dtangosol.coherence.log=log4j \
-Dpid=$$ -cp [...] com.tangosol.net.DefaultCacheServer

Note that I am using -Dtangosol.coherence.log.level to choose the log level. The log level (debug, info, warn) can also be selected using the Log4J configuration, although using the Coherence system property provides finer grained control. The script also sets the pid system property.

Using this technique, the logs generated by Coherence are rolled, making it much easier to archive logs and (if required) to upload them to support.

Written by Patrick Peralta

January 14th, 2009 at 11:10 pm

Posted in Development