Logging In A Spring Boot Application Deployed to Docker Tomcat

Advertisements

I have a dockerized dev environment set up with a few images:

  • Tomcat 10.0
  • Postgres 12.1
  • PgAdmin 4

I have configured Tomcat to activate the manager webapp so that I can use the Maven cargo plugin to deploy a Spring Boot application. The deployment seems to work in the sense that cargo correctly uploads my war to the manager. Unfortunately, it will not write an application log, and the application is not working (sure would be nice to see logs to figure out why, right?).

Here is the relevant section of my docker-compose.yml file. I have the logs directory directed to a volume on my host system.

services:
  tomcat:
    container_name: tomcat
    image: tomcat:10.0-jdk11-openjdk
    restart: always
    
    ports: 
      - "8080:8080"
    networks:
      static:
        ipv4_address: 192.168.20.10
    volumes:
    - '/home/jason/development/projects/docker/java-dev-environment/volumes/tomcat/usr_local_tomcat_conf:/usr/local/tomcat/conf'
    - '/home/jason/development/projects/docker/java-dev-environment/volumes/tomcat/usr_local_tomcat_webapps:/usr/local/tomcat/webapps'
    - '/home/jason/development/projects/docker/java-dev-environment/volumes/tomcat/usr_local_tomcat_logs:/usr/local/tomcat/logs'

Here is the logback.xml file (which is in the src/main/resources directory of the Spring Boot app:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOGS" value="/usr/local/tomat/logs/gliese" />

    <include resource="org/springframework/boot/logging/logback/base.xml" />

    <appender name="Console"
              class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
            </Pattern>
        </layout>
    </appender>

    <appender name="RollingFile"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOGS}/gliese.log</file>
    <encoder
            class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
    </encoder>
    <rollingPolicy
            class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily and when the file reaches 10 MegaBytes -->
        <fileNamePattern>${LOGS}/gliese-%d{yyyy-MM-dd}.%i.log
        </fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>10MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    </appender>

    <!-- LOG everything at INFO level -->
    <root level="info">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />
    </root>
</configuration>

By my reading of this, this should direct application output to a subdirectory of /usr/local/tomcat/logs, which I have confirmed exists (on the home system).

Does anyone have any idea why I am not seeing the gliese.log file? I’ve hunted for it in the tomcat host container in case it went somewhere else, but no luck.

>Solution :

Unless you’re using Spring Boot 3.0 (which has not you reached GA), you should use Tomcat 9. Tomcat 10 implements the Servlet 5 specification which repackages the javax.servlet APIs to jakarta.servlet. Spring Boot won’t support this till its 3.0 release.

Leave a ReplyCancel reply