How properly to set up tomcat logs into Maven Cargo Plugin

1.8k Views Asked by At

I'm trying to use Tomcat 8 with Maven Cargo Plugin. Developing I'm introduced an error, but error logs are not printed by Tomcat.

How can I specify to print error log?

As you can see into my pom.xml file I've tried to configure something but it won't works

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>it.hbg</groupId>
    <artifactId>balancesheet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <tomcat.version>8.5.2</tomcat.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>tomcat8x</containerId>
                        <log>target/cargo.log</log>
                        <!--<output>target/cargo/configurations/tomcat8x/logs/container.log</output>-->
                        <logLevel>debug</logLevel>
                        <artifactInstaller>
                            <groupId>org.apache.tomcat</groupId>
                            <artifactId>tomcat</artifactId>
                            <version>${tomcat.version}</version>
                        </artifactInstaller>
                    </container>
                    <deployables>
                        <deployable>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/balancesheet</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <!-- log4j -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.8.2</version>
        </dependency>

    </dependencies>
</project>

Someone can help me please?

1

There are 1 best solutions below

0
mallen On

I know it's an old question but here's your answer...

Add the log4j (and/or slf4j) dependencies INSIDE (as a child of) the cargo plugin config. Those dependency files get deployed inside the target/.../<tomcat_home>/common/lib folder, and therefore are used by Tomcat for debugging

...
<configuration>
  <container>
    ...
    <dependencies>
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
      </dependency>
    </dependencies>
  </container>
</configuration>

You will also need dependencies in the regular dependencies section specifying the version so maven knows where to get the deps from.