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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no Log4J symbol that does exactly what you want.
%dreturns the current date with a given pattern, defined by aSimpleDateFormat(the pattern you put between the brackets), but doesn’t give you the time in millis.%rgives 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.