Search code examples
filegrailslogginglog4jappender

Grails - log into files via appender


This post has NOT been accepted by the mailing list yet. Hi everyone,

Thank you in advance for any help provided. I encounter a problem trying to keep track of my logs into a file, and do not understand what is wrong in the syntax I am using. Here are my settings for logging into Config.groovy:

[SNIP] 
log4j = { 
    // Example of changing the log pattern for the default console 
    // appender: 

    appenders { 
    //    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n') 

        file name: "scraperServiceLogger", 
             file: "target/scraperService.log" 
    }

    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' 
           'grails.app.' 

    error scraperServiceLogger: "grails.app.service.ScraperService"

    warn   'org.mortbay.log' 

    debug 'grails.test.*' 
} 
[/SNIP] 

Here is how I am trying to use it within my ScraperService.groovy:

[SNIP] 
 log.error "test" 
[/SNIP] 

The file I want to write in is created correctly but the logging in only displayed on console. Any help greatly appreciated :)

All the best.


Solution

  • Try using the full package to your service

    error scraperServiceLogger: "grails.app.service.com.whatever.ScraperService"