# Docker logging to file

**URL:** <https://forum.keycloak.org/t/docker-logging-to-file/1665>\
**Category:** Getting advice\
**Created:** [March 11, 2020, 11:16pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665 "2020-03-11T23:16:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerkovicl](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jerkovicl/32/490_2.png) [@jerkovicl](https://forum.keycloak.org/u/jerkovicl)\
**Post date:** [March 11, 2020, 11:16pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/1 "2020-03-11T23:16:23Z")

</div>

How can I expose keycloak log to file on host from container to able to parse it with fail2ban?  
I tried volume mounting but I am getting permission denied errors

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [March 12, 2020, 7:51am UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/2 "2020-03-12T07:51:54Z")

</div>

That should be done on your docker level, where you “redirect/store” logs from the container. It depends on used docker log driver, but default `json-file` log to the file. See `docker inspect <keycloak-container> | grep LogPath`. Hacking with volumes is also possible, but it requires to configure logging of the Keycloak itself + it may be a mess when you will be scaling and all Keycloak containers will be writing to the same log file.

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [March 12, 2020, 7:56am UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/3 "2020-03-12T07:56:03Z")

</div>

You can put the following in your jail

```
logpath = /var/lib/docker/containers/*/*-json.log
```

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [March 12, 2020, 9:43am UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/4 "2020-03-12T09:43:46Z")

</div>

> [@zonaut](#):
>
> /var/lib/docker/containers/_/_-json.log

But this includes logs of all containers on the host, not just Keycloak container.

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [March 12, 2020, 3:42pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/5 "2020-03-12T15:42:09Z")

</div>

Yes, this fits my use case because the containers that I am running are also the only ones I need to check.  
If his use case is different he can off course be more detailed in his configuration.

---

<div class="post-metadata">

**Author:** ![jerkovicl](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jerkovicl/32/490_2.png) [@jerkovicl](https://forum.keycloak.org/u/jerkovicl)\
**Post date:** [March 12, 2020, 7:32pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/6 "2020-03-12T19:32:37Z")

</div>

ok i managed to volume mount the `server.log` file from `/opt/jboss/keycloak/standalone/log/server.log` but login errors are not being written in that file only in docker log, any idea what to change?  
Activated saving login events from admin audit and events section also.

---

<div class="post-metadata">

**Author:** ![Robinyo](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@Robinyo](https://forum.keycloak.org/u/Robinyo)\
**Post date:** [March 14, 2020, 8:49pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/7 "2020-03-14T20:49:07Z")

</div>

This project might also be of interest:

- [OpenTelemetry](https://opentelemetry.io/)
- [OpenTracing on Kubernetes](https://medium.com/opentracing/opentracing-on-kubernetes-get-yer-tracing-for-free-7a69cca03c8a)
- [Java Agent for OpenTracing](https://github.com/opentracing-contrib/java-specialagent#44-instrumentation-plugin)

---

<div class="post-metadata">

**Author:** ![Medardus2004](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/medardus2004/32/2566_2.png) [@Medardus2004](https://forum.keycloak.org/u/Medardus2004)\
**Post date:** [March 7, 2021, 10:12am UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/8 "2021-03-07T10:12:14Z")

</div>

I have the same issue,  
did you find some solution?

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://forum.keycloak.org/u/chrisk)\
**Post date:** [January 30, 2023, 12:43pm UTC](https://forum.keycloak.org/t/docker-logging-to-file/1665/9 "2023-01-30T12:43:17Z")

</div>

I am interested also on this, I found that there is folder tools that contains the loglevel.cli that is called during the build yet, what is the right configuration in order to achieve that @jerkovicl wants?
