Home > Mobile >  Unable to get custom logs in Docker container while running war in inside tomcat image
Unable to get custom logs in Docker container while running war in inside tomcat image

Time:01-15

I am using logback.xml file to log in SpringBoot application..When I deploy the war file inside my local machine in tomcat then I can see the log file named test_app1.log being generated inside tomcat\logs\test_app1.log file...But when I run it in docker container, I can see the logs in terminal but the test_app1.log is not generated inside /usr/local/tomcat/logs directory of docker container..Can someone help me in resolving it?

My dockerfile content is below:

# syntax=docker/dockerfile:1

FROM tomcat:9-jdk17-temurin-focal

COPY target/test-app.war /usr/local/tomcat/webapps/

My docker command is as below;

docker run -d -p 8080:8080 test:v1

pom.xml file below:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.4</version>
        <packaging>war</packaging>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Branch>${branch}</Branch>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

and logback.xml file below:

<configuration>
    <property name="APPLICATION_NAME" value="test-app" />
    <property name="LOG_ROOT" value="../logs" />
    <property name="LOG_FILE_NAME" value="${APPLICATION_NAME}.server.log" />

    <appender name="STDOUT"
        >
        <encoder>
            <pattern>           
  • Related