Log4j 与 Logback的ConversionPattern对比

为了能将log4j的配置无缝转到logback,需要了解其中ConversionPattern的差异,以下是对比表格,内容来自:

  1. log4j官网
  2. logback官网

其中可能需要转换的地方主要有两块:

  1. %l
  2. %x
Log4j Log4j Description Logback Logback Description
c Used to output the category of the logging event. c{length} / lo{length} / logger{length} Outputs the name of the logger at the origin of the logging event.
C Used to output the fully qualified class name of the caller issuing the logging request C{length} class{length} Outputs the fully-qualified class name of the caller issuing the logging request.
d Used to output the date of the logging event. d{pattern} / date{pattern} / d{pattern, timezone} / date{pattern, timezone} Used to output the date of the logging event.
F Used to output the file name where the logging request was issued. F / file Outputs the file name of the Java source file where the logging request was issued.
l Used to output location information of the caller which generated the logging event. caller{depth} / caller{depth, evaluator-1, ... evaluator-n} Outputs location information of the caller which generated the logging event.
L Used to output the line number from where the logging request was issued. L / line Outputs the line number from where the logging request was issued.
m Used to output the application supplied message associated with the logging event. m / msg / message Outputs the application-supplied message associated with the logging event.
M Used to output the method name where the logging request was issued. M / method Outputs the method name where the logging request was issued.
n Outputs the platform dependent line separator character or characters. n Outputs the platform dependent line separator character or characters.
p Used to output the priority of the logging event. p / le / level Outputs the level of the logging event.
r Used to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event. r / relative Outputs the number of milliseconds elapsed since the start of the application until the creation of the logging event.
t Used to output the name of the thread that generated the logging event. t / thread Outputs the name of the thread that generated the logging event.
x Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.    
X Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event. The X conversion character must be followed by the key for the map placed between braces, as in %X{clientNumber} where clientNumber is the key. The value in the MDC corresponding to the key will be output. X{key:-defaultVal} / mdc{key:-defaultVal} Outputs the MDC (mapped diagnostic context) associated with the thread that generated the logging event.
% The sequence %% outputs a single percent sign.    

Log4j 与 Logback的ConversionPattern对比

上一篇:bae3.0第一步 添加框架支持


下一篇:飞鸽端口被占