In log4j.properties
I can set PatternLayout
e.g. ("[%p] %c - %m - %d %n")
Is there any symbol (%something) which returns current time in milliseconds?
Logging levels are used to categorize the entries in your log file. But they categorize in a very specific way, i.e., by urgency. The level allows you to separate the following kinds of information: You can filter your log files during the search.
Apache log4j provides various Layout objects, each of which can format logging data according to various layouts. It is also possible to create a Layout object that formats logging data in an application-specific way. All Layout objects receive a LoggingEvent object from the Appender objects.
The PatternLayout class extends the abstract org. apache. log4j. Layout class and overrides the format() method to structure the logging information according to a supplied pattern.
The most commonly used layout for Log4j is PatternLayout. A sample pattern is %d [%t] %-5p (%F: %L) – %m%n . The format strings for the pattern are as follows: Date – Full date until microseconds.
You can try this one.
log4j.appender.appender_name.layout=org.apache.log4j.PatternLayout
log4j.appender.appender_name.layout.ConversionPattern=%d %p [%c] - %m%n
Date params %d
. For example : %d{HH:mm:ss,SSS}
.
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
There is no Log4J symbol that does exactly what you want.
%d
returns the current date with a given pattern, defined by a SimpleDateFormat
(the pattern you put between the brackets), but doesn't give you the time in millis.
%r
gives the number of milliseconds since the start of execution.
One possible way of achieving what you want is to extend the behaviour of Log4j, it's quite a bit more complex, but if it's absolutely necessary... here you go:
Customize log4j (edit: no longer online?)
Customize log4j (edit: 2018 alternative)
Edit: Keep in mind that, from your comment, if you need to figure out time differences between executions in different machines, you have to make sure the clocks of the machines are synchronized, or it'll be leading you to wrong conclusions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With