前言
日志的格式有时候会帮助我们很好地分析源码和定位问题,前面我都是使用默认的格式,现在为了调试 Spring ,开启合适的日志格式会非常有利于工作的进行。
官方 PatternLayout 文档
拆解一个例子
%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
Each conversion specifier starts with a percent sign (%) and is followed by optional format modifiers and a conversion character.(原文)
%-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},其中d表示这是时间格式
- %-5p 用5个字符的长度打印p,其中p表示日志级别信息
- %c{1} 表示打印类,单以缩写的形式 a.b.Class
- %L 表示打印line行的信息
- %m 输出程序的日志信息
- %n 为该日志换行
感悟
以前都是翻:如何在 Idea 实现日志跳转类的,但花10分钟看看 api 文档,其实是会事半功倍的。而且这些信息还能沉淀,以前的做法是配一次日志,就查一次。