Logging to disk without FS overflow

By default logging is set to RAM with circular buffer. I am trying to identify if it is possible to make logging onto the disk in circular manner defining the max size of file. The purpose is system log surviving reboot/power off, with controlled risk of FS overflow.

The doc says

Note : If log_type is set to file, then at some point when the log fills, the device may encounter an out-of-space condition. This is especially an issue for devices with limited onboard storage: in memory, or on flash.

But at the same time there're log_size and log_buffer_size, and these do not state they apply to only RAM-based logging.

Please advise. Thanks.

If you are using Luci System -> System -> Logging -> Log Buffer Size setting doesn't appear to set config/system's log_buffer_size, but instead it sets log_size

When log_file and log_size are set, then a file is written to the maximum size set in log_size. When it reaches that size, it is renamed to log_file.old (the previous log_file.old, if present, is deleted first) and a new log_file is created. So the maximum written will be log_size x 2.

If you are redirecting the log to a persistent file, I highly recommend it not be to somewhere located on the device's internal flash. That will cause a low-level of constant writes to your flash. In some cases, there are realistic error conditions that can occur on the device that can cause a megabyte or more a day to be written to the log. This can cause significant wear to a device's irreplaceable internal flash.

there's also logrotate ...

1 Like

@frollic and @VA1DER thank you very much for the information. I finally got working on it, and seem need some more help. I switch system log to the SD-card, but it seems system logging starts before SD-card is mounted (logically) and system log file does not appear on the SD-card. What would be the right procedure to switch log file to the removable location, or have it switched automatically when SD-card is mounted?

I am ok with the two-log-file configuration, adding logrotate would be the next step if system-provided logging mechanism will prove unsatisfactory.