使用log4j清除文件? [英] using log4j for clearing a file?

查看:146
本文介绍了使用log4j清除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用log4j写入具有以下属性文件的文件:

im using log4j to write into a file with the following properties file :

log4j.rootLogger=DEBUG, FA

#File Appender
log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.File=temp.ppr
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern= %m%n

我的问题是,在我的程序的每次运行中,我想清除文件temp.ppr,然后使用lo4j有效地写入它?或者你推荐其他解决方案?

My problem is , that in each run of my program , i want to clear the file "temp.ppr" , and then write to it efficiently with lo4j? or do you recommend other solutions?

谢谢

推荐答案

你可以这样做:

log4j.appender.FA=org.apache.log4j.RollingFileAppender
log4j.appender.FA.MaxBackupIndex=1

然后在应用程序的启动代码中:

And then in the startup code of the application:

Logger.getRootLogger().getAppender("FA").rollOver()

这样,对于程序的每次运行,现有日志都会移动到temp.ppr.1,而temp.ppr会启动新的。这样,您始终可以记录上一次运行的日志。

That way, for each run of the program, the existing log is moved to "temp.ppr.1" and "temp.ppr" starts new. This way, you always have the log of the previous run as well.

这篇关于使用log4j清除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆