[MAGNOLIA-3396] log4j.xml in magnolia-core Created: 19/Nov/10  Updated: 04/Nov/15  Resolved: 04/Nov/15

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: 4.3.8
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Philipp Gaschütz Assignee: Philipp Bärfuss
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Java6, Tomcat6, slf4j, log4j


Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

magnolia-core includes a log4j.xml configuration file in its root directory.

If one wants to use other projects which itself use slf4j/log4j or log4j on their own and one wants to use a log4j.properties file instead of the XML based configuration, one needs to (well, first figure out, and then) add a "-Dlog4j.configuration=log4j.properties" system property to java options, since log4j will first search for XML based configuration files on the classpath and then for the .properties files.

I can't see a need for magnolia-core including a log4j.xml in its root directory, expecially because magnolia has its own Log4J configurer, which only initializes log4j if a log4j configuration property has been set in magnolia.properties. In turn, not specifying it probably means, that the developer had other intentions anyway.

Thanks
Philipp



 Comments   
Comment by Magnolia International [ 17/Dec/10 ]

Philipp,
The reason magnolia-core has its own log4j.xml is for the "boot" phase, to be able to log during the few operations before the custom log4j configurer kicks in. It's actually a fairly crucial phase, and the few statements logged in there are probably those I read the most: they print out which config files (magnolia.properties) are used. (and those config files are in turn used to determine the "final" location of the log4j.xml we want to use)

Am I guessing correctly that using "-Dlog4j.configuration=log4j.properties" will only be effective until Magnolia's custom log4j configurer reconfigures log4j ?

Given that we can't afford to not log the boot phase, what would you suggest ? I guess replacing this xml by a properties would not help, as it would conflict with your other projects anyway. (i.e an arbitrary one would be picked up depending on classpath order, I guess)

Comment by Philipp Gaschütz [ 17/Dec/10 ]

Hi Gregory,

ok, understood... makes sense.
Yes, AFAIR -Dlog4j.configuration=log4j.properties will only be effective until Magnolia reconfigures log4j. I ended up disabling Magnolia's logging completly and use sl4j with logback and the log4j bridge instead.

However, replacing the log4j.xml with a .properties file would indeed make a change, since log4j will first search the classpath for any .xml configurations and only after it has found none, will scan the classpath for a log4j.properties - and I would have thought it would do so from bottom to top (ie. the classloader would check /WEB-INF/classes first)
I am not too sure, whether slf4j will work correctly then - I don't really remember the tests I was doing. I'd setup a test case, but I am a bit short on time at the moment...

Best
Philipp

Comment by Philipp Gaschütz [ 17/Dec/10 ]

Quick ammendment:
I am pretty sure it does make a difference to move to a log4j.properties file.

If you include your own log4j.properties file, this would be picked up before the log4j.properties included in magnolia.
If you then set the log4j configuration in magnolia.properties to the one you provided on the classpath, you should be fine with other projects running log4j. If you set log4j configuration location in magnolia.properties to [null] you should be fine running slf4j.

See http://www.slf4j.org/legacy.html#log4j-over-slf4j --> "When does it not work"

At the end of the day, it's not too much of an urgent issue, I eventually simply switched to logback and things worked fine. But it took me quite some time to figure out where my log messages were going, until I found out that they were swallowed due to the magnolia initialization process.

Comment by Magnolia International [ 21/Dec/10 ]

Thanks for the insight.
We actually also consider moving to logback - see MAGNOLIA-3351. But that would probably not help you ?

I wonder if there is a way to have the boot phase logging less intrusive. Any idea ?

Comment by Michael Mühlebach [ 04/Nov/15 ]

Given the thousands of other issues we have open that are more highly requested, we won't be able to address this issue in the foreseeable future. Instead we will focus on issues with a higher impact, and more votes.
Thanks for taking the time to raise this issue. As you are no doubt aware this issue has been on our backlog for some time now with very little movement.
I'm going to close this to set expectations so the issue doesn't stay open for years with few updates. If the issue is still relevant please feel free to reopen it or create a new issue.

Generated at Mon Feb 12 03:46:05 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.