-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Friday 21 June 2019

log to a new file every day in rails?

 a solution that will allow me to create a new log file for rails application everyday.
The goal is to go from standard production.log to
production.2019-06-01.log
production.2019-06-02.log
...etc
Where the latest log is has today's date.
I am aware of logrotate application but the issue is that production.log is current one, production.log.1 is supposedly yesterdays. So if you want to find something that happened on a specific day few weeks ago, you'll need to eyeball which log file it will be in.

The solution

logger = Logger.new('production.log', 'daily') # or 'weekly', 'monthly'
To get the desired output use :
t = Time.now()
file = 'production.' + (t.strftime("%m-%d-%y")) + '.log' 
logger = Logger.new(file, 'daily') # or 'weekly', 'monthly'

No comments:

Post a Comment

Thanks for your comments

Rank

seo