Eclipse:将时间戳添加到Maven日志条目 [英] Eclipse: Add timestamp to Maven log entries

查看:72
本文介绍了Eclipse:将时间戳添加到Maven日志条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse Neon.1,并且使用了Google App Engine插件的deploy目标

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>

这是我的启动配置

<?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>

我启用了debug_output以获得完整的日志,这是直接来自Maven Build的几行内容

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

以下是特定GCloud目标的几行内容

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

是否有一种方法可以在每行前面加上时间戳记? 对于这种请求,我认为这是Eclipse接口的特定配置,而不是Maven特定的.

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.

我已经找到了与此主题相关的其他问题,但所有问题都与直接从mvn命令行启动而不是使用Eclipse内置控制台的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] ------------------------------------------------------------------------

期望的输出是这样的

[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

推荐答案

使用Maven 3.5.0,您可以将日志记录输出配置为在每行前面添加一个时间戳.只需执行以下操作:

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

$MAVEN_HOME/conf/logging/simplelogger.properties中设置org.slf4j.simpleLogger.showDateTime=true并添加图案属性org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS.

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.

这将产生如下输出:

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]
...

注意:,因为该版本的日志记录已迁移到slf4j,所以该解决方案仅适用于Maven 3.1.0和更高版本.

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

这篇关于Eclipse:将时间戳添加到Maven日志条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆