Announcement Announcement Module
Collapse
No announcement yet.
Log problems with Java and Grails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Log problems with Java and Grails

    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:
    Code:
    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

  • #2
    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("myAppe nder")

    What are you trying to achieve?

    Comment

    Working...
    X