Getting Data In

How to format exceptions with log4j to stdout

pwolfpwolf
New Member

When we had Splunk processing log files, the exceptions looked fine. But now that we are processing just the STDOUT from Docker, the exception stack traces were appearing as separate log messages. I fixed that in a way, buy removing the line breaks in the message itself with a pattern in log4j. Now it want it appear as separate lines when I view the exception. Is there some character or string that I can substitute so each method in the stack trace appears as a separate line, but not a separate message?

Here is my current log4j pattern:

<Pattern>%d{ISO8601} %-5p %C{1} - [%x]  %m %throwable{separator(\n)}%n</Pattern>

In Spunk it appears with a literal "\n" instead of a line break.

What is the correct Pattern I should use?

0 Karma

koshyk
Super Champion

did you check how the output logs come in notepad++ (or a quality text editor)?
My suggestion is to use %d{ISO8601} %-5p %c %x - %m%n

0 Karma

pwolfpwolf
New Member

@koshyk , without the "throwable{separator}" , log4j outputs the exception as multiple lines with each line in the stack trace being treated as a separate log message, which is not what we want. We are processing the STDOUT of our container, not a log file.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...