【问题标题】:How to configure Logging for an Embedded Tomcat from Maven plugin 'tomcat7-maven-plugin'如何从 Maven 插件“tomcat7-maven-plugin”为嵌入式 Tomcat 配置日志记录
【发布时间】:2013-06-03 06:23:56
【问题描述】:

我将 Maven 3.0.4 与 tomcat7-maven-plugin 一起用于嵌入式 Tomcat 服务器。我想通过编辑 pom.xml 来生成服务器日志。但是,我无法在配置部分使用“tomcatLoggingFile”属性获取任何日志。以下是我的配置:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <configuration>
        <tomcatLoggingFile>tomcat_server.log</tomcatLoggingFile>
    </configuration>
</plugin>

我查看了 tomcat7-maven-plugin 的官方文档:http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/run-mojo.html 但仍然不知道为什么它不起作用。

另外,我查看了这篇文章:Configuring Logging for an Embedded Tomcat from Maven plugin 并改用 org.slf4j.LoggerFactory 。在文件 tomcat_server.log 中没有找到任何日志。

当我在 pom.xml 中切换回使用 jboss-as-maven-plugin 并运行mvn jboss-as:run 时,可以在目标文件夹中成功生成 server.log。

有什么建议吗?

【问题讨论】:

    标签: tomcat logging configuration


    【解决方案1】:

    文档说,tomcatLoggingFile 指的是“Tomcat 日志配置的路径”,而不是日志文件本身。 此外,您应确保日志库位于类路径中。 见http://tomcat.apache.org/tomcat-7.0-doc/logging.html

    【讨论】:

      【解决方案2】:

      Embedded Tomcat Maven 的日志记录配置目前因错误而中断

      https://issues.apache.org/jira/browse/MTOMCAT-127

      解决方法是简单地重定向标准输出,例如:

      mvn tomcat7:run 2>&1 | tee catalina.out
      

      【讨论】:

        【解决方案3】:

        使用 log4j 或其他日志库,这是一个棘手的部分......你应该在你的 maven 插件配置中添加额外的依赖项

              <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        ....
                        <extraDependencies>
                            <dependency>
                                <groupId>org.slf4j</groupId>
                                <artifactId>slf4j-api</artifactId>
                                <version>1.7.2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.slf4j</groupId>
                                <artifactId>jul-to-slf4j</artifactId>
                                <version>1.7.2</version>
                            </dependency>
                            <dependency>
                                <groupId>log4j</groupId>
                                <artifactId>log4j</artifactId>
                                <version>1.2.17</version>
                            </dependency>
                        </extraDependencies>
                    </configuration>
                </plugin>
        

        【讨论】:

          【解决方案4】:

          我刚刚在 web.xml 中包含的 xml 配置中为 log4j 使用了文件追加器

          【讨论】:

            猜你喜欢
            • 2012-05-30
            • 1970-01-01
            • 2011-11-02
            • 2014-02-23
            • 2019-10-13
            • 2014-07-09
            • 2012-02-07
            • 2013-07-14
            • 1970-01-01
            相关资源
            最近更新 更多