eoc
eoc copied to clipboard
Add timestamps for maven logs
I was struggling with the task of adding timestamps for build logs, because applied changes for log4j logger didn’t applied on a build process. In other words, if you use eoc with the new version of eo-maven-plugin (where we already added timestamps for log4j logs), you still will see the next output:
[INFO] There are 33 EO sources registered already
[INFO] Registered 1 EO sources from ./Users/lombrozo/Workspace/EOlang/Projects/learning to ./Users/lombrozo/Workspace/EOlang/Projects/learning/.eoc/eo-foreign.json, included [**.eo], excluded [.eoc/**]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.536 s
[INFO] Finished at: 2022-11-10T21:46:32+03:00
[INFO] ------------------------------------------------------------------------
Why? Because we use logs frameworks like this (I can be wrong in details):


As you can see, we expect to use log4j implementation for slf4j, but here is a trick: Since 3.1.x version of maven, the default maven distributive uses its own slf4j implementation - slf4j-simple, in other words, our picture changes to the next:


You can check maven that installed on your laptop and in the maven lib directory you probably will find the next jars:
maven-slf4j-provider-3.8.3.jar (==“slf4j-simple”)
slf4j-api-1.7.32.jar
Since slf4j chooses only one logging implementation, we have only 2 options here to add timestamps for build logs:
- Use native
slf4j-simplelogger directly. To do so we can just add the next arguments for all maven commands
-Dorg.slf4j.simpleLogger.showDateTime=true
-Dorg.slf4j.simpleLogger.dateTimeFormat=yyyy-dd-MM HH:mm:ss
Then all maven build logs will look like:
2022-10-11 21:49:00 [INFO] Assemble cycle #1 (eo:33/xmir:33/xmir2:33/discovered:33 -> eo:33/xmir:33/xmir2:33/discovered:33), took 3s
2022-10-11 21:49:00 [INFO] 1 assemble cycle(s) produced some new object(s): eo:33/xmir:33/xmir2:33/discovered:33
2022-10-11 21:49:00 [INFO] ------------------------------------------------------------------------
2022-10-11 21:49:00 [INFO] BUILD SUCCESS
2022-10-11 21:49:00 [INFO] ------------------------------------------------------------------------
2022-10-11 21:49:00 [INFO] Total time: 3.203 s
2022-10-11 21:49:00 [INFO] Finished at: 2022-11-10T21:49:00+03:00
2022-10-11 21:49:00 [INFO] ------------------------------------------------------------------------
- Remove
slf3j-simplefrommvnwdistributive (I don’t know if it’s even possible). But at least, you can try to removeslf4j-simplefrom yourmaven/libfolder andlog4jwill work fine.
Useful links:
- More detailed about maven logging you can read here.
- Maven slf4j provider library in GitHub.
- The list of properties that we can use in order to adjust maven
slf4j-simplelogger.
why not add
'-Dorg.slf4j.simpleLogger.showDateTime=true',
'-Dorg.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss',
in src/mvnw.js?