Logger/log4j problem

1,517 views
Skip to first unread message

Ilkka Huotari

unread,
Mar 15, 2011, 5:10:33 PM3/15/11
to play-fr...@googlegroups.com
I can't seem to understand how to configure logging.

How do I direct all the log messages into console as well as into a file?

Thanks.

Werner Vesterås

unread,
Mar 15, 2011, 6:01:34 PM3/15/11
to play-framework
You can see how I configure log4j in this thread:
http://groups.google.com/group/play-framework/browse_thread/thread/ba510959f241f1d5

---
Werner
Oslo, Norway

Ilkka Huotari

unread,
Mar 15, 2011, 7:26:30 PM3/15/11
to play-fr...@googlegroups.com
Thanks but I got quite a few errors from it. Of course I could have done something wrong.

I got errors like 
log4j:WARN Continuable parsing error 37 and column 23
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)".
log4j:ERROR Attempted to append to closed appender named [console].
log4j:ERROR Attempted to append to closed appender named [file].

So... still the same question... How to make log messages go into a file? This must be an easy problem to solve. 

Alison Winters

unread,
Mar 15, 2011, 7:49:46 PM3/15/11
to play-framework
Much easier to use log4j.properties than log4j.xml. Try something like
this:

log4j.rootLogger=ERROR, Rolling
log4j.logger.play=INFO

# Rolling
log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.Rolling.File=logs/application.log
log4j.appender.Rolling.MaxFileSize=1MB
log4j.appender.Rolling.MaxBackupIndex=9
log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.Rolling.layout.ConversionPattern=%p %d{DATE} [%t] m%n

Console will still go to system.out as per normal.

Alison

On Mar 15, 7:26 pm, Ilkka Huotari <ilk...@gmail.com> wrote:
> Thanks but I got quite a few errors from it. Of course I could have done
> something wrong.
>
> I got errors like
> log4j:WARN Continuable parsing error 37 and column 23
> log4j:WARN The content of element type "log4j:configuration" must match
> "(renderer*,appender*,plugin*,(category|logger)*,root?,(categoryFactory|log gerFactory)?)".

Alison Winters

unread,
Mar 15, 2011, 7:53:01 PM3/15/11
to play-framework
That should be %m%n not just m%n :)

Ilkka Huotari

unread,
Mar 15, 2011, 8:07:49 PM3/15/11
to play-fr...@googlegroups.com
Thank you Alison :) That worked. 

IMO, the documentation is a bit short on Play! site on this, and it could probably save a lot of time for a few people if there were a few more examples in documentation (with explanations even? what do these mean: log4j.rootLogger=ERROR, Rolling and log4j.logger.play=INFO and how are they related). Just a thought.

Anyway, thanks again. 

Alison Winters

unread,
Mar 15, 2011, 8:15:01 PM3/15/11
to play-framework
It would be great if the Play site showed a few more examples, I
agree. My logging configuration is very similar to the one described
here: http://www.playframework.org/documentation/1.1.1/production

Log4J is one of the most confusing Java libraries to configure I
think, and reading the manual on their website is just even more
confusing. Essentially what this config is doing is:

# by default only log ERRORs and log to the appender called 'Rolling'
log4j.rootLogger=ERROR, Rolling

# for all logs under "play" (i.e. via play.Logger class), log at INFO
level
log4j.logger.play=INFO

# set up appender called 'Rolling' with various settings
log4j.appender.Rolling.*

Alison

On Mar 15, 8:07 pm, Ilkka Huotari <ilk...@gmail.com> wrote:

Ilkka Huotari

unread,
Mar 15, 2011, 8:24:58 PM3/15/11
to play-fr...@googlegroups.com
Ahh, now I see that the logging examples were in two places, I looked at this: http://www.playframework.org/documentation/1.1.1/logs ... and I didn't think there would be another page for these as well. So that was what misled me. 

Thanks for the explanations, they helped too. 

Ilkka

Drew

unread,
Mar 16, 2011, 2:48:48 PM3/16/11
to play-framework
Just an idea, wouldn't it be better if Play used Logback by default?

http://logback.qos.ch/

Drew

On Mar 15, 5:24 pm, Ilkka Huotari <ilk...@gmail.com> wrote:
> Ahh, now I see that the logging examples were in two places, I looked at
> this:http://www.playframework.org/documentation/1.1.1/logs... and I didn't

Morten Kjetland

unread,
Mar 17, 2011, 6:21:07 AM3/17/11
to play-fr...@googlegroups.com
There is also a defect regarding loglevel:

It is fixed in master and will be included in Play 1.2

-Morten

--
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.


sas

unread,
Mar 17, 2011, 8:28:41 AM3/17/11
to play-framework
maybe make the log system pluggable?

so that you could choose what logging library to use

pablo72

unread,
Mar 21, 2011, 7:59:03 PM3/21/11
to play-fr...@googlegroups.com, Drew
Oh my god, one more logging library ????? 

Paolo

Drew Kutcharian

unread,
Mar 21, 2011, 9:32:07 PM3/21/11
to play-fr...@googlegroups.com, pablo72

Logback is intended as a successor to the popular log4j project, picking up where log4j leaves off.

Logback's basic architecture is sufficiently generic so as to apply under different circumstances. At present time, logback is divided into three modules, logback-core, logback-classic and logback-access.

The logback-core module lays the groundwork for the other two modules. The logback-classic module can be assimilated to a significantly improved version of log4j. Moreover, logback-classic natively implements the SLF4J API so that you can readily switch back and forth between logback and other logging frameworks such as log4j or java.util.logging (JUL).     

So I wouldn't really call it another logging library. In addition, Play already uses SLF4J API to connect to Log4J. 

BTW, there are only two major logging libs out there, Log4j and juli. So to add another one is not that bad. 

The funny thing is Play is another web framework that came after Struts and bunch of other terrible solutions, so based on your logic you should've stayed with Struts. What are you doing on this mailing list??????

cheers,

Drew

Morten Kjetland

unread,
Mar 22, 2011, 7:45:55 PM3/22/11
to play-fr...@googlegroups.com
I think it is a good idea to replace log4j with logback/slf4j.

I've created a ticket and intend to look into it:

-Morten


GrailsDeveloper

unread,
Mar 23, 2011, 7:54:07 AM3/23/11
to play-framework
This was discussed before in
http://groups.google.com/group/play-framework/browse_thread/thread/65c39ed581de760b/b301261dc5fb6e34?lnk=gst&q=logback#b301261dc5fb6e34.
So have these arguments in mind.

Niels

On 23 Mrz., 00:45, Morten Kjetland <m...@kjetland.com> wrote:
> I think it is a good idea to replace log4j with logback/slf4j.
>
> I've created a ticket and intend to look into it:http://play.lighthouseapp.com/projects/57987-play-framework/tickets/6...
>
> -Morten
>
> On Tue, Mar 22, 2011 at 2:32 AM, Drew Kutcharian <d...@venarc.com> wrote:
> > Fromhttp://logback.qos.ch/
> > *
>
> > Logback is intended as a successor to the popular log4j project, picking
> > up where log4j leaves off <http://logback.qos.ch/reasonsToSwitch.html>.
>
> > Logback's basic architecture is sufficiently generic so as to apply under
> > different circumstances. At present time, logback is divided into three
> > modules, logback-core, logback-classic and logback-access.
>
> > The logback-core module lays the groundwork for the other two modules. The
> > logback-classic module can be assimilated to a significantly improved
> > version of log4j. Moreover, logback-classic natively implements the SLF4J
> > API <http://www.slf4j.org> so that you can readily switch back and forth
> > between logback and other logging frameworks such as log4j or
> > java.util.logging (JUL).
> > *
Reply all
Reply to author
Forward
0 new messages