2013-02-08 40 views
4

在部署我的GAE應用程序之前,我在本地運行了數百個unit tests。我正在使用LocalServiceTestHelper來使用GAE服務,如memcache或數據存儲。在測試之間建立並拆除助手會創建大量的日誌輸出。如何在運行GAE/J測試用例時從LocalServiceTestHelper隱藏INFO消息?

如何重新配置​​java.util.logging以避免由LocalServiceTestHelper完全引起的INFO messages

INFO: Local Datastore initialized: 
Type: Master/Slave 
Storage: In-memory 
Feb 08, 2013 7:01:52 PM com.google.appengine.api.taskqueue.dev.LocalTaskQueue init 
INFO: LocalTaskQueue is initialized 
Feb 08, 2013 7:01:52 PM com.google.appengine.api.taskqueue.dev.LocalTaskQueue init 
INFO: Automatic task execution is disabled. 
Feb 08, 2013 7:01:52 PM org.quartz.simpl.SimpleThreadPool initialize 
INFO: Job execution threads will use class loader of thread: main 
Feb 08, 2013 7:01:52 PM org.quartz.core.QuartzScheduler <init> 
INFO: Quartz Scheduler v.null.null.null created. 
Feb 08, 2013 7:01:52 PM org.quartz.simpl.RAMJobStore initialize 
INFO: RAMJobStore initialized. 
Feb 08, 2013 7:01:52 PM org.quartz.impl.StdSchedulerFactory instantiate 
INFO: Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' 
Feb 08, 2013 7:01:52 PM org.quartz.impl.StdSchedulerFactory instantiate 
INFO: Quartz scheduler version: null.null.null 
Feb 08, 2013 7:01:52 PM com.google.appengine.api.taskqueue.dev.LocalTaskQueue start_ 
INFO: Local task queue initialized with base url http://localhost:8080 
Feb 08, 2013 7:01:52 PM org.quartz.core.QuartzScheduler shutdown 
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutting down. 
Feb 08, 2013 7:01:52 PM org.quartz.core.QuartzScheduler standby 
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED paused. 
Feb 08, 2013 7:01:52 PM org.quartz.core.QuartzScheduler shutdown 
INFO: Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED shutdown complete. 

編輯:

我創建文件src /測試/資源/ logging.properties。在測試執行之前,該文件被複制到target/test-classes /。它有以下內容:

com.google.appengine.api.taskqueue.dev.level=SEVERE 
org.quartz.level=WARNING 

但我仍然在運行測試時看到相同的日誌輸出。

回答

3

雖然src/test/resources /中的logging.properties文件格式正確,但maven-surefire插件不知道它的位置。如in another stackoverflow post所述,您必須在配置插件時設置java.util.logging.config.file系統屬性。應用這個簡單的變化後,一切都按預期工作。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.4.2</version> 
    <configuration> 
    <systemProperties> 
     <property> 
     <name>java.util.logging.config.file</name> 
     <value>${project.build.directory}/test-classes/logging.properties</value> 
     </property> 
    </systemProperties> 
    ... 
0

appengine-java-sdk/config/user/文件夾中獲取的logging.properties副本,如果使用maven把它放到你的項目的類路徑,例如src/test/resources文件夾,並從這裏開始配置自己的設置:

# A default java.util.logging configuration. 
# (All App Engine logging is through java.util.logging by default). 
# 
# To use this configuration, copy it into your application's WEB-INF 
# folder and add the following to your appengine-web.xml: 
# 
# <system-properties> 
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
# </system-properties> 
# 

# Set the default logging level for all loggers to WARNING 
.level = WARNING 

要爲配置日誌級別一個特定的包,使用:

# Set logging level for particular package 
com.google.appengine.api.taskqueue.dev.level = SEVERE 
org.quartz.level = WARNING 

對於一個完整的配置指南,JRE安裝文件夾退房lib/logging.properties

+0

謝謝!我用更多的信息更新了我的問題。我已經在src/test/resources中有這樣一個文件。但我仍然看到日誌輸出。任何想法是怎麼回事? – Ingo 2013-02-10 14:18:31

+0

我仍然面臨這個問題。我的控制檯充滿了「Local Datastore initialized」消息,即使我有一個logging.properties文件unter src/test/resources。有什麼建議麼? – roemer 2015-04-03 08:34:05