Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Add timestamp to Maven log entries

I'm using Eclipse Neon.1 and I use the deploy goal of Google App Engine plugin

<!-- https://github.com/GoogleCloudPlatform/app-maven-plugin -->
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>0.1.2</version>
    <configuration>
        <deploy.project>${app.id}</deploy.project>
        <deploy.version>${app.version}</deploy.version>
    </configuration>
</plugin>

Here is my launch configuration

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
    <booleanAttribute key="M2_DEBUG_OUTPUT" value="true" />
    <stringAttribute key="M2_GOALS" value="com.google.cloud.tools:appengine-maven-plugin:deploy" />
    <booleanAttribute key="M2_NON_RECURSIVE" value="false" />
    <booleanAttribute key="M2_OFFLINE" value="false" />
    <stringAttribute key="M2_PROFILES" value="" />
    <listAttribute key="M2_PROPERTIES" />
    <stringAttribute key="M2_RUNTIME" value="EMBEDDED" />
    <booleanAttribute key="M2_SKIP_TESTS" value="true" />
    <intAttribute key="M2_THREADS" value="1" />
    <booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false" />
    <stringAttribute key="M2_USER_SETTINGS" value="" />
    <booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false" />
    <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc}" />
</launchConfiguration>

I enabled debug_output in order to have the full log, here is a couple of lines directly from the Maven Build

[DEBUG]   Included: org.apache.maven.plugins:maven-resources-plugin:jar:2.6
[DEBUG]   Included: org.apache.maven.reporting:maven-reporting-api:jar:2.0.6
[DEBUG]   Included: org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7
[DEBUG]   Included: commons-cli:commons-cli:jar:1.0

And here are a couple lines from the specific GCloud goal

[INFO] GCLOUD: Reading application configuration data...
[INFO] GCLOUD: nov 23, 2016 3:04:54 PM
[INFO] GCLOUD: Configuration Warning : <application>/<version> XML elements and --application/--version should not be specified when staging
[INFO] GCLOUD: 
[INFO] GCLOUD: The following parameters will be scrubbed from app.yaml

Is there a way to have a timestamp in front of each line? For this kind of request, I think this is a specific configuration of Eclipse interface and not specific to Maven.

I already found other questions related to this topic, but there are all related to maven launched directly from mvn command-line, not using the Eclipse built-in console.

W/o any additional configuration, the only "temporal" data I have is at the end of the whole build, with a log like this:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15:52 min
[INFO] Finished at: 2016-11-23T14:57:19+01:00
[INFO] Final Memory: 37M/314M
[INFO] ------------------------------------------------------------------------

The expected output is something like this

[2016-11-23T14:57:19+01:00][DEBUG]   Included: org.apache.maven.plugins:maven-resources-plugin:jar:2.6
[2016-11-23T14:57:20+01:00][DEBUG]   Included: org.apache.maven.reporting:maven-reporting-api:jar:2.0.6
[2016-11-23T14:57:21+01:00][DEBUG]   Included: org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7
[2016-11-23T14:57:22+01:00][DEBUG]   Included: commons-cli:commons-cli:jar:1.0
....
[2016-11-23T14:59:22+01:00][INFO] GCLOUD: Reading application configuration data...
[2016-11-23T14:59:23+01:00][INFO] GCLOUD: nov 23, 2016 3:04:54 PM
[2016-11-23T14:59:24+01:00][INFO] GCLOUD: Configuration Warning : <application>/<version> XML elements and --application/--version should not be specified when staging
[2016-11-23T14:59:25+01:00][INFO] GCLOUD: 
[2016-11-23T14:59:26+01:00][INFO] GCLOUD: The following parameters will be scrubbed from app.yaml
like image 792
Deviling Master Avatar asked Nov 23 '16 14:11

Deviling Master


2 Answers

You can specify the options via JVM properties. For example:

mvn clean install -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS
like image 142
Marian Teodorescu Avatar answered Oct 22 '22 20:10

Marian Teodorescu


with Maven 3.5.0 you can configure the logging output to prepend a timestamp to each line. Simply do the following:

In $MAVEN_HOME/conf/logging/simplelogger.properties set org.slf4j.simpleLogger.showDateTime=true and add the pattern property org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS.

This will produce output like this:

10:28:25.849 [INFO] Scanning for projects...
10:28:25.914 [INFO]
...
10:28:25.975 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xxx ---
10:28:26.023 [INFO] Deleting /home/shillner/samples/xxx/target
10:28:26.024 [INFO]
...

Note: This solution only works with Maven 3.1.0 and later versions since the logging was migrated to slf4j in this version.

Hope this helped, although it is a bit late ;)

like image 31
shillner Avatar answered Oct 22 '22 20:10

shillner