Different log4j.xml file for DEV vs PROD

416 views
Skip to first unread message

J

unread,
Aug 18, 2011, 12:36:39 PM8/18/11
to play-framework
I want to load a different log4j.xml file in DEV vs PROD. I believe
this is exactly what framework ids were meant for. Unfortunately, I
haven't been able to get this to work. I found an old thread on this
(http://groups.google.com/group/play-framework/browse_thread/thread/
bdfa056c63e2b17b/cd8d2d2e3ebf0b9f) but it wasn't clear to me whether
there was a resolution.

This is what I have configured in application.conf:

application.log.path=/log4j.xml
%prod.application.log.path=/log4j.prod.xml

But when I start my app in prod mode ("play run --%prod"), it still
uses the dev version ("/log4j.xml") based on the logging output I see
(I changed the logging format in PROD in order to test if this works).

What's odd is that the I believe the "%prod.application.log.path"
property is actually being read because if I intentionally misspell /
log4j.prod.xml to /log4j.blah.xml, then the logging format changes.
But when I spell it correctly, it doesn't abide by what I have defined
in /log4j.prod.xml, instead it uses /log4j.xml!!

Really strange. Is this a bug? Anyone able to use a different
log4j.xml file depending on framework id?

Thanks,
J

notalifeform

unread,
Aug 18, 2011, 4:54:43 PM8/18/11
to play-fr...@googlegroups.com
Hi J,

We've  been using different log4j configurations for a while successfully, but using .properties files.
To help you out I tried to get it working with an XML config too, but I didn't get it to work.

Looking at the code of play.Logger, I don't think that XML configs are not supported by play! at all


on line 73, you can see that the found file (xml or properties) is always fed to the 
org.apache.log4j: PropertyConfigurator

(while an xml config should be fed to the org.apache.log4j.xml.DOMConfigurator /me thinks)

I guess your log4.xml is picked up by log4j itself.

So, to get it working you can either file a bugreport to lighthouse (which is the nice thing to do anyway)
and maybe also a pull request to fix it, or wait for the core team to fix it.

But, you can also consider to use .property files.


cheers,


Robert





J

unread,
Aug 19, 2011, 11:31:04 AM8/19/11
to play-framework
Yes, you're right. The reason why it has been working for me is
because log4j automatically looks for a file named "log4j.xml" as part
of its default initialization procedure (http://logging.apache.org/
log4j/1.2/manual.html). For dev, my file is named "log4j.xml" so it
works fine. But in prod, the file is named "log4j.prod.xml" and it
doesn't work.

Clearly a bug. I filed a ticket on lighthouse:
http://play.lighthouseapp.com/projects/57987-play-framework/tickets/1047-log4j-xml-configuration-doesnt-work

Hopefully it gets fixed in 1.3 - should be a simple fix.

Thanks!

On Aug 18, 4:54 pm, notalifeform <notalifef...@gmail.com> wrote:
> Hi J,
>
> We've  been using different log4j configurations for a while successfully,
> but using .properties files.
> To help you out I tried to get it working with an XML config too, but I
> didn't get it to work.
>
> Looking at the code of play.Logger, I don't think that XML configs are not
> supported by play! at all
>
> https://github.com/playframework/play/blob/master/framework/src/play/...

GrailsDeveloper

unread,
Aug 19, 2011, 3:45:16 PM8/19/11
to play-framework
Created pull-requests for 1.2.x and master-branch.

Niels

On 19 Aug., 17:31, J <ja...@sumall.com> wrote:
> Yes, you're right.  The reason why it has been working for me is
> because log4j automatically looks for a file named "log4j.xml" as part
> of its default initialization procedure (http://logging.apache.org/
> log4j/1.2/manual.html).  For dev, my file is named "log4j.xml" so it
> works fine.  But in prod, the file is named "log4j.prod.xml" and it
> doesn't work.
>
> Clearly a bug.  I filed a ticket on lighthouse:http://play.lighthouseapp.com/projects/57987-play-framework/tickets/1...

J

unread,
Aug 19, 2011, 5:04:31 PM8/19/11
to play-framework
Thanks! I added a comment to your pull request. I think the logic
needs to be changed so that the extension of the file is checked in
order to determine XML vs properties.

On Aug 19, 3:45 pm, GrailsDeveloper <opensourc...@googlemail.com>
wrote:

GrailsDeveloper

unread,
Aug 20, 2011, 3:16:00 AM8/20/11
to play-framework
Thanks for the review. It's difficult to create automatic tests for
this issue :-/

Niels

GrailsDeveloper

unread,
Aug 21, 2011, 9:21:57 AM8/21/11
to play-framework
So
https://github.com/playframework/play/pull/317
should be better. Specially the test.
Niels
On 20 Aug., 09:16, GrailsDeveloper <opensourc...@googlemail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages