简体   繁体   English

当Java.util.logging的FileHandler无法写入文件时,该怎么做?

[英]What does Java.util.logging do when its FileHandler cannot write to the file?

I've written software that uses Java.util.logging. 我已经编写了使用Java.util.logging的软件。 It runs on a client PC. 它在客户端PC上运行。 I'm using a FileHandler to log certain entries to a file. 我正在使用FileHandler将某些条目记录到文件中。 The file resides on on a server. 该文件位于服务器上。 If the server goes away for a bit, then returns (or some other temporary error occurs), what does FileHandler do? 如果服务器消失了一点,然后返回(或发生了一些其他临时错误),FileHandler会做什么?

I occasionally see scenarios in which log records have failed to get written to the file (for hours or days). 我偶尔会看到一些情况,其中日志记录未能写入文件(数小时或数天)。 I need to stop/start the software to restart the logging. 我需要停止/启动软件以重新启动日志记录。 I'm hoping that there is a way to recover from a "temporary" file problem, whether it's provided by the class, or if it's something I need to code for. 我希望有一种方法可以从“临时”文件问题中恢复,无论它是由类提供的,还是我需要编写代码的问题。

Note: I'm using Java 1.4.2 (wince) because I'm using a proprietary operating system on proprietary hardware. 注意:我使用Java 1.4.2(wince),因为我在专有硬件上使用专有操作系统。 It is what it is! 就是这样!

The FileHandler uses the java.io.FileOutputStream to write log records. FileHandler使用java.io.FileOutputStream写入日志记录。 If a write fails then the FileHandler will fallback to using the assigned ErrorManager . 如果写入失败,则FileHandler将回退到使用分配的ErrorManager The default ErrorManager will just write the first failure to the console and ignore all errors after that. 默认的ErrorManager只会将第一个失败写入控制台,然后忽略所有错误。 If you want to change that behavior you have to install a custom ErrorManager. 如果要更改该行为,则必须安装自定义ErrorManager。

Since you are on proprietary operating system on proprietary hardware you should just mock up a test case using a FileOutputStream or FileHandler and simulate the error conditions. 由于您使用的是专有硬件上的专有操作系统,因此您应该仅使用FileOutputStream或FileHandler模​​拟测试用例并模拟错误情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM