Java Spring boot on docker logging rolling policy doesn't limit amount of log archives

Viewed 25

When I was running some test instances on multiple server I encountered a not enough space on some of the locations and as I inspected it was an issue with logger. I use @Slf4j annotation to log.

Here is my configuration for logging:

# Logging
logging.level.root=INFO
logging.level.web=INFO
logging.logback.rollingpolicy.max-file-size=20MB
logging.file.name=logs/ims-app.log
logging.file.path=logs
logging.logback.rollingpolicy.max-history=7

Recent logs inside the docker:

/logs # ls -lah
total 7M
drwxr-xr-x    2 root     root        4.0K Sep 22 17:40 .
drwxr-xr-x    1 root     root        4.0K Sep 22 11:26 ..
-rw-r--r--    1 root     root      543.8K Sep 22 17:41 ims-app.log
-rw-r--r--    1 root     root      507.2K Sep 22 11:52 ims-app.log.2022-09-22.0.gz
-rw-r--r--    1 root     root      507.1K Sep 22 12:21 ims-app.log.2022-09-22.1.gz
-rw-r--r--    1 root     root      495.6K Sep 22 16:21 ims-app.log.2022-09-22.10.gz
-rw-r--r--    1 root     root      497.5K Sep 22 16:48 ims-app.log.2022-09-22.11.gz
-rw-r--r--    1 root     root      495.7K Sep 22 17:14 ims-app.log.2022-09-22.12.gz
-rw-r--r--    1 root     root      496.6K Sep 22 17:40 ims-app.log.2022-09-22.13.gz
-rw-r--r--    1 root     root      496.2K Sep 22 12:48 ims-app.log.2022-09-22.2.gz
-rw-r--r--    1 root     root      499.8K Sep 22 13:15 ims-app.log.2022-09-22.3.gz
-rw-r--r--    1 root     root      497.8K Sep 22 13:42 ims-app.log.2022-09-22.4.gz
-rw-r--r--    1 root     root      498.6K Sep 22 14:09 ims-app.log.2022-09-22.5.gz
-rw-r--r--    1 root     root      499.5K Sep 22 14:36 ims-app.log.2022-09-22.6.gz
-rw-r--r--    1 root     root      498.2K Sep 22 15:03 ims-app.log.2022-09-22.7.gz
-rw-r--r--    1 root     root      496.7K Sep 22 15:29 ims-app.log.2022-09-22.8.gz
-rw-r--r--    1 root     root      496.4K Sep 22 15:56 ims-app.log.2022-09-22.9.gz

After this issue I decided to move to a centralized logging with elk, but this issue will still continue on the java side. How do I limit how many log file for an instance. I still want to save recent logs as files, but in 30 days it exceeded 19GB (on the dev server) any suggestion on this?

1 Answers

You should not produce log files inside a running container. Just instruct log4j to write to standard output. This is a good practice.

If you need the files then map a volume and have the files saved in that folder. This way your container is not impacted and your only problem is the space on the host.

Related