In the LOG4J configuration file, the log output format can be configured in the log4j.appender.CATNAME.layout.ConversionPattern item. The meaning of the format character is as follows.
Java code
- %n - newline
- %m - log content
- %p - log level (FATAL, ERROR, WARN, INFO, DEBUG or custom)
- %r - milliseconds since the program started
- %% - percent sign in output
- %t - the current thread name
- %d - date and time,
- Commonly used formats are %d{DATE}, %d{ABSOLUTE}, %d{HH:mm:ss,SSS}, %d{ddMMyyyy HH:mm:ss,SSS}. . .
- %l - same as %F%L%C%M
- %F - java source file name
- %L - java source line number
- %C - java class name, %C{1} outputs the last element
- %M-java method name
%n - newline %m - log content %p - log level (FATAL, ERROR, WARN, INFO, DEBUG or custom) %r - milliseconds since the program started %% - percent sign in output %t - the current thread name %d - date and time, Commonly used formats are %d{DATE}, %d{ABSOLUTE}, %d{HH:mm:ss,SSS}, %d{ddMMyyyy HH:mm:ss,SSS}. . . %l - same as %F%L%C%M %F - java source file name %L - java source line number %C - java class name, %C{1} outputs the last element %M-java method name
Example:
Java code
- [%d{HH\:mm\:ss\:SSS}][%p] (%c\:%L) - %m%n
[%d{HH\:mm\:ss\:SSS}][%p] (%c\:%L) - %m%n
The output format is: [08:58:59:412][INFO] (com.soon.action:35) - server started