Uses the following pattern:
yyyy-MM-dd'T'HH:mm:ss.SSSXXX
In the javadoc of java.text.SimpleDateFormat
, you can read that (for the X
letter):
ISO 8601 Time zone: The number of pattern letters designates the format for both formatting and parsing as follows:
ISO8601TimeZone:
OneLetterISO8601TimeZone
TwoLetterISO8601TimeZone
ThreeLetterISO8601TimeZone
OneLetterISO8601TimeZone:
Sign TwoDigitHours
Z
TwoLetterISO8601TimeZone:
Sign TwoDigitHours Minutes
Z
ThreeLetterISO8601TimeZone:
Sign TwoDigitHours : Minutes
Z
e.g.
X -08;
XX -0800;
XXX -08:00
If your configuration file is the log4j.xml
, can be as follows:
<!-- console -->
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<param name="conversionPattern"
value="%d{yyyy-MM-dd'T'hh:mm:ss.SSSXXX} %-5p (%c.java:%L).%M - %m%n" />
</layout>
</appender>
And if you have a Java class with:
import org.apache.log4j.Logger;
public class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class);
public static void main(String[] args) {
LOGGER.info("Test");
}
}
The output is as follows:
2013-09-12T08:08:18.532-05:00 INFO (Main.java:8).main - Test