Search code examples
javaloggingrecoveryfilehandler

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


I've written software that uses Java.util.logging. It runs on a client PC. I'm using a FileHandler to log certain entries to a file. 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?

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. It is what it is!


Solution

  • The FileHandler uses the java.io.FileOutputStream to write log records. If a write fails then the FileHandler will fallback to using the assigned ErrorManager. The default ErrorManager will just write the first failure to the console and ignore all errors after that. If you want to change that behavior you have to install a custom 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.