PDA

View Full Version : Log problems with Java and Grails



toriton
Sep 15th, 2010, 07:28 AM
Hi all, i have a little problem about how retrieve an appender from Log4j configured via Config.groovy.
While the appender does its job without problems for groovy's classes under grails.app.<artefactType>, the same appender don't work if i use this statement:
Logger.getLogger("name").

This is how it is configured in Config.groovy file:


log4j = {

appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
appender new DailyRollingFileAppender(name:"myAppender",layout:pattern(conversionPattern: '[%t]%d{dd MMM yyyy HH:mm:ss} %-5p %c - %m%n'),file:"C:\\myapp\\logs\\myapp.log",datePattern:"'.'yyyy-MM-dd")
}
root{
info 'stdout'
additivity = true
}

info myAppender:'grails.app'
error myAppender:'StackTrace'

}

So when i use the code:
Logger.getLogger("myAppender") , i was expected to retrieve the same instance logger.
Instead the logger is totally a new one,instanciated at runtime from log4j.

What's wrong?

thanks in advance for any tips!
T.

P.S. Using grails 1.2.0

pledbrook
Sep 23rd, 2010, 05:16 PM
You cannot access appenders via the getLogger() method because they are different to loggers. I would check out the Log4J documentation for more information.

You can probably use Logger.getLogger("grails.app").getAppender("myAppender")

What are you trying to achieve?