views:

27

answers:

1

Hi, I want to have log output of my packages or classes in a specific appender. But everything is printed out to the root-logger.

Here is my config:

log4j = {
    appenders {
        console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
        file name:'grailslog', file:'grails.log', threshold:org.apache.log4j.Level.DEBUG
        file name:'mylog', file:'mylog.log', threshold:org.apache.log4j.Level.DEBUG
    }

    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'

    debug  'grails.app'

    debug  mylog: 'my.package', additivity: true

    root {
      error 'grailslog'
      additivity = true
    }
}

I also tried this syntax:

log4j = {
    appender.stdout = "org.apache.log4j.ConsoleAppender"
    appender.'stdout.layout'="org.apache.log4j.PatternLayout"
    appender.'stdout.layout.ConversionPattern'='[%r] %c{2} %m%n'

    appender.mylog= "org.apache.log4j.DailyRollingFileAppender"
    appender.'mylog.File' = "mylog.log"
    appender.'mylog.layout' = "org.apache.log4j.PatternLayout"
    appender.'mylog.layout.ConversionPattern' = '%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n'

    appender.grailslog = "org.apache.log4j.DailyRollingFileAppender"
    appender.'grailslog.File' = "grails.log"
    appender.'grailslog.layout' = "org.apache.log4j.PatternLayout"
    appender.'grailslog.layout.ConversionPattern' = '%d{[ dd.MM.yy HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n'

    rootLogger="error,stdout,grailslog"

    logger {
      grails="info,stdout,grailslog"
      my.package="debug,mylog"
    }
}

But this doesn't work any more with the current grails version.

A: 

I've added per environment logging so my production logs go to a file/email & dev go to stdout

environments {
  development {
    debug 'grails.app', 'stdout'
    //trace 'org.hibernate.type'

  }
  production {
    appenders {
      file name: "file", file: "/var/log/myapp.log"
      appender new SMTPAppender(name: 'smtp', to: mail.error.to, from: mail.error.from,
          subject: mail.error.subject, threshold: Level.ERROR,
          SMTPHost: mail.error.server, SMTPUsername: mail.error.username,
          SMTPDebug: mail.error.debug.toString(), SMTPPassword: mail.error.password,
          layout: pattern(conversionPattern:
          '%d{[ dd.MM.yyyy HH:mm:ss.SSS]} [%t] %n%-5p %n%c %n%C %n %x %n %m%n'))
    }

    root {
      error 'stdout', 'smtp','file'
      additivity = true
    }
  }
}
Dave
Ok, that looks good. But my intention is to log different package members or log-levels to different logs. In my Example above I want everything of "my.package" in one seperate log.
steyze