Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamps for maven logs #94

Open
volodya-lombrozo opened this issue Nov 11, 2022 · 0 comments
Open

Add timestamps for maven logs #94

volodya-lombrozo opened this issue Nov 11, 2022 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@volodya-lombrozo
Copy link
Member

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):


image

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:


image

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:

  1. Use native slf4j-simple logger 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] ------------------------------------------------------------------------
  1. Remove slf3j-simple from mvnw distributive (I don’t know if it’s even possible). But at least, you can try to remove slf4j-simple from your maven/lib folder and log4j will work fine.

Useful links:

  1. More detailed about maven logging you can read here.
  2. Maven slf4j provider library in GitHub.
  3. The list of properties that we can use in order to adjust maven slf4j-simple logger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants