简体   繁体   中英

Java - Logging Appender format Documentation

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.

Assuming you are using Logback, the pattern parts aredescribed 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM