gpt4 book ai didi

grails - grails 2或更高版本的log4j配置,对dailyRollOver不起作用

转载 作者:行者123 更新时间:2023-12-02 15:45:57 25 4
gpt4 key购买 nike

log4j = {
def pattern = new PatternLayout('%d{dd-MM-yyyy HH:mm:ss,SSS} %5p %c{2} - %m%n')
environments{
development{
appenders{
appender new ConsoleAppender(
name: 'stdout',
layout: pattern
)
appender new DailyRollingFileAppender(
name:"file",
file:"/home/logs/app.log",
layout: pattern,
datePattern: "'.'yyyy-MM-dd")
}
}
production{
appenders {
appender new DailyRollingFileAppender(
name:"file",
file:"/home/logs/app.log",
layout: pattern,
datePattern: "'.'yyyy-MM-dd")

rollingFile name:"stacktrace",
file:"/home/logs/stacktrace.log"

appender new ConsoleAppender(
name: 'stdout',
layout: pattern
)
}
}
}
root {
info("file")
}
}

DailyrollOver无法正常工作。根据文档,我认为应该有不同的文件(app.log。{today's_date})。但是仅存在一个文件(app.log)。我在这里缺少什么吗?

最佳答案

在任何环境中尝试此配置,

   import org.apache.log4j.DailyRollingFileAppender // import at the top of the file
production {

log4j = {
appenders {
file name : 'loggerFile',
file :"/YOUR_PATH/loggerFile.log",
append: false,
layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss} [%5p] - %m%n')
appender new DailyRollingFileAppender(
name: 'dailyAppender',
datePattern: "'.'yyyy-MM-dd",
fileName: "/YOUR_PATH/loggerFile.log",
layout: pattern(conversionPattern: '%d{dd-MM-yyyy HH:mm:ss} [%5p] - %m%n')
)

}
root {
debug 'dailyAppender'
error 'stdout'
info 'dailyAppender'
}
}
}

Note :

1.you need to create the logger file at the given location like /YOUR_PATH/loggerFile.log otherwise app will throw the FileNotFound exception.

  1. Separate log for date wise file will take 1 or more hour to reflect after app start.

关于grails - grails 2或更高版本的log4j配置,对dailyRollOver不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47918887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com