Are log files not meant to be read by machines but by users only? I wonder if there are file appenders for any logging framework that write their output to XML.
相关问题
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- convert logback.xml to log4j.properties
- Django management command doesn't show logging
- apache modules ap_log_perror is at a different lev
相关文章
- how do I log requests and responses for debugging
- Android Studio doesn't display logs by package
- Stacktrace does not print in Glassfish 4.1 Cluster
- Out of curiosity — why don't logging APIs impl
- Laravel log file based on date
- Java -How to get logger to work in shutdown hook?
- Codeigniter not logging
- Is there any way to remove the information line fr
"Logging to XML" is quite a general requirement, because there is no such thing as the standard log file format. But since XML files are text files, which logging frameworks can write, and since many of those frameworks allow configuring log line format, I see no problem in defining your log output with XML tags of choice.
For log4j, it might be something like this:
yielding example output:
This looks quite like XML, doesn't it? It will lack XML preamble, though, so technically it won't be valid. If it's critical that it is, I recommend writing a custom appender extending
org.apache.log4j.FileAppender
(or any of its subclasses) that would handle any additional opening/closing text in every log file.The problem with writing logs to XML, that does not exist in plain text files, is that you have to enforce that not one possible log statement would print XML forbidden characters, otherwise you'll end up with a non well-formed XML. That's hard to achieve without writing a custom appender — see
org.apache.log4j.HTMLAppender
sources for example.