我正在创建一个ant脚本来为一个小项目进行一些集成测试。有问题的应用程序是打包为WAR的Web应用程序。目前,我的ant脚本生成一个WAR文件,使用打包的WAR文件启动Jetty,然后针对服务器应用程序运行基于Selenium的单元测试。到目前为止一切正常。
我的问题是Jetty ant插件会为终端生成大量的日志输出。我真的想改变Jetty的日志记录级别,但我无法弄清楚如何。我曾尝试用两种不同的方式改变码头测井系统属性,但都没有工作。首先在ant文件中包含<systemproperty>
个元素,然后使用ant_opts
设置它们(也就是说,我设置ANT_OPTS="-Dorg.eclipse.jetty.LEVEL=WARN -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StrErrLog"
)
我在守护进程模式下运行服务器,以便它与我的测试目标一起运行。所以,虽然我能够关闭jetty.run目标本身的日志记录,但也关闭了测试目标中的日志记录,如果我在测试目标中将其重新打开,那么测试期间的所有jetty输出仍然会被写入到终点站。此外,测试目标期间的所有Jetty输出都标记为[junit],因为它在测试目标期间输出。
我想将Jetty的日志记录级别降低到WARN(这应该是插件的默认值),我无法弄清楚如何。我已经包含了构建脚本的相关部分。
<target name="jetty.run" depends="build-and-package">
<typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" classpathref="classpath" loaderref="jetty.loader" onerror="ignore" />
<taskdef classpathref="classpath" resource="tasks.properties" loaderref="jetty.loader" />
<jetty.run daemon="true">
<systemProperties>
<systemProperty name="org.eclipse.jetty.LEVEL" value="WARN" />
<systemProperty name="org.eclipse.jetty.util.log.class" value="org.eclipse.jetty.util.log.StrErrLog" />
</systemProperties>
<webApp war="${artifacts}/${warfilename}" contextPath="/" />
</jetty.run>
</target>
<target name="test" depends="compile-tests, jetty.run">
<mkdir dir="${junit.output.dir}" />
<junit fork="yes" printsummary="withOutAndErr" haltonfailure="yes" haltonerror="yes">
<formatter type="xml" />
<batchtest todir="${junit.output.dir}">
<fileset dir="${compiled-tests.dir}">
<include name="**/*Test*" />
</fileset>
</batchtest>
<classpath refid="classpath" />
<classpath path="${compiled-classes.dir}" />
<classpath path="${compiled-tests.dir}" />
</junit>
</target>
编辑以下是从jetty.run任务开始的一些(非常修剪的)示例输出。我试图消除所有或大部分非junit输出
jetty.run:
[jetty.run] Daemon=true
[jetty.run] 2015-02-02 14:47:47.671:INFO::main: Logging initialized @2789ms
[jetty.run] Configuring Jetty for project: Build script for Vaadin 7 projects
[jetty.run] Setting property 'org.eclipse.jetty.LEVEL' to value 'WARN'
[jetty.run] Setting property 'org.eclipse.jetty.util.log.class' to value 'org.eclipse.jetty.util.log.StrErrLog'
[jetty.run] 2015-02-02 14:47:47.757:INFO:oejs.Server:main: jetty-9.2.7.v20150116
[jetty.run] 2015-02-02 14:47:47.769: Starting web application null
[jetty.run] 2015-02-02 14:47:48.759:INFO:oejw.StandardDescriptorProcessor:main: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
[jetty.run] 2015-02-02 14:47:48.794:INFO:oejsh.ContextHandler:main: Started o.e.j.a.AntWebAppContext@cad498c{/,file:/tmp/jetty-0.0.0.0-8080-card_trainer.war-_-any-2642472331853673434.dir/webapp/,AVAILABLE}{build/card_trainer.war}
[jetty.run] 2015-02-02 14:47:48.795:WARN:oejsh.RequestLogHandler:main: !RequestLog
[jetty.run] 2015-02-02 14:47:48.807:INFO:oejs.ServerConnector:main: Started ServerConnector@6c5a7edc{HTTP/1.1}{0.0.0.0:8080}
[jetty.run] 2015-02-02 14:47:48.808:INFO:oejs.Server:main: Started @3929ms
[jetty.run] Jetty AntTask Started
test:
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:/usr/share/ant/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/home/dyule/git/card_trainer/ivy_libs/nodeploy/ant.jar!/org/apache/tools/ant/Project.class
[junit] Running com.example.card_trainer.CardSourceTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.126 sec
[junit] Running com.example.card_trainer.Card_trainerTest
[junit] Feb 02, 2015 2:47:51 PM
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework addAtmosphereHandler
[junit] INFO: Installed AtmosphereHandler com.vaadin.server.communication.PushHandler$1 mapped to context-path: /*
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework addAtmosphereHandler
[junit] INFO: Installed the following AtmosphereInterceptor mapped to AtmosphereHandler com.vaadin.server.communication.PushHandler$1
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework doInitParams
[junit] WARNING: SessionSupport error. Make sure you define org.atmosphere.cpr.SessionSupport as a listener in web.xml instead
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework autoConfigureService
[junit] INFO: Atmosphere is using org.atmosphere.cpr.DefaultAnnotationProcessor for processing annotation
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.DefaultAnnotationProcessor configure
[junit] INFO: AnnotationProcessor class org.atmosphere.cpr.DefaultAnnotationProcessor$ServletContainerInitializerAnnotationProcessor being used
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.DefaultAnnotationProcessor fallbackToManualAnnotatedClasses
[junit] WARNING: Unable to detect annotations. Application may fail to deploy.
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework autoDetectWebSocketHandler
[junit] INFO: Auto detecting WebSocketHandler in /WEB-INF/classes/
[junit] Feb 02, 2015 2:47:51 PM org.atmosphere.cpr.AtmosphereFramework initWebSocket
[junit] INFO: Installed WebSocketProtocol org.atmosphere.websocket.protocol.SimpleHttpProtocol
答案 0 :(得分:0)
来自ant脚本 - 您确实使用Jetty的默认日志记录 的 StdErrLog 强>
当然,这会将所有日志记录抛出到终端(STDOUT,STDERR)
您可以将其内容捕获到文件 -
捕获控制台输出到文件
Jetty发行版中的日志记录模块,能够将所有STDOUT和STDERR输出简单地捕获到文件中。
添加&#34; - module = logging&#34;到$ JETTY_HOME / start.ini文件
更多信息:Default Logging with Jetty's StdErrLog
配置StdErrLog
配置StdErrLog的推荐方法是创建$ {jetty.home} /resources/jetty-logging.properties文件,指定Log实现到StdErrLog,然后设置日志记录级别。
- 希望这可能会有所帮助