Issue
So I am fine tuning logging in one of my application and I am struglling to find any documentation on what each of the character mean in the pattern. For example, we define like below:
logging.patter.console = %d %-5p %c - %m%n
I know few items like %d prints date/time. %m, %msg, %message would print the log message. %logger would print class name. Similarly, I want to see whole list of such directives and what does they mean (Specifically, I am looking to print line number from where this logging happens from the code). I searched a lot but couldn't find such a list anywhere.
I am trying to custumize my logging and making it a json format. Most of things work but I am not able to print the line numbers dynamically using directive. I can surely get line number of exception from going through the stack trace and all but I don't want to do it manually. I want to do it via % directives.
Solution
Assuming you are using Logback, the pattern parts are described here.
However if you want to log in JSON don't abuse the pattern for this, instead use a proper appender that will write JSON instead of a simple line. Something like the logback-json-classic
project.
Or something like the Logstash Logback Encoder.
Looking at those 2 projects I would suggest the latter (that seems to be still maintained) and add the appropriate configuration.
In short don't use the pattern use a proper JSON based appender.
Answered By - M. Deinum
Answer Checked By - Marilyn (JavaFixing Volunteer)