1

Lets say I want to logrotate when the filesize is 1kb . Before the run if the filesize of the log is 4kb I expect logrotate to create 4 different log files.

Before:

something.log (4kb) 

What I expect to happen.

something.log (0kb) 
something.log.1 (1kb)
something.log.2 (1kb)
something.log.3 (1kb)
something.log.4 (1kb)

But currently what is happening is

something.log (0kb) 
something.log.1 (4kb)

Even though I have given the size to be 1k.

The program reading the logs cant handle files larger than a certain size so I want to use logrotate to keep size in check.

Example logrotate confing file I am using

/pathme/something/data/*/logs/*.log {
su username1 username1
missingok
rotate 10
notifempty
size 1k
copytruncate}
userskin
  • 13
  • 2

1 Answers1

0

Logrotate will by default only be run by cron once a day, look at its config and act accordingly. If a log file exceeds whatever max size you told it to have in the logrotate config during (say) the afternoon, logrotate will not do anything about it until it runs. That typically happens around midnight.

If you need pinpoint-ish precision on logfile sizes, I suggest you run logrotate more frequent (hourly, every 30 mins or whatever), and then also configure logrotate with a smaller value than the required max size to avoid having the logfiles becoming too large for the program needing to read them.

You didn't specify the OS, but the daily system cron jobs are typically in /etc/cron.daily or similar.

TorW
  • 61
  • 5
  • 1
    Thank you yes. I had also come to the same conclusion. Just running logrotate in shorter frequencies. – userskin Jul 28 '23 at 09:57