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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“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.HTMLAppendersources for example.