I want to have log output of my packages or classes in a specific appender. But everything is printed out to the root-logger.
Here is my config:
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
file name:'grailslog', file:'grails.log', threshold:org.apache.log4j.Level.DEBUG
file name:'mylog', file:'mylog.log', threshold:org.apache.log4j.Level.DEBUG
}
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'
warn 'org.mortbay.log'
debug 'grails.app'
debug mylog: 'my.package', additivity: true
root {
error 'grailslog'
additivity = true
}
}
I also tried this syntax:
log4j = {
appender.stdout = "org.apache.log4j.ConsoleAppender"
appender.'stdout.layout'="org.apache.log4j.PatternLayout"
appender.'stdout.layout.ConversionPattern'='[%r] %c{2} %m%n'
appender.mylog= "org.apache.log4j.DailyRollingFileAppender"
appender.'mylog.File' = "mylog.log"
appender.'mylog.layout' = "org.apache.log4j.PatternLayout"
appender.'mylog.layout.ConversionPattern' = '%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n'
appender.grailslog = "org.apache.log4j.DailyRollingFileAppender"
appender.'grailslog.File' = "grails.log"
appender.'grailslog.layout' = "org.apache.log4j.PatternLayout"
appender.'grailslog.layout.ConversionPattern' = '%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n'
rootLogger="error,stdout,grailslog"
logger {
grails="info,stdout,grailslog"
my.package="debug,mylog"
}
}
But this doesn't work any more with the current grails version.
A short update:
Grails has a new Documentation for the log-DSL (domain specific language). Therefore the code above has a wrong syntax.
They wrote:
... the name of the logger is 'grails.app.(type).(className)' ...
I managed to use my other log file.
Instead of using a logger with the package name I used a custom name and initialized my logger with this.
debug mylog: 'myLog', additivity: true
[...]
def log = Logger.getLogger("myLog")
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