2016-11-23 67 views
4

我使用Eclipse Neon.1,我使用谷歌應用程序引擎插件的deploy目標的Eclipse:添加時間戳到Maven日誌條目

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

[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接口的特定配置,並非特定於Maven。

我已經發現了與此主題相關的其他問題,但都與直接從mvn命令行啓動的maven相關,不使用Eclipse內置控制檯。

W/O任何額外的配置,只有「時間」的數據我已經是在整個構建年底,日誌是這樣的:

[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 

回答

7

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

注:,因爲日誌被遷移在這個版本SLF4J此解決方案僅使用Maven 3.1.0及更高版本的作品。

希望這會有所幫助,雖然有點晚了)