Search code examples
javaloggingjbosstimestampcustomization

How to customize timestamp in pattern formatter of jboss logging


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.


Solution

  • 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.