-
Notifications
You must be signed in to change notification settings - Fork 21
101 the datefile adapter
In many scenarios, you will want to have one file for each day, e.g. rollover of the log. This is where the Datefile
adapter comes into place. A basic datefile adapter is defined as follows:
logger = Yell.new :datefile, 'development.log'
# The same logger defined within the block
logger = Yell.new do |l|
l.adapter :datefile, 'development.log'
end
Although you have provided development.log
as filename, by default, the adapter will replace it with development.YYYYMMDD.log
, e.g. development.20121224.log
.
The standard is a daily log rotate, but you are able to change that to your own likings. You only need to pass a :date_pattern
option to the adapter, which will respect any possible string for Ruby's strftime method.
Let's assume that Time.now
results to 2012-12-24 15:00:30 +0100
logger = Yell.new do |l|
l.adapter :datefile, 'development.log', :date_pattern => "%Y%m%d-%H"
end
logger.info "Hello World!"
The message would be logged into development.20121224-15.log
. Any later hour will go into a new log file.
logger = Yell.new do |l|
l.adapter :datefile, 'development.log', :date_pattern => "%Y-week-%V"
end
logger.info "Hello World!"
The message would be logged into development.2012-week-52.log
There is a - sort-of experimental - option that you can pass to keep your logiles in check:
logger = Yell.new do |l|
l.adapter :datefile, 'development.log', :keep => 5
end
As usual, the datefile adapter will roll your files over, but this time the :keep
option will cleanup any datefile logs (of the same pattern as the current one) and only hold on to the given number.
If you want to know more, continue to How To: Different Adapters for Different Log Levels