Problems w/ logging to a file

New OpenWrt user (about 2 weeks now) on a Nighthawk XR500.

OpenWrt 22.03.5 r20134-5f15225c1e / LuCI openwrt-22.03 branch git-23.093.57104-ce20b4a

I've had partial success logging to an attached Flash drive, except that I also want to use logrotate, and the production of the .old log file is getting in the way. It seems that this is caused by the log file (in my case /mnt/sda2/log/system.log) exceeding the size set by log_size in the system config. So I tried to change that from 64 to 128 - didn't work. After Save & Apply, the log says

Wed Dec 31 16:00:00 1969 kern.emerg kernel:

and from there on, the log entries aren't going to my log file. Change it back to 64 and log entries go to my log file.
Here's the relevant section of the system config file:

config system
	option hostname 'OpenWrt'
	option ttylogin '0'
	option urandom_seed '0'
	option log_proto 'udp'
	option conloglevel '8'
	option cronloglevel '5'
	option zonename 'America/Los Angeles'
	option timezone 'PST8PDT,M3.2.0,M11.1.0'
	option log_file '/mnt/sda2/log/system.log'
	option log_remote '0'
	option log_size '64'

Is this a known limitation, or is there some way around this? At this point all I want to do is prevent the system.log.old file from being produces, so that I can move on to testing my config of logrotate.

Well, it's worse than I thought. After a few reboots the system is refusing to write to the Flash drive at all. The system config file is still as I showed it in my first post. The Flash drive is still mounted (when I ssh in) but I wonder if it's not mounting soon enough? Here's the contents of fstab config:

config global
	option anon_swap '0'
	option anon_mount '0'
	option auto_swap '1'
	option auto_mount '1'
	option delay_root '5'
	option check_fs '1'

config mount
	option target '/mnt/sda2'
	option uuid 'b47a86cd-293b-44f0-9492-010e781cd4cf'
	option enabled '1'

And another update - this doesn't seem related to log_size at all. I've now got it set for 512. But on reboot, it doesn't log to the file on the Flash drive ... until I restart the log service (via ssh). Then things seem ok.

They seem to be starting too close to each other and it is possible the mount is not completely ready by the time log starts. You can restart log from /etc/rc.local.


Thanks, @fantom-x!
I've read that on some versions of linux, rc.local can sometimes run before boot is complete, so I'm planning to try using @reboot in crontab. I'm guessing that really means it will run when the cron service starts, which is set for START=50 (well, the symlink in /etc/rc.d is S50cron) which "should" be late enough. Have you used rc.local on OpenWrt to run scripts at the end of boot?

You use udp so the logs flies out but no one cares if nothing is listening on the broadcast, so log server or other memory. Ready or not here we come and everything is lost.
You could try rotation without deleting the original file at a lower size than deletion size.

Also remember to let loose the log file after logrotate rotation.

But you are really working agains the wind here. The best solution when including logrotate is to have a real log server as the system you want is build for. Or instal rsyslog instead of default log and logrotate and let them make the work with meaningful settings as they are supposed to do.