preface

The format of the log can sometimes help us analyze the source code and locate problems. I used the default format previously, but now for debugging Spring, it is very helpful to turn on the appropriate log format.

The official PatternLayout document

Break down an example

%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
Copy the code

Each conversion specifier starts with a percent sign (%) and is followed by optional format modifiers and a conversion Character. (the original)

%-5p means the priority of the logging event should be left justified to a width of five characters.

  • %d{YYYY-MM-DD HH: MM :ss,SSS}, where d indicates the time format
  • %-5p P is a string of 5 characters. P indicates the log level
  • %c{1} indicates the print class, only in the abbreviated form A.b.class
  • %L prints the information of the line
  • %m Displays program log information
  • %n is a newline for the log

feeling

How to implement log jump class in Idea, but spend 10 minutes to read the API documentation, in fact, will get twice the result with half the effort. And these information can also precipitate, the previous approach is to match a log, check a.