• Uncategorized

About linux : Rotate-logfiles-on-an-hourly-basis-by-appending-date-and-hour

Question Detail

I wanted to implement a log rotation option in linux. I have a *.trc file where all the logs are getting written. I wanted a new log file to be created every hour. I have done some analysis and found the below

  1. I have done some analysis and got to know about the logrotate option. Where we need to update the rotation details for a specific file in the logrotate.conf file
  2. I wanted to know if there is an option without using the logrotate option. I wanted to rotate the logfiles on an hourly basis, so something like appending date and hour information to the log file and create new files based on the current hour information.

Im looking for some suggestions on how to implement the log rotation using the second option specified above.

Any details on the above would be really helpful

Question Answer

If you have control over the process that creates the logs, you could just timestamp the file at the moment of creation. This will remove the need to rename the log.

Before you write every line you check the time. If one hour passed after that file was created, you close the current file and open a new one with a new timestamp.

If you do not have control over the process, you can pipe the output of your process (stdout,stderr) to multilog, which is a binary that’s part of the package daemon-tools in most Linux distros.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.