Changes in log4j.properties are ignored, when running sl4fj under Tomcat

Lately, I run into this very subtle bug:
my logs were all visible, like intended and configured in log4j.properties (or log4j.xml), when I fired up my web-application in development-mode under Jetty with mvn jetty:run.
But if I installed the application on the production-server, which uses a Tomcat 7 servlet-container, no special logger-configuration where picked up from my configuration-file.
But – very strange – my configuration-file was not ignored completely.
The appender-configuration and the log-level from the root-logger where picked up from my configuration-file.
Only all special logger-configuration were ignored.

Erroneous logging-configuration

Here is my configuration, as it was when I run into the problem:

  • Logging was done with slf4j
  • Logs were written by log4j with the help of slf4j-log4j12
  • Because I was using some legacy libraries, that were using other logging-frameworks, I had to include some bridges to be able to include the log-messages, that were logged through this frameworks in my log-files.
    I used: jcl-over-slf4j and log4j-over-slf4j.

Do not use sl4fj-log4j and log4j-over-slf4j together!

As said before:
All worked as expected while developing under Jetty and in production under Tomcat, only special logger-confiugrations where ignored.

Because of that, it took me quiet a while and a lot of reading, to figure out, that this was not a configuration-issue, but a clash of libraries.
The cause of this strange behaviour were the fact, that one must not use the log4j-binding slf4j-log4j12 and the log4j-bridge log4j-over-slf4j together.

This fact is quiet logically, because it should push all your logging-statements into an endless loop, where they are handed back and forth between sl4fj and log4j as stated in the sl4fj-documentation here.
But if you see all your log-messages in development and in production only the configuration behaves strangley, this mistake is realy hard to figure out!
So, I hope I can save you some time by dragging your attention to this.

The solution

Only the cause is hard to find.
The solution is very simple:
Just switch from log4j to logback.

There are some more good reasons, why you should do this anyway, over which you can learn more here.

hibernate4-maven-plugin 1.0.4 released!

We finally did it.
Today we released the version 1.0.4 of hibernate4-maven-plugin to Central!

This release mainly is a library-upgrade to version 4.3.1.Final of hibernate.
It also includes some bug-fixes provided by the community.
Please see the release notes for details.

It took us quiet some time, to release this version and we are sorry for that.
But with a growing number of users, we are becoming more anxious to break some special use-cases.
Because of that, we started to add some integration-tests, to avoid that hassle, and that took us some time…

If you have some special small-sized (example) use-cases for the plugin, we would appreciate it, if you would provide them to us, so we can add them es additional integration-tests.

Release notes:


commit f3dabc0e6e3676244986b5bbffdb67d427c8383c
Author: Kai Moritz
Date: Mon Jun 2 10:31:12 2014 +0200

[maven-release-plugin] prepare release hibernate4-maven-plugin-1.0.4

commit 856dd31c9b90708e841163c91261a865f9efd224
Author: Kai Moritz
Date: Mon Jun 2 10:12:24 2014 +0200

Updated documentation

commit 64900890db2575b7a28790c5e4d5f45083ee94b3
Author: Kai Moritz
Date: Tue Apr 29 20:43:15 2014 +0200

Switched documentation to xhtml, to be able to integrate google-pretty-print

commit bd78c276663790bf7a3f121db85a0d62c64ce38c
Author: Kai Moritz
Date: Tue Apr 29 19:42:41 2014 +0200

Fixed bug in site-configuration

commit 1628bcf6c9290a729352215ee22e5b48fa628c4c
Author: Kai Moritz
Date: Tue Apr 29 18:07:44 2014 +0200

Verifying generated SQL in integration-test hibernate4-maven-plugin-envers-sample

commit 25079f13c0eda6807d5aee67086a21ddde313213
Author: Kai Moritz
Date: Tue Apr 29 18:01:10 2014 +0200

Added integration-test provided by Erik-Berndt Scheper

commit 69458703cddc2aea1f67e06db43bce6950c6f3cb
Author: Kai Moritz
Date: Tue Apr 29 17:52:17 2014 +0200

Verifying generated SQL in integration-test schemaexport-example

commit a53a2ad438038084200a8449c557a41159e409dc
Author: Kai Moritz
Date: Tue Apr 29 17:46:05 2014 +0200

Added integration-test provided by Guido Wimmel

commit f18f820198878cddcea8b98c2a5e0c9843b923d2
Author: Kai Moritz
Date: Tue Apr 29 09:43:06 2014 +0200

Verifying generated SQL in integration-test hib-test

commit 4bb462610138332087d808a62c84a0c9776b24cc
Author: Kai Moritz
Date: Tue Apr 29 08:58:33 2014 +0200

Added integration-test provided by Joel Johnson

commit c5c4c7a4007bc2bd58b850150adb78f8518788da
Author: Kai Moritz
Date: Tue Apr 29 08:43:28 2014 +0200

Prepared POM for integration-tests via invoker-maven-plugin

commit d8647fedfe936f49476a5c1f095d51a9f5703d3d
Author: Kai Moritz
Date: Tue Apr 29 08:41:50 2014 +0200

Upgraded Version of maven from 3.0.4 to 3.2.1

commit 1979c6349fc2a9e0fe3f028fa1cc76557b32031c
Author: Frank Schimmel
Date: Wed Feb 12 15:16:18 2014 +0100

Properly support constraints expressed by bean validation (jsr303) annotations.

* Access public method of package-visible TypeSafeActivator class without reflection.
* Fix arguments to call of TypeSafeActivator.applyRelationalConstraints().
* Use hibernate version 4.3.1.Final for all components.
* Minor refactorings in exception handling.

commit c3a16dc3704517d53501914bb8a0f95f856585f4
Author: Kai Moritz
Date: Fri Jan 17 09:05:05 2014 +0100

Added last contributors to the POM

commit 5fba40e135677130cbe0ff3c59f6055228293d92
Author: Mark Robinson
Date: Fri Jan 17 08:53:47 2014 +0100

Generated schema now corresponds to hibernate validators set on the beans

commit aedcc19cfb89a8b387399a978afab1166be816e3
Author: Kai Moritz
Date: Thu Jan 16 18:33:32 2014 +0100

Upgrade to Hibernate 4.3.0.Final

commit 734356ab74d2896ec8d7530af0d2fa60ff58001f
Author: Kai Moritz
Date: Thu Jan 16 18:23:12 2014 +0100

Improved documentation of the dependency-scanning on the pitfalls-page

commit f2955fc974239cbb266922c04e8e11101d7e9dd9
Author: Joel Johnson
Date: Thu Dec 26 14:33:51 2013 -0700

Text cleanup, spelling, etc.

commit 727d1a35bb213589270b097d04d5a1f480bffef6
Author: Joel Johnson
Date: Thu Dec 26 14:02:29 2013 -0700

Make output file handling more robust

* Ensure output file directory path exists
* Anchor relative paths in build directory

commit eeb182205a51c4507e61e1862af184341e65dbd3
Author: Joel Johnson
Date: Thu Dec 26 13:53:37 2013 -0700

Check that md5 path is file and has content

commit 64c0a52bdd82142a4c8caef18ab0671a74fdc6c1
Author: Joel Johnson
Date: Thu Dec 26 11:25:34 2013 -0700

Use more descriptive filename for schema md5

commit ba2e48a347a839be63cbce4b7ca2469a600748c6
Author: Joel Johnson
Date: Thu Dec 26 11:20:24 2013 -0700

Offer explicit disable option

Use an explicit disable property, but still default it to test state

commit e44434257040745e66e0596b262dd0227b085729
Author: Kai Moritz
Date: Fri Oct 18 01:55:11 2013 +0200

[maven-release-plugin] prepare for next development iteration