It is possible to change the logging.properties file to use a FileHandler. This directs everything to a file, (obviously).
Check reference 3 for a good explanation of the logging.properties file.
Unfortunately the default values of the FileHandler in the default JSE logging.properties6 file leaves a lot to be desired.
property | default | comments | mine |
---|---|---|---|
limit | 50000 | 50 kilobytes is quite small for a log file | 5000000 |
count | 1 | this means the total number of files written is 1, so if the log increases beyond 'limit', you lose the old messages as the file is re-initialized | 100 |
append | false | might want to set this to true, to prevent loss of log messages upon restart. Unfortunately, this means you'll have *two* XML files within the log and they need to be separated afterwards. | true |
The following Handlers seem to be already available in Java4, if you're looking for something different.
I very much like the XMLFormatter. It provides even more information than general logging, and it can be easily post-processed.
JLogViewer
JLogViewer1 can view the XML logs written to file. I am sure there are other programs that perform the same function, but this is the one I happened to come across.
java -cp jlogviewer_1_0_0d.jar gianluca.utility.LogViewer
Fixing the logs
Unfortunately for me, the logs contain odd characters (because I am writing received data from sockets into the logs) that are not properly handled by jlogviewer.I was required to remove the special characters from my logs. Found a blog post2 on how to remove them.
cat java0.log.0 | tr -d "\013" | tr -d "\001" | tr -d "\000" | tr -d "\017" > sanitized_java.log
Update 17-03-2014: updated the item on appending to existing logs.
References
- [1] JLogViewer
- http://jlogviewer.sourceforge.net/
- [2] Removing special characters in Linux
- http://deepupc.wordpress.com/2009/10/28/removing-special-charactersmca-in-vi/
- [3] java Logging - Configuration
- http://tutorials.jenkov.com/java-logging/configuration.html
- [4] javadoc java.util.logging.Handler
- http://docs.oracle.com/javase/7/docs/api/java/util/logging/Handler.html
- [5] javadoc java.util.logging.LogManager
- http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.html
- [6] default logging.properties provided by JRE 7
- https://gist.github.com/maartenl/9346237
No comments:
Post a Comment