Jaavaaan
Jaavaaan

Reputation: 122

Access log file not created in Docker container for Spring Boot application

I have a Spring-Boot application that does not create an access log file of the embedded Tomcat server while running inside a docker container. But when run outside of the container it does create a file.

Iam using a custom log configuration:

@Configuration
public class LoggingConfiguration {

    @Bean
    public WebServerFactoryCustomizer<TomcatServletWebServerFactory> connectorCustomizer(final AccessLogProperties accessLogProperties) {
        return tomcat -> {
            final JsonAccessLogValve logValve = new JsonAccessLogValve();
            logValve.setEnabled(accessLogProperties.isEnabled());
            logValve.setBuffered(accessLogProperties.isBuffered());
            logValve.setRenameOnRotate(accessLogProperties.isRenameOnRotate());
            logValve.setRotatable(accessLogProperties.isRotate());
            logValve.setPrefix(accessLogProperties.getPrefix());
            logValve.setSuffix(accessLogProperties.getSuffix());
            logValve.setPattern(accessLogProperties.getPattern());
            tomcat.addContextValves(logValve);
        };
    }
}

The properties are configured in my application.yml and made available through: AccessLogProperties.class

...
    json-access-log:
      enabled: true
      buffered: false
      pattern: "%{yyy-MM-dd'T'hh:mm:ssZ}t %I %l %u %a %r %q %s (%D ms) %{Authorization}i"
      rename-on-rotate: true
      rotate: true
      prefix: chalkup-${ACTIVE_APP_ENVIRONMENT}
      suffix: .access
...

locally a file is created in the root of my project under ./logs and there a file chalkup-local.access is created and appended with info.

sofar running in intellij results in the access file I need.

When I run the app in a docker container. No file is created:

docker config:

FROM eclipse-temurin:21-alpine
ADD ./target/chalkup-*.jar chalkup.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/chalkup.jar"]
  chalk-up:
    container_name: chalk-up
    build:
      dockerfile: Dockerfile
      context: .
    environment:
      ACTIVE_APP_ENVIRONMENT: test
    entrypoint:
      - java
      - -agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=n
      - -Djava.security.egd=file:/dev/./urandom
      - -jar
      - /chalkup.jar
      - -Dspring.profiles.active=local
    volumes:
      - /tmp/logs:/logs
    ports:
      - "8080:8080"
      - "5005:5005"
    depends_on:
      - wiremock

But when I look in the /logs dir in the running container. I only see the regular logfile but NOT the access log file

Changed the basedir, no success changed read/write permissions in the container. No success configured the regular access log server: tomcat: basedir: . accesslog: enabled: true

But this one also does not appear in the container, while it does when running outside the container

Update:

For now I have build a workaround. I have extended the JsonAccessLogValve class and overridden the log method. In this log method I simply write the message content to the sl4j log.

Upvotes: 0

Views: 98

Answers (0)

Related Questions