Limit log file size?

i used search and did not find anything helpful…

how can i limit the log file size? it was 7GB (on an old RPI 2 with 32GB SD Card)
for now i changed log level to fatal about same as no log but that is not optimal… also would be nice to write the log file to RAM

You can search the forum using keyword “log rotate” or click the tag under the title.

i think i know log rotate from rsyslog but that does not work for docker does it?

If you redirected logs to the file, the logrotate will work the same way, as for regular services.
If you didn’t - you may specify the internal log limits and rotation with options

1 Like

thanks just for info maybe it helps someone:
i did now use the 2 --log commands u told me and i made a ramdisk in /store/ram (with mount -t tmpfs -o size=1024m myramdisk /store/ram/)

in config.yaml i set the log path to log.output: "/app/config/ram/node.log"

looks like its working fine and if the “–log-opt max-size=10m” works with 5 files max the ram disk should never get more than ~50MB… maybe 1GB was too much but no problem, switched from RPI to old PC with 16GB RAM

too bad that is not working:

root@store:/store/ram# ll -h
total 12M
drwxrwxrwt 2 root root   60 May 22 12:53 ./
drwxr-xr-x 5 root root 4.0K May 22 14:53 ../
-rw-r--r-- 1 root root  12M May 22 15:01 node.log

log is 12 MB already and i did use --log-opt max-size=10m

you can create a /etc/docker/daemon.json

here are the options I got on mine

{
  "log-driver": "local",
  "log-opts": {
    "max-size": "10m",
    "max-file": "15"
  },
  "shutdown-timeout": 300,
  "live-restore": true
}

1 Like

thanks, in the meantime i made a cronjob that emptys the logfile once per day

1 Like

the docker’s options --log-opt working only if you do not redirect logs.
If you redirected logs - you need to use a logrotate or similar script to rotate them yourself. In case of RAM like you used it - it’s not possible at all.
If you want to reduce a verbosity you may set the log level to error instead of info.

2 Likes