3 min. reading time

One of the problems of long-running Maven builds is that there is no easy method to determine the runtimes of the individual plugin executions. 

In projects I often face the issue that a Jenkins build runs into a configured timeout being stuck in the middle of a plugin execution or even when downloading artifacts. Unfortunately it is not easily possible to compare the log outputs of the failed and previously succeeded builds due to missing execution times. Wouldn't it be nice and really helpful to disply just the current time in front of every Maven log line?

Nothing easier than that ...

How to add timestamps to every Maven log line

In Maven 3.1.0 the logging was migrated to SLF4J which brings us some configuration options. For the addition of log timestamps just open the file $M2_HOME/conf/logging/simplelogger.properties and do the following:

  • set property org.slf4j.simpleLogger.showDateTime to true
  • add the property org.slf4j.simpleLogger.dateTimeFormat with your preferred format (I'm using HH:mm:ss,SSS)

When you're running Maven the next time your log output will look something like this:

13:56:09,901 [INFO] Scanning for projects...
13:56:09,959 [INFO]                                                                         
13:56:09,959 [INFO] ------------------------------------------------------------------------
13:56:09,959 [INFO] Building Logging Test Project 0.0.1-SNAPSHOT
13:56:09,960 [INFO] ------------------------------------------------------------------------
13:56:10,023 [INFO]
13:56:10,023 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ logging-test ---
13:56:10,068 [INFO] Deleting /home/shillner/logging-test/target
13:56:10,068 [INFO]
13:56:10,069 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ logging-test ---
13:56:10,151 [INFO] Using 'UTF-8' encoding to copy filtered resources.
13:56:10,154 [INFO] Copying 3 resources
...

 

That's it!

Comments