log4j in grails: error printed when use variable in appender config

后端 未结 1 1768
别那么骄傲
别那么骄傲 2021-01-22 17:35

I am using slf4j \"DailyRollingFileAppender\" in grails 2.3.4.

When i tried to use a variable as part of the \"file\" parameter, the grails always print some error logs

相关标签:
1条回答
  • 2021-01-22 18:07

    Use Holders to read config properties. I assume it will not be able to read the config property itself while setting up log4j as it is part of the config itself.

    import grails.util.Holders
    
    ...
    
    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 DailyRollingFileAppender(
                name: "userEventLog",
                file: "${Holders.config.event.log.dir}/user-event.log",
                layout: pattern(conversionPattern: '%m%n'),
                datePattern: "'.'yyyy_MM_dd",
                threshold: org.apache.log4j.Level.INFO
            )
        }
    
        info userEventLog: "app.bean.log.UserEventLog"
    }
    
    0 讨论(0)
提交回复
热议问题