Java Logger不会写入文件 [英] Java Logger doesn't write into file
本文介绍了Java Logger不会写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Logger配置为写入应用程序配置文件夹中的文件,但是我不知道该怎么做,这是我用来在程序启动时配置日志记录输出的功能:
I'm trying to configure Logger to write to a file in the application configuration folder, but I'm not able to figure how to do so, here is the function I use to configure the logging output at program startup:
private void ConfigureLogger(){
Logger logger = Logger.getLogger(FormLogin.class.getName());
try{
FileHandler handler = new FileHandler(getConfigurationFolder()+"\\application.log", 10, 1, true);
logger.addHandler(handler);
}
catch(IOException e){
}
logger.log(Level.SEVERE, "test message");
}
已创建application.log文件,但未在控制台应用程序中写入测试日志.
The application.log file is created, but the test log is not written in it but in the console application.
推荐答案
您可以尝试:
FileHandler handler = new FileHandler("D:/temp/application.log", 8096, 1, true);
参数:
- pattern-用于命名输出文件的模式
- limit-写入任何一个文件的最大字节数
- count-要使用的文件数
- 追加-指定追加模式
这篇关于Java Logger不会写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文