1

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.

jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • 1
    for package you can use %50logger for Line number use %L and so on https://logback.qos.ch/manual/layouts.html#line – Vipul Pandey Nov 15 '22 at 09:17

1 Answers1

1

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224