About Me

Mein Bild
Freelancing software developer / architect, mobile geek. Topics: Software technologies (java, groovy, agile), politics, web, science, green, mobile, android.
Homepage: www.tutaona.com

"The absence of limitations is the enemy of art." - Orson Welles

Mittwoch, 27. Juni 2012

Logging Config for Grails 2.0

Finally I developed a good logging config. It debug logs your classes to development.log, grails stuff info logging to grails.log. Test logging goes into test.log and for production it logs nothing to the console (= catalina.out) and info logging to a daily rolling logfile.
import org.apache.log4j.*
environments {
  development {
    log4j = {
      appenders {
        file name: 'grailsfile', file: 'target/grails.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
        file name: 'rootlog', file: 'target/root.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
        file name: 'devfile', file: 'target/development.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
      }
      root { error 'stdout', 'rootlog' }
      info additivity: false, grailsfile: 'org.codehaus.groovy.grails, com.orientechnologies'//.commons'
      all additivity: false, devfile: [
        'grails.app.controllers.my.package',
        'grails.app.domain.my.package',
        'grails.app.services.my.package',
        'grails.app.taglib.my.package',
        'grails.app.conf.my.package',
        'grails.app.filters.my.package',
        'my.package'
      ]
    }
  }

  test {
    log4j = {
      appenders {
        file name: 'grailsfile', file: 'target/grails.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
        file name: 'rootlog', file: 'target/root.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
        file name: 'testfile', file: 'target/test.log', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
      }
      root { error 'stdout', 'rootlog' }
      info additivity: false, grailsfile: 'org.codehaus.groovy.grails'
      all additivity: false, testfile: [
        'grails.app.controllers.my.package',
        'grails.app.domain.my.package',
        'grails.app.services.my.package',
        'grails.app.taglib.my.package',
        'grails.app.conf.my.package',
        'grails.app.filters.my.package',
        'my.package'
      ]
    }
  }

  production {
    grails.logging.jul.usebridge = false
    log4j = {
      appenders {
        console name: 'console', layout: pattern(conversionPattern: "[%d{ISO8601}]\t%p\t%c{2}\t%m%n")
        appender new org.apache.log4j.DailyRollingFileAppender(
          name:"logfile", fileName:"./my.application.log",
          layout:pattern(conversionPattern: '[%d{ISO8601}]\t%p\t%c{2}\t%m%n')
        )
      }
      // set this to debug if debugging on a dev server
      info 'grails.app.controllers.my.package',
        'grails.app.domain.my.package',
        'grails.app.services.my.package',
        'grails.app.taglib.my.package',
        'grails.app.conf.my.package',
        'grails.app.filters.my.package',
        'my.package'
     
      info 'org.codehaus.groovy.grails.commons', 'com.orientechnologies'

      root {
        error 'logfile'
        additivity = true
      }
    }
  }
}

Keine Kommentare:

Kommentar veröffentlichen