Usually when users use a logging framework one of their primary requirement is to customize the log output format. In Log4j framework this is done using the layout components.
There are couple of predefined layouts comming from the log4j api however, if you want more customize layout with extra set of attributes you need to write your own custom layout extending the org.apache.log4j.PatternLayout class.
In WSO2 Products we do not use the default PatternLyout we have written our own layout to make sure our log format is service aware and multi-tenanted. Therefore we have our own set of conversion characters defined in our TenantAwarePatternLayout class.
Below table explains characters used in the TenantAwarePatternLayout and all other characters (which are comming from PatternLayout) which you can use in your custom pattern.
Conversion Character |
Description |
Coming from custom carbon layout
|
|
D | used to output the name of the tenant domain which is currently logged in to the server (super tenant domain is carbon.super) |
T | used to output the tenant id - to uniquely identify each tenant tenant id can be used in the layout (super tenant id is 0) |
S | used to output the server key - to uniquely identify each carbon server a server key can be used (ie as,esb,dss ) |
U | used to output the user name - current user who is logged into the server |
A | used to output the application name - service name or web application name of the current running applicaiton |
H | used to output the host name |
I | used to output the carbon instance id- uuid which is generated for each carbon instance to uniquely identify each instance |
Coming from the log4j patternlayout
|
|
c | used to output category(logger); a.b.c → %c{2} = a.b (this can be also used as fully qualified name) |
d | used to output the date of the logging event. for example, %d{hh:mm:ss,sss} or %d{dd mmm yyyy hh:mm:ss,sss}. |
F |
used to output the file name where the logging request was issued. |
l | used to output location information of the caller which generated the logging event. |
L | used to output the line number from where the logging request was issued. |
m | used to output the application supplied message associated with the logging event. |
M | used to output the method name where the logging request was issued. |
n | used to output the platform dependent line separator character or characters. |
p | used to output the priority 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. |
t | used to output the name of the thread that generated the logging event. |
Please note %C, %F, %l, %L, %M slow down program run!
To create your own ConversionPattern you can go to the log4j.properties file and edit ConversionPattern of the appender of your choice.
log4j.appender.CARBON_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n
which is the conversion character for ipaddress?
ReplyDelete