Score:1

how to make logrotate take filesize into consideration when rotating

jp flag

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}
Score:0
al flag

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.

userskin avatar
jp flag
Thank you yes. I had also come to the same conclusion. Just running logrotate in shorter frequencies.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.