Allan
Allan

Reputation: 31

grails does not write to log file

I have the following in my grails config log4j section:

appenders {
  file name: "usageAppender", file: "${logDirectory}/onetract3.log"
}

root { error 'stdout', 'usageAppender' }

info usageAppender: "grails.app.services.com.onetract.onetract.UserService"

The file "onetract3.log" is successfully created, however nothing is written to this file.

I can see in the console that the info is handled correctly.

2014-03-09 20:09:06,912 [http-bio-8080-exec-5] INFO  onetract.UserService  - New candidateRelations for: com.onetract.onetract.Person : 18

Grails version is 2.3.5

Any ideas on why this isn't getting written to the log file?

Edit: 10.03.1014, set additivity to false.

info additivity: false 
    usageAppender: "grails.app.services.com.onetract.onetract.UserService" 

Upvotes: 0

Views: 1434

Answers (2)

Allan
Allan

Reputation: 31

The problem was due to the following entry:

file: "${logDirectory}/onetract3.log"

Before the application is running, this works, afterwards not.

The workaround is to explicitly tell the appender where the file is, i.e.

file: "logs/onetract/onetract3.log"

This then works.

Upvotes: 1

Rohit Raina
Rohit Raina

Reputation: 336

use this

// Example of changing the log pattern for the default console appender:
//
//appenders {
//    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

    appenders {
        rollingFile  name:'myLogFile', 
        file:'log/myLogFile.log', 
        threshold: org.apache.log4j.Level.ALL, 
        maxFileSize:10485760
    }
    root {
        error 'myLogFile'
        additivity = true
    }

   info "grails.app","com.test"
   warn "grails.app","com.test"
   debug "grails.app","com.test"
   error "grails.app","com.test"
   fatal "grails.app","com.test"
   trace "grails.app","com.test"

   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'

Upvotes: 1

Related Questions