【问题标题】:How to hide INFO messages from LocalServiceTestHelper when running GAE/J test cases?运行 GAE/J 测试用例时如何隐藏来自 LocalServiceTestHelper 的 INFO 消息?
【发布时间】:2013-01-24 15:23:41
【问题描述】:

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

如何重新配置​​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

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

【问题讨论】:

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


    【解决方案1】:

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

    # 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

    【讨论】:

    • 谢谢!我用更多信息更新了我的问题。我已经在 src/test/resources 中有这样的文件。但我仍然看到日志输出。知道发生了什么吗?
    • 我仍然面临这个问题。即使我在 src/test/resources 下有一个 logging.properties 文件,我的控制台也充满了“本地数据存储已初始化”消息。有什么建议吗?
    【解决方案2】:

    虽然 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>
       ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多