I'm trying to set up the Grails application logging configuration, but the applications (and their layout patterns) seem to be ignored.
In Config.groovy:
log4j = { appenders { console name: 'stdout', layout: pattern(conversionPattern: '%c{2} %m%n') file name: 'fileLogger', file: 'application.log', layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{1} - %m%n') } error 'org.codehaus.groovy.grails.web.servlet', // controllers 'org.codehaus.groovy.grails.web.pages', // GSP 'org.codehaus.groovy.grails.web.sitemesh', // layouts 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping 'org.codehaus.groovy.grails.web.mapping', // URL mapping 'org.codehaus.groovy.grails.commons', // core / classloading 'org.codehaus.groovy.grails.plugins', // plugins 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration 'org.springframework', 'org.hibernate', 'net.sf.ehcache.hibernate' info 'grails.app' debug 'org.hibernate.SQL' trace 'org.hibernate.type' }
The logger section is actually considered by Log4J (for example, if I comment on debug and trace lines for sleep mode, the recording of Hibernate statements stops as expected).
But I tried different versions of the appenders section, and none of them seem to be considered, in fact, the format applied to the console is that it includes only the message itself (for example, if I write
log.info("test")
in code i will get
test
in the console and nothing in the log file.
I added "debug = true" to the section, and also set 'org.apache.log4j' to track, but did not change anything.
This is probably something trivial, but I canβt understand.: /
I am using Grails 2.3.0RC2.
So, I did this, as Alidad suggested, and switched my configuration to:
log4j = { appenders { console name: 'stdout', layout: pattern(conversionPattern: '%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%t] %-5p %c{1}:%L %x - %m%n') } root { info 'stdout' } error stdout: 'org.codehaus.groovy.grails.web.servlet', // controllers 'org.codehaus.groovy.grails.web.pages', // GSP 'org.codehaus.groovy.grails.web.sitemesh', // layouts 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping 'org.codehaus.groovy.grails.web.mapping', // URL mapping 'org.codehaus.groovy.grails.commons', // core / classloading 'org.codehaus.groovy.grails.plugins', // plugins 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration 'org.springframework', 'org.hibernate', 'net.sf.ehcache.hibernate' info stdout: 'grails.app' }
However, although this is an improvement (my layout is not ignored), it also causes everything to be written twice:
2013-09-08 18:00:19,447 +0100 [localhost-startStop-1] INFO BootStrap:152 - Init completed Init completed 2013-09-08 18:00:19,641 +0100 [localhost-startStop-1] INFO NimbleBootStrap:152 - Creating default user account with username:user Creating default user account with username:user
In fact, this happens even if I comment on the "root" section.