gpt4 book ai didi

java - Eclipse:将时间戳添加到 Maven 日志条目

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:04:42 25 4
gpt4 key购买 nike

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

<!-- 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 构建

[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 目标

[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接口(interface)的特定配置,而不是Maven特有的。

我已经找到了与此主题相关的其他问题,但所有问题都与直接从 mvn 命令行启动的 maven 有关,而不是使用 Eclipse 内置控制台。

没有任何额外的配置,我拥有的唯一“时间”数据是在整个构建的末尾,日志如下:

[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 中,您可以配置日志输出以在每一行前添加时间戳。只需执行以下操作:

$MAVEN_HOME/conf/logging/simplelogger.properties 中设置 org.slf4j.simpleLogger.showDateTime=true 并添加模式属性 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]
...

注意:此解决方案仅适用于 Maven 3.1.0 及更高版本,因为在此版本中日志已迁移到 slf4j。

希望这对您有所帮助,虽然有点晚了;)

关于java - Eclipse:将时间戳添加到 Maven 日志条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40766844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com