I want to log "pretty printed" XML using Logback/SLF4J. Right now, what I get in logs is totally unreadable and I have to open something to parse it. I want to be able to configure logging for debug (because I want to see XML only in debug) to output XML in a human readable way.
Is it possible?
Multiline processing is used to ensure a log message that is made up of multiple lines, separated by a line break or carriage return, are properly grouped as a single log message when ingested into Sumo Logic. Multiline processing requires your logs to have line breaks or carriage returns between messages.
SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP. The logback project supports SLF4J natively.
Logback and SLF4J can be primarily classified as "Log Management" tools. According to the StackShare community, Logback has a broader approval, being mentioned in 4 company stacks & 9 developers stacks; compared to SLF4J, which is listed in 5 company stacks and 7 developer stacks.
Developers just need to include the logging framework dependency in the classpath and SLF4J will utilize it to append the logs. If no logging dependency is provided on the classpath, it will default to a no-operation implementation and nothing gets logged.
Simply add a newline \n
in log statement:
log.info("Message id: {}\nContents: {}", id, xml);
UPDATE: In order to pretty-print XML have a look at: How to pretty print XML from Java?. One thing to keep in mind, there is no need to perform costly formatting if the XML is not going to be actually printed. Therefore this is one of the rare cases where is*Enabled()
should be used:
if(log.isInfoEnabled())
log.info("Message: {}", prettyFormat(xml));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With