开发者

Grails not printing messages to log file using custom appender

开发者 https://www.devze.com 2023-04-08 14:51 出处:网络
My Grails application is going to mirgate an existing database to a new database. I got some unformatted email addresses from the existing database which do not pass validation with my Grails applicat

My Grails application is going to mirgate an existing database to a new database. I got some unformatted email addresses from the existing database which do not pass validation with my Grails application because of a constraint (email:true), so I get a field error.

I want write these field errors in a log file. How can I do that? I tried a Appender in log4J. It will somehow create a log file so-call "migration.log", but it does not write any field error into this log file.

log4j = {
// Example of changing the log pattern for the default console
// appender:
//
appenders {
   // console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
   appender new FileAppender(
     name: "migrationAppender",file : "migration.log", layout: pattern(conversionPattern: "%c{2} %m%n")
   )
}

This is configration. I define a FileAppender. In my service. I just call the following:

 def foundation = new Foundation(name: name, foundationName: foundationName).addToAddresses(address).addToCommunicationMedia(email)
    foundation.validate()
    if (!foundation.hasErrors()) {
        foundati开发者_如何学Pythonon.save(flush: true)
    }
    else {
        log.error "${foundation.errors}"
    }

In the console, the errors occur and I saw a "migration.log" has been created, but somehow the file in empty.

Error 2011-09-26 09:00:29,543 [main] ERROR service.MasterDataMigrationService  - org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'de.rvgmbh.nemesis.migration.domain.partner.participant.IndividualPerson' on field 'communicationMedia[0].address': rejected value [erbelrechtsanwalt-eberl.de];


log4j = {   
    appenders {     
        rollingFile name:"file", maxFileSize:(1024*1024), file:"migration.log", maxBackupIndex:10
        environments {
            development {
                console name:'stdout'
            }
        }
    }

    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'

    environments {
        development {
            root {
                info 'file', 'stdout'
            }
            debug 'grails.app'

        }//development
        test {
            root {
                info 'file'
            }
            info  'grails.app'          
        }
        production {
            root {
                info 'file'
            }           
            info  'grails.app'      
        }
    }
}

dev: logs to console and file from debug level

test: logs to file from info level

prod: logs to file from info level

0

精彩评论

暂无评论...
验证码 换一张
取 消