Reputation: 2009
I am looking for 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.
Upvotes: 3
Views: 2596
Reputation: 2009
All great answers! I am currently running on tomcat, so I utilized the default java logging classes to do this.
Upvotes: 0
Reputation: 283
did you try :
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'
Upvotes: 5
Reputation: 1133
you can configure logrotate to do what you need check daily
and dateext
options here https://linux.die.net/man/8/logrotate.
also you can use the more modern way and use something like ELK https://www.elastic.co/elk-stack to index the logs in elasticsearch and use kibana dashboard to search your logs easily.
Upvotes: 4