Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Created November 29, 2019 08:57
Show Gist options
  • Save jarek-przygodzki/a85499c9b1b5e11fe993a17604c925b3 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/a85499c9b1b5e11fe993a17604c925b3 to your computer and use it in GitHub Desktop.
How to add timestamps to Maven log

Maven is using SLF4J for its logging. Its default binding is an extended simple logger flavor of SLF4J, which means it can be configured using simplelogger.properties file (in Maven conf/logging directory) or using system properties.

To add timestamps to log output we need two properties:

  • org.slf4j.simplelogger.showDateTime: a boolean to add the timestamp in the output
  • org.slf4j.Simplelogger.dateTimeFormat: a SimpleDateFormat which formats the timestamp activated by previous property

We can do it permamently in the simplelogger.properties file or add these system properties on the JVM, possibly using MAVEN_OPTS

-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS
@ichengzi
Copy link

-Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS -Dorg.slf4j.simpleLogger.showThreadName=true showThreadName also work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment