在maven jetty 7插件中启用调试日志记录 [英] Enable debug logging in maven jetty 7 plugin

查看:113
本文介绍了在maven jetty 7插件中启用调试日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个带有简单 mvn jetty的java webapp:运行,使用最新的jetty插件,但我似乎找不到告诉码头的方法将DEBUG消息输出到控制台(对于嵌入式jetty实例,而不是插件本身)。它目前只输出WARN和INFO消息。我已经尝试设置 -DDEBUG -DVERBOSE ,但他们没有做任何事情。我已经看过文档,但它似乎没有涵盖这个。

I'm running a java webapp with a simple mvn jetty:run, using the latest jetty plugin, but I can't seem to find a way to tell jetty to output DEBUG messages to console (for the embedded jetty instance, not the plugin itself). It's currently outputting only WARN and INFO messages. I've tried setting -DDEBUG and -DVERBOSE, but they don't do anything. I've already had a look at the documentation, but it doesn't seem to cover this.

推荐答案

更新:好的,我终于开始工作了,这就是我的所作所为。

Update: OK, I finally got things working and here is what I did.

我的理解是Jetty 7对特定的日志框架没有任何依赖性,即使对于JSP引擎也是如此,因为Jetty 7使用JSP 2.1引擎。所以你可以使用任何日志框架。在这里,我将使用logback。

My understanding is that Jetty 7 doesn't have any dependencies on a particular logging framework, even for the JSP engine since Jetty 7 uses the JSP 2.1 engine. So you can use any logging framework. Here I will use logback.

首先在插件中添加 logback-classic 作为依赖项并设置 logback.configurationFile 指向配置文件的系统属性:

First add logback-classic as dependency in the plugin and set the logback.configurationFile system property to point on a configuration file:

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>7.0.0.pre5</version>
        <configuration>
          <systemProperties>
            <systemProperty>
              <name>logback.configurationFile</name>
              <value>./src/etc/logback.xml</value>
            </systemProperty>
          </systemProperties>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.15</version>
          </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

然后添加 src / etc / logback.xml 配置文件。低于最低配置:

Then add a src/etc/logback.xml configuration file. Below a minimal configuration:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>

  <root level="debug">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

通过此设置,jetty将输出DEBUG消息:

With this setup, jetty will output DEBUG messages:


$ mvn jetty:run
...
00:31:33.089 [main] DEBUG org.mortbay.log - starting DefaultHandler@145e5a6
00:31:33.089 [main] DEBUG org.mortbay.log - started DefaultHandler@145e5a6
00:31:33.105 [main] DEBUG org.mortbay.log - starting RequestLogHandler@1e80761
00:31:33.106 [main] DEBUG org.mortbay.log - started RequestLogHandler@1e80761
00:31:33.106 [main] DEBUG org.mortbay.log - starting HandlerCollection@1485542
00:31:33.106 [main] DEBUG org.mortbay.log - started HandlerCollection@1485542
00:31:33.106 [main] DEBUG org.mortbay.log - starting org.mortbay.jetty.Server@a010ba
00:31:33.174 [main] DEBUG org.mortbay.log - started org.mortbay.jetty.nio.SelectChannelConnector$1@ee21f5
00:31:33.216 [main] INFO  org.mortbay.log - Started SelectChannelConnector@0.0.0.0:8080
00:31:33.217 [main] DEBUG org.mortbay.log - started SelectChannelConnector@0.0.0.0:8080
00:31:33.217 [main] DEBUG org.mortbay.log - started org.mortbay.jetty.Server@a010ba
[INFO] Started Jetty Server

资源:

  • The Maven Jetty Plugin page
  • The [m2] jetty6 plugin & log4j message/thread
  • The Chapter 3: Logback configuration from the Logback documentation

这篇关于在maven jetty 7插件中启用调试日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆