How to configure Logging for an Embedded Tomcat fr

2019-03-25 16:43发布

I'm using Maven 3.0.4 with tomcat7-maven-plugin for embedded Tomcat server. I would like to generate the server log through editing pom.xml. However, I can't get any log with the "tomcatLoggingFile" property in the configuration section. Below is my configuration:

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

I've checked the official documentation for tomcat7-maven-plugin: http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/run-mojo.html but still don't know why it's not working.

Also, I've checked this post: Configuring Logging for an Embedded Tomcat from Maven plugin and use org.slf4j.LoggerFactory instead. There is no any log found in the file tomcat_server.log.

When I switch back to use jboss-as-maven-plugin in pom.xml and run mvn jboss-as:run, the server.log can be generated inside target folder successfully.

Any suggestion?

4条回答
【Aperson】
2楼-- · 2019-03-25 17:21

I just used file appender for log4j in xml config included in web.xml

查看更多
Emotional °昔
3楼-- · 2019-03-25 17:23

The logging configuration for Embedded Tomcat Maven is currently broken due to bug

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

The workaround is to simply redirect the stdout, like:

mvn tomcat7:run 2>&1 | tee catalina.out
查看更多
女痞
4楼-- · 2019-03-25 17:25

Use log4j or another logging library and here it is a tricky part.... you should add extra dependencies in your maven plugin configuration

      <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>
查看更多
神经病院院长
5楼-- · 2019-03-25 17:34

The documentations says, that tomcatLoggingFile refers to "the path of the Tomcat logging configuration", not the logging file itself. Besides you shall ensure, that the logging libraries are on the classpath. See http://tomcat.apache.org/tomcat-7.0-doc/logging.html

查看更多
登录 后发表回答