kros365
kros365

Reputation: 105

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?

Upvotes: 3

Views: 8485

Answers (4)

Aleksey Vanin
Aleksey Vanin

Reputation: 11

If you want to write log to file inside container, make sure the whole path to the file directory are created + has the appropriate rights for the user. For example, you can create necessary staff in dockerfile with follow instructions:

RUN useradd -u 1001 tech_user
RUN mkdir -p /opt/tomcat/logs/
RUN chown -R tech_user /opt/tomcat/logs

chown & useradd needed only if you run the process as non root.

Upvotes: 1

Tara
Tara

Reputation: 21

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

Upvotes: 2

Alan Brown
Alan Brown

Reputation: 21

If you log to console (not file) then you will be able to view the logs using the 'docker logs' command. Generally, logging to file in docker is not of much use as the file will disappear with the container.

Upvotes: 1

Doflamingo19
Doflamingo19

Reputation: 1629

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.

Upvotes: 1

Related Questions