我有一种模式可以以以下格式输出到控制台和日志文件:
[INFO] 17:31:12 - Checking Bla Bla Bla
[INFO] 17:31:12 - ************* Starting *********************
[INFO] 17:31:12 - Testing Begins
有什么方法可以添加行数,使其看起来像:
[001][INFO] 17:31:12 - Checking Bla Bla Bla
[002][INFO] 17:31:12 - ************* Starting *********************
[003][INFO] 17:31:12 - Testing Begins
答案 0 :(得分:2)
试试下面的转换模式
ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
答案 1 :(得分:0)
在Log4j 1中,可以在此处看到符号 http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
行号为%L。
在Log4j 2中,符号也是%L
https://logging.apache.org/log4j/2.0/manual/layouts.html#Pattern_Layout
答案 2 :(得分:0)
Is it line number or count of log lines ordered in sequence ?
if it is line number you can use %L (Used to output the line number
from where the logging request was issued.)
https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html