lib/filum/logger.rb in filum-2.1.0 vs lib/filum/logger.rb in filum-2.2.0
- old
+ new
@@ -1,21 +1,38 @@
require 'logger'
module Filum
class Logger < ::Logger
+
attr_reader :logfile
+
def initialize(logfile, options = {})
+ @timings = {}
@logfile = logfile
create_log_directory
super(logfile, shift_age='daily')
self.formatter = Filum::LogFormatter.new(options)
self.level = Logger::INFO
end
def context_id=(context_id)
Thread.current[:context_id] = context_id
+ end
+
+ def start_timing(label)
+ @timings[label] = Time.now
+ info("Started timing for #{label} at #{@timings[label]}")
+ end
+
+ def end_timing(label)
+ finish = Time.now
+ if @timings[label]
+ info("Stopped timing for #{label} at #{@timings[label]}, #{(finish.to_f - @timings[label].to_f).round(3)}")
+ else
+ info("Stopped timing for #{label} at #{@timings[label]}, no start time found")
+ end
end
private
def create_log_directory
return unless @logfile.is_a?(String)