21

I'm using the Tomcat7 Maven plugin:

<plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0-beta-1</version>
            <configuration>
                    <update>true</update>
                    <contextFile>${basedir}/conf/context.xml</contextFile>
                    <tomcatUsers>${basedir}/conf/tomcat-users.xml</tomcatUsers>
            </configuration>
 </plugin> 

I run my app as follows (which runs tomcat embedded)

mvn tomcat7:run

THE ISSUE: There is no catalina.out log file?

I want to turn on logging for the Realms so I can debug something. In the ./target/tomcat/log dir there is only access_log.* no other log files.

I've tried messing with the ./target/tomcat/conf/logging.properties file to no avail.

How can I configure logging for this Tomcat?

thejartender
  • 9,339
  • 6
  • 34
  • 51
geemang
  • 231
  • 1
  • 2
  • 6
  • 3
    Great question. I believe there is a real bug that is preventing the logs from being created. For me, the only log file I get within the `tomcat/logs` folder is the `access.log`. I don't get the other logs, such as `catalina.out` log, etc. – djangofan Dec 31 '15 at 20:22

5 Answers5

9

I found solution, you need describe extra dependencies of your logging library. In my case its logback, if you use log4j just change dependencies. It works... below my config:

       <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <path>/myapp</path>
                <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>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                        <version>1.0.7</version>
                    </dependency>
                    <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-core</artifactId>
                        <version>1.0.7</version>
                    </dependency>
                </extraDependencies>
            </configuration>
        </plugin>
Serhii Bohutskyi
  • 2,261
  • 2
  • 28
  • 28
0

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
Victor Lyuboslavsky
  • 9,882
  • 25
  • 87
  • 134
0

My solution is,

            String logBackfile  ="....."; //the logback config
            LoggerContext lc = new LoggerContext();

            JoranConfigurator configurator = new JoranConfigurator();  
            configurator.setContext(lc);  
            lc.reset();  
            configurator.doConfigure(logBackfile);
            StatusPrinter.printInCaseOfErrorsOrWarnings(lc);  
Stony
  • 3,541
  • 3
  • 17
  • 23
0

This is only a partial answer, but I got it working like this, where my app contains its own logback dependencies (no need to declare extraDependencies).

The only caveat here is that I still am not able to get the Tomcat catalina.log output that I need when there is a lower level error in my application (before the app loads and/or other). With this configuration, I only get my application level log file (not the logs/catalina.out that I really want):

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version><!-- Tomcat 7.0.47 -->
    <configuration>
        <port>9090</port>
        <path>/${project.artifactId}</path>
        <systemProperties>
            <spring.profiles.active>webService</spring.profiles.active>
            <java.util.logging.config.file>src/integration-test/resources/logback.xml</java.util.logging.config.file>
        </systemProperties>
    </configuration>
    <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <fork>true</fork>
            </configuration>
        </execution>
        <execution>
            <id>tomcat-shutdown</id>
            <goals>
                <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>
djangofan
  • 28,471
  • 61
  • 196
  • 289
-1

Try using

    <tomcatLoggingFile>log.txt</tomcatLoggingFile>

in configuration section.

Amol Ghotankar
  • 2,008
  • 5
  • 28
  • 42