How log rotation works in rails

8 views
Skip to first unread message

Loganathan Sellapa

unread,
Jan 1, 2015, 8:02:48 AM1/1/15
to bangal...@googlegroups.com
Hi All, 

I have implemented the log rotation feature for my application, and I am seeing unexpected behaviors in the log rotation.

  Logger.new('log/production.log', 3, 50.kilobytes)

ASSUMPTIONS:  

I have assumed that the above code will rotate the log whenever the log file reaches 50KB, as same as the below manner

1. When I restart the application with log rotation changes, old log file needs to be moved to backup logs if it is has content more than 50KB
2. production.log reaches 50 KB first time
3. production.log content will be moved to new file called  production.log.0
4. production.log again reaches 50 KB
5. production.log.0 content will be moved completely to production.log.1
6. production.log content moved to  production.log.0 and the production.log becomes  empty.
7. The contents of the the log files production.log, production.log.0 and production.log.1 are needs to be in sequentia order like below
  •      production.log has content FROM 11AM to 12PM
  •      production.log.0  has content FROM 10AM to 11AM
  •      production.log.1  has content FROM 9AM to 10AM

Actual behavior:

1. When I start the application after log rotation settings, my current log is cleared completely and no backup is taken
2. Then I process some request in my application
3. production.log reaches 50 KB first time
4. Part of the content of  production.log is moved to production.log.0
5. Part of the content of  production.log.0 is moved to production.log.1
6. The contents of the  log files production.log,  production.log.0 and production.log.1 are not in sequential order, instead it has the content as like below

  •      production.log has content FROM 11AM to 12PM
  •      production.log.0  has content FROM 10AM to 1AM
  •      production.log.1  has content FROM 9AM to 10AM, and some contents from 11.20AM to 11.25AM
Can anybody let me know the issue over here?

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe

Shireesh

unread,
Jan 2, 2015, 2:11:48 AM1/2/15
to bangal...@googlegroups.com
The rails default log rotation didn't work very well for us also.
We've recently moved to using the linux "logrotate" tool, which seems to be doing a good job.

~Shireesh

Loganathan Sellapa

unread,
Jan 2, 2015, 2:13:04 AM1/2/15
to bangal...@googlegroups.com
Did you face the same kind of issues?

regards,
Loganathan
Mob: +91 7760780741 | +91 9944414388
Skype: loganathan.sellappa
ViewMe


--
You received this message because you are subscribed to the Google Groups "BANGALORE RUG-Ruby Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bangalorerug...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Srushti Ambekallu

unread,
Jan 2, 2015, 2:15:06 AM1/2/15
to bangal...@googlegroups.com, bangal...@googlegroups.com
I've never tried the Rails rotation. I've always used logrotate (for Rails and non-Rails projects) which has been around for ages and works well. I would stick to that. You'll want to spend a bit of time understanding the options though. 


Thanks,
Srushti


Reply all
Reply to author
Forward
0 new messages