How can I configure logging for maven build? The log which maven generates is not providing enought information like time stamp with each log statement. Where/what log config file maven uses?
5 Answers
You may be aware of this, and it will not print dates, but use mvn -X
to print verbose output.
Additionally, you can always pipe the output of maven to some other utility (assuming your shell environment contains halfway competent tools). For instance mvn -X clean | awk '{print "("d")"$0}' "d=$(date)"
prints out a date before each line in maven. I didn't bother formatting the date, but that's easily done with arguments to the date
executable. Note that this won't really work for maven commands that require interactive user input, such as maven archetype:generate
.

- 16,075
- 10
- 57
- 68
Answer provided by @whaley is a good direction. However, the $(date) is evaluated only once at the beginning and then remains the same. I had to use an approach mentioned in Is there a Unix utility to prepend timestamps to stdin?:
mvn -X <goals> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }'

- 1
- 1

- 3,991
- 2
- 23
- 25
As suggested by @eckes, default logging configuration file is available at /conf/logging/simplelogger.properties, from Maven 3.1.0 onward.
Change "org.slf4j.simpleLogger.showDateTime" property value to "true"
org.slf4j.simpleLogger.showDateTime=true
To change dateTimeFormat, as default is relative time in milliseconds.
Add below line in simplelogger.properties file.
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS
References:
Maven logging: https://maven.apache.org/maven-logging.html
DateFormats: http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html

- 73
- 5
Maven in Version 3.1 and 3.2 allow simpler configuration of the SLF4J based logger. You can specify "-l logfile" on the command line, and the default configuration of the SimpleLogger is in the config file conf/logging/simplelogger.properties
.
If you want to turn on the default timestampts (milliseconds since start) you can simple change the property in this file: org.slf4j.simpleLogger.showDateTime=true
.

- 10,103
- 1
- 59
- 71
-
But `-l` is "log file to where all build output will go", not the logging configuration. – lexicore Nov 29 '16 at 07:15
-
1@lexicore yes, this is what I said "-l logfile" – eckes Jun 06 '17 at 22:14
-
I am looking for change the build log to a file, mvn -l logfile works for me. – IcyBrk Jan 13 '18 at 15:19
This still seems some closed issue in Maven, as you can see on:
https://issues.apache.org/jira/browse/MNG-519
The provided workaround looks not too bad, but you need to modify the maven installation.

- 35,625
- 19
- 175
- 265

- 3,344
- 4
- 28
- 31