Reputation: 53
I want to change the format of timestamp in the logs generated by pattern formatter in my java standalone.xml
file.
The current format is "%d{yyyy-MM-dd'T'HH:mm:ss.ssZZZ}"
which generates timestamp like "2021-02-02T19:39:01.01+0530"
but my required timestamp is "2021-02-02T19:39:01.01+05:30"
. I tried adding colon ":" in the format like "%d{yyyy-MM-dd'T'HH:mm:ss.ss:ZZZ}"
but it did not work.
Upvotes: 2
Views: 1239
Reputation: 17780
You can do this in the logging subsystem. The pattern-formatte
uses the SimpleDateFormat
for formatting the time stamp. In CLI you'd do the following assuming you're using the default configuration.
/subsystem=logging/pattern-formatter=PATTERN:write-attribute(name=pattern, value="%d{yyyy-MM-dd'T'HH:mm:ss.ssXXX} %-5p [%c] (%t) %s%e%n")
The XXX
is the time zone in the format you're looking for.
Upvotes: 2
Reputation: 40034
Try it like this.
String fmt = "yyyy-MM-dd'T'HH:mm:ss.ssZZZZZ";
String ldt = ZonedDateTime.now().format(DateTimeFormatter.ofPattern(fmt));
System.out.println(ldt);
Prints
2021-02-02T11:08:06.06-05:00
Upvotes: 2