Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging to file using docker and logback

I use logback for logging. logback.xml:

<configuration>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>logs/test.log</file>
        <append>true</append>
        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="FILE" />
    </root>
</configuration>

Without docker everything works fine, but with docker log file is not created. How i can see logs using docker?

like image 405
kros365 Avatar asked Jul 10 '26 08:07

kros365


2 Answers

I know this is really late, but it might help someone like me in future:

The solution is to add a volume in the docker-compose.yml file, to have a place with write permission.

in docker-compose file:

volumes:
    - ${PWD}/log:/log

in application.yml:

logging:
    file:
       name: ./log/saps.log
like image 157
Tara Avatar answered Jul 15 '26 23:07

Tara


Do you have specified in docker file the creation about /log/test.log file? I think the problem is the path that is not created in docker.

like image 42
Doflamingo19 Avatar answered Jul 16 '26 00:07

Doflamingo19