Module: Useful::RubyHelpers::Logger::ClassMethods
- Defined in:
- lib/useful/ruby_helpers/logger.rb
Instance Method Summary collapse
Instance Method Details
#benchmark(*args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/useful/ruby_helpers/logger.rb', line 9 def benchmark(*args, &block) require 'benchmark' name, msg, opts = handle_log_args(args) result = nil ms = Benchmark.measure { result = block.call }.real name += ' ' unless name.empty? name += '(%.1fms)' % [ms*1000] log(name, msg, opts) result end |
#log(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/useful/ruby_helpers/logger.rb', line 20 def log(*args) name, msg, opts = handle_log_args(args) opts[:level] ||= 'debug' unless logger.respond_to?(opts[:level].to_s) raise Exception, "no '#{opts[:level].to_s.upcase}' logger provided" end if name.empty? && msg.empty? nil else formatted_log_msg(name, msg, opts).tap do |log_msg| logger.send(opts[:level].to_s, log_msg) end end end |