I am trying to customize my Grails application's logging config, but the appenders (and their layout patterns) are seemingly 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 actually gets considered by Log4J (e.g., if I comment the debug and trace lines for hibernate then the logging of Hibernate statements stops as expected).
But I have been trying different versions of the appenders section and none of it seems to be considered, actually the format applied to the console is something that only includes the message itself (e.g., if I write
log.info("test")
in code I will get
test
in console and nothing in the log file.
I added "debug=true" to the section, and also set 'org.apache.log4j' to trace but it seemed to change nothing.
It's probably something trivial but I cannot figure it out. :/
I'm using Grails 2.3.0RC2.
So I did 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 while this is an improvement (my layout isn't ignored) it also leads to everything being logged 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
Actually this happens even if I comment the "root" section out.
Try applying the apender to your info level
log4j = {
...
root{
info 'stdout'
}
...
}
I think what you are missing is loggers do not know where to send the messages.
Generally you can do that by
error myAppender: "grails.app.controllers.BookController",
myFileAppender: ["grails.app.controllers.BookController",
"grails.app.services.BookService"],
rollingFile: "grails.app.controllers.BookController"
or define it at the root level for all levels. Take a look at Documentation 4.1.2 Logging
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')
}
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' , additivity: false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With