Java 每天使用 log4j 创建新的日志文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20618527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:10:16  来源:igfitidea点击:

Create new log file daily using log4j

javalog4jrollingfileappender

提问by Rocky

I want to use Log4j in my java project, which configuration should I provide in configuration file that every night at 12.00 am new file will generate and file name should like - output-log-of-MyProjectName-HostName-2013-Dec-10.txtname). My configuration file is like that-

我想在我的 java 项目中使用 Log4j,我应该在配置文件中提供哪个配置,每天晚上 12 点将生成新文件,文件名应该类似于 - output-log-of-MyProjectName-HostName-2013-Dec-10。 txt名称)。我的配置文件是这样的-

log4j.appender.FILE = org.apache.log4j.DailyRollingFileAppender    
log4j.appender.FILE.File = ${log}/log.out    
log4j.appender.FILE.DatePattern = '.' yyyy-MM-dd-a

It is creating new file everyday but it appending date after file name. Please help me. Thanks in advance.

它每天都在创建新文件,但在文件名后附加日期。请帮我。提前致谢。

采纳答案by mcgyver5

I think you want DailyRollingFileAppender (geedubb links to the log4j docs about it) Here is example

我想你想要 DailyRollingFileAppender(geedubb 链接到有关它的 log4j 文档) 这是示例

Here is another stackoverflow question like yours

这是另一个像你一样的stackoverflow问题