使用Maven-Jetty-Plug插件进行logback日志记录 [英] logback logging with maven-jetty-plugin

查看:190
本文介绍了使用Maven-Jetty-Plug插件进行logback日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Maven-jetty-plugin使用logback日志记录.显然,在启动Maven-jetty-plugin并初始化slf4j之后,会读取系统属性logback.configurationFile,因此Jetty不会读取文件./src/test/resources/logback.xml. . 结果,我将所有日志消息设置为调试级别并打印到控制台(默认的日志配置).使用-Dlogback.configurationFile = ...启动maven解决了该问题.但是,我更喜欢在pom中设置该属性,因为使用log4j和maven-jetty-plugin可以实现.有什么想法吗?

I want to use logback logging with maven-jetty-plugin. Apparently, the system property logback.configurationFile is read after maven-jetty-plugin is started and has initialized slf4j, so the file ./src/test/resources/logback.xml isn't read by jetty. As a result, I get all log messages set to debug level and printed to console (a default logback configuration). Launching maven with -Dlogback.configurationFile=... resolves the problem. However, I'd prefer setting the property in the pom as it is possible with log4j and maven-jetty-plugin. Any ideas ?

这是我的pom.xml:

Here is my pom.xml:

...
 <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.0.4.v20111024</version>
    <dependencies>
       <dependency>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
          <version>1.0.0</version>
       </dependency>
       <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.6.1</version>
        </dependency>
        </dependencies>
        <configuration>
          <systemProperties>
            <systemProperty>
               <name>logback.configurationFile</name>
               <value>./src/test/resources/logback.xml</value>
            </systemProperty>
           </systemProperties>
...

这是logback.xml:

And here is logback.xml:

<configuration>

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
    </rollingPolicy>

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>

  </appender>

  <root level="INFO">
    <appender-ref ref="FILE" />
  </root>

</configuration>

推荐答案

使用较旧的maven-jetty-plugin而不是jetty-maven-plugin对我有效:

Using the older maven-jetty-plugin rather than the jetty-maven-plugin works for me:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <version>6.1.26</version>
  <configuration>
    <systemProperties>
      <systemProperty>
        <name>logback.configurationFile</name>
        <value>${project.build.outputDirectory}/jetty-logback.xml</value>
      </systemProperty>
    </systemProperties>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.6.4</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</plugin>

这篇关于使用Maven-Jetty-Plug插件进行logback日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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