如何在运行GAE / J测试用例时隐藏来自LocalServiceTestHelper的INFO消息?

时间:2013-02-08 19:13:27

标签: java unit-testing google-app-engine testing logging

在部署我的GAE应用之前,我在本地运行了数百个unit tests。我使用LocalServiceTestHelper来使用内存缓存或数据存储等GAE服务。在测试之间设置和拆除帮助程序会产生大量的日志输出。

如何重新配置​​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 / test / resources / logging.properties。在执行测试之前,将文件复制到target / test-classes /。它具有以下内容:

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

但是在运行测试时我仍然看到相同的日志输出。

2 个答案:

答案 0 :(得分:3)

虽然src / test / resources /中的logging.properties文件格式正确,但maven-surefire-plugin并不知道它的位置。如上所述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>
   ...

答案 1 :(得分:0)

logging.properties文件夹中获取appengine-java-sdk/config/user/的副本并将其放入项目的类路径中,例如{@ 1}}文件夹(如果使用maven),并从此处开始配置您自己的设置:< / p>

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

有关完整的配置指南,请查看JRE安装文件夹中的# Set logging level for particular package com.google.appengine.api.taskqueue.dev.level = SEVERE org.quartz.level = WARNING