grails separating info logging

末鹿安然 提交于 2019-12-10 21:00:29

问题


I am trying to separate the info, warn and errors log, i did the below configuration, but on info file continue to log the other types of log on the same file, i already tried to search on the other topics but i did not find a solution, anyone can help ?

def logLayoutPattern = new PatternLayout("%d{yyyy-MM-dd/HH:mm:ss.SSS} %x %-5p %c{2} - %m%n")
appenders {
     appender new DailyRollingFileAppender(name: "perfil",threshold: Level.INFO,file: "/tmp/logs/file_perfil.log",datePattern: "'.'yyyy-MM-dd",layout: logLayoutPattern)
     appender new DailyRollingFileAppender(name: "errors",threshold: Level.ERROR,file: "/tmp/logs/file_errors.log",datePattern: "'.'yyyy-MM-dd",layout: logLayoutPattern)
     appender new DailyRollingFileAppender(name: "warn",threshold: Level.WARN,file: "/tmp/logs/file_warn.log",datePattern: "'.'yyyy-MM-dd",layout: logLayoutPattern)
}

info perfil: ["grails.app.controllers.com.app.PerfilController"]
warn warn: 'grails.app'

error errors: ['org.codehaus.groovy.grails.web.servlet',
       'org.codehaus.groovy.grails.web.pages',
       'org.codehaus.groovy.grails.web.sitemesh',
       'org.codehaus.groovy.grails.web.mapping.filter',
       'org.codehaus.groovy.grails.web.mapping',
       'org.codehaus.groovy.grails.commons',
       'org.codehaus.groovy.grails.plugins',
       'org.codehaus.groovy.grails.orm.hibernate',
       'org.springframework',
       'org.hibernate',
       'net.sf.ehcache.hibernate']
root {
    error 'errors'
    additivity = false
    warn 'warn'
    additivity = false
    info 'perfil'
    additivity = false
}

回答1:


You need to add additivity: false on the custom appenders instead of the root logger.

Something like this would suffice:

info perfil: ["grails.app.controllers.com.app.PerfilController"]
     additivity: false

warn warn: 'grails.app'
     additivity: false

error errors: ['org.codehaus.groovy.grails.web.servlet',
       'org.codehaus.groovy.grails.web.pages',
       'org.codehaus.groovy.grails.web.sitemesh',
       'org.codehaus.groovy.grails.web.mapping.filter',
       'org.codehaus.groovy.grails.web.mapping',
       'org.codehaus.groovy.grails.commons',
       'org.codehaus.groovy.grails.plugins',
       'org.codehaus.groovy.grails.orm.hibernate',
       'org.springframework',
       'org.hibernate',
       'net.sf.ehcache.hibernate']
     additivity: false

root {
    error 'errors'
    warn 'warn'
    info 'perfil'
}

All the loggers inherit from the root by default and additivity is true by default.



来源:https://stackoverflow.com/questions/18645226/grails-separating-info-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!