Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there way to specify current line number in log4j pattern

I have a pattern to output to console and log file in following format:

[INFO]  17:31:12 - Checking Bla Bla Bla 
[INFO]  17:31:12 - ************* Starting *********************
[INFO]  17:31:12 - Testing Begins

is there any way to append line count so that it looks like:

[001][INFO] 17:31:12 - Checking Bla Bla Bla 
[002][INFO] 17:31:12 - ************* Starting *********************
[003][INFO] 17:31:12 - Testing Begins
like image 496
Nodir Nasirov Avatar asked Jan 28 '23 00:01

Nodir Nasirov


1 Answers

In Log4j 1, the symbols can be seen here http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

Line Number is %L.

In Log4j 2, the symbol is also %L

https://logging.apache.org/log4j/2.0/manual/layouts.html#Pattern_Layout

like image 101
ProgrammersBlock Avatar answered Jan 29 '23 12:01

ProgrammersBlock