log4j.properties per environment - DEV vs PROD

2,150 views
Skip to first unread message

grandfatha

unread,
Nov 30, 2010, 6:03:16 AM11/30/10
to play-framework
I would like to conditionally enable debug-logging for some of my
controllers in the DEV environment. For such fine-grained control, it
is required to have a log4j.properties file, because the play.Logger
at DEBUG level will output everything at DEBUG level and not just some
of my controllers. I would like to have access to log4j logging
configuration hell, if you will :)


My problem is: If I only have one log4j file, I occasionally start to
forget to reset the DEBUG level for those controllers to INFO, which
means that I get a bloated log file in production.


The ideal solution would be to have per-environment specific
log4j.properties files. Is this possible with Play?

Guillaume Bort

unread,
Nov 30, 2010, 6:40:11 AM11/30/10
to play-fr...@googlegroups.com
It should be possible by specifying:

%dev.application.log.path=/log4j-dev.properties
%prod.application.log.path=/log4j-prod.properties

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

grandfatha

unread,
Nov 30, 2010, 8:25:51 AM11/30/10
to play-framework
Thats what I tried at first and it did not work. I also tried
different variations and all of them failed:

%dev.application.log.path=log4j-dev.properties
%prod.application.log.path=log4j-prod.properties

%dev.application.log.path=conf/log4j-dev.properties
%prod.application.log.path=conf/log4j-prod.properties

%dev.application.log.path=/conf/log4j-dev.properties
%prod.application.log.path=/conf/log4j-prod.properties

It only works if I comment out the log path setting and have a simple
log4j.properties file in my conf folder.

-----------------------------------
Sample Code:
-----------------------------------

import org.apache.log4j.Logger;

public class TestController extends Controller {

private static final Logger log =
Logger.getLogger(TestController.class);

public static void test(){

log.debug("test"); // does not work
log.info("test-info");// does not work
play.Logger.info("play-logger-info"); // works
play.Logger.log4j.debug("play-loger-debug"); // does not work

play.Logger.log4j.getLogger(TestController.class).debug("GNAAA !!"); //
does not work
}

-----------------------------------
Sample Config for DEV:
-----------------------------------
log4j.rootLogger=ERROR, Console

log4j.logger.play=INFO

log4j.logger.controllers.TestController=DEBUG

# Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m
%n

Guillaume Bort

unread,
Nov 30, 2010, 8:59:23 AM11/30/10
to play-fr...@googlegroups.com
Need to check why. Please report the bug, and if you can try to debug
to see what is the problem.

grandfatha

unread,
Nov 30, 2010, 9:10:24 AM11/30/10
to play-framework
I am trying to debug right now to make sure that I absolutely made no
mistake. Gonna post results later.

grandfatha

unread,
Nov 30, 2010, 10:19:14 AM11/30/10
to play-framework
If I do:

application.log.path=/log4j-dev.properties
%prod.application.log.path=/log4j-prod.properties

instead of

%dev.application.log.path=/log4j-dev.properties
%prod.application.log.path=/log4j-prod.properties

I get the following results:

log.debug("test"); // works now
log.info("test-info");// works now
play.Logger.info("play-logger-info"); // still works
play.Logger.log4j.debug("play-loger-debug"); // does not work, but
probably does not matter


Because of ongoing database migrations, I canot test in prod mode
right now, but I guess it would work.

Guillaume Bort

unread,
Dec 1, 2010, 7:32:26 AM12/1/10
to play-fr...@googlegroups.com
%dev.application.log.path=/log4j-dev.properties

Will only work if your current framework id is dev. To set it, use the
'play id' command.

Reply all
Reply to author
Forward
0 new messages