Logging configuration (Logback)
Starting with server release 3.0.4.9, Mercury DB (HgDB) 3.0 logs through SLF4J with Logback 1.2.13 as the backend. The old log4j 1.x library is no longer used. This page describes what changed in an installation and how to migrate your own logging configuration.
What changed
| Before | Now | |
|---|---|---|
| Backend | log4j 1.2.14 (slf4j-log4j12) | Logback 1.2.13 (logback-classic, logback-core) |
| Configuration file | log4j.properties | logback.xml (XML) |
| JVM option | -Dlog4j.configuration=file://.../log4j.properties and -Dlog4j.debug=true | -Dlogback.configurationFile=file://.../logback.xml |
| Calls to the log4j API from libraries | log4j | log4j-over-slf4j bridge, which redirects them to SLF4J |
commons-logging | commons-logging 1.2 | spring-jcl, which is already in the server and routes the calls to SLF4J |
A file log4j.properties is not read anymore. If you have your own logging settings, you have to write them again in logback.xml.
Libraries of the server
In the library directory of the application (apache-tomcat/mercury/lib in a standard installation):
- remove:
log4j-1.2.14.jar(or another log4j 1.x),slf4j-log4j12-*.jar,commons-logging-*.jar, - add:
logback-classic-1.2.13.jar,logback-core-1.2.13.jarandlog4j-over-slf4j-1.7.36.jar, - keep:
slf4j-api-1.7.36.jarandspring-jcl-*.jar.
An upgrade replaces the whole server (libraries, applications and the installation package), so the new set of libraries is part of the delivery.
Configuration files
The server has two configuration files, both in the format of Logback:
apache-tomcat/lib/logback.xmldefines the appenders of the Tomcat logs (catalina,localhost,manager,host-manager) and of the Mercury application (mercury-ws-app.log),apache-tomcat/mercury/classes/mercury-ws-app/logback.xmlis the configuration of the application.
If you keep your own versions of these files, convert them by hand. The most frequent elements correspond as follows:
log4j 1.x (log4j.properties) | Logback (logback.xml) |
|---|---|
log4j.rootLogger=INFO, A | <root level="INFO"><appender-ref ref="A"/></root> |
log4j.category.pro.ibpm.mercury=DEBUG | <logger name="pro.ibpm.mercury" level="DEBUG"/> |
ConsoleAppender | ch.qos.logback.core.ConsoleAppender |
RollingFileAppender (MaxFileSize, MaxBackupIndex) | RollingFileAppender with FixedWindowRollingPolicy and SizeBasedTriggeringPolicy |
DailyRollingFileAppender (DatePattern) | RollingFileAppender with TimeBasedRollingPolicy |
PatternLayout (%d{ISO8601} %-5p [%F:%L] : %m%n) | <encoder><pattern> with the same pattern |
<appender name="MERCURY" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/../logs/mercury-ws-app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${catalina.base}/../logs/mercury-ws-app.log.%i</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>20</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>7024KB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{ISO8601} %-5p [%F:%L] : %m%n</pattern>
</encoder>
</appender>
FixedWindowRollingPolicy in Logback keeps at most 21 rolled files, while log4j allowed any number (the standard configuration used MaxBackupIndex=100). The standard configuration keeps now 20 files of 7024 KB. If you need a longer history, use SizeAndTimeBasedRollingPolicy with the maxHistory and totalSizeCap parameters; it changes the names of the rolled files.
JVM options
In setenv.sh (or setenv.bat) of Tomcat replace the log4j options with:
-Dlogback.configurationFile=file://${TOMCAT_HOME}/lib/logback.xml
-Dorg.jboss.logging.provider=slf4j
The second option makes Hibernate (JBoss Logging) log through SLF4J, instead of choosing the backend itself.
Command-line tools
The command-line tools of the installation package read the configuration from the file config/logback.xml of the package (earlier config/log4j.properties).
Checking
After the start of the server, call the service for changing logging levels. In the result, the field backend has the value logback.
IBM BPM
Inside IBM BPM, logging is provided by BPM itself (its own log4j.jar and slf4j-api). Libraries that run in BPM use only the SLF4J API, so do not install Logback or log4j-over-slf4j in the directory of BPM libraries. The Logback libraries are meant for the Mercury DB server.