This module implements methods that act somewhat like Ruby's Logger class It is included in Cabin::Channel
# File lib/cabin/mixins/logger.rb, line 17 def level=(value) if value.respond_to?(:downcase) @level = value.downcase.to_sym else @level = value.to_sym end end
# File lib/cabin/mixins/logger.rb, line 82 def log(message, data={}) _log(message, data) end
# File lib/cabin/mixins/logger.rb, line 86 def _log(message, data={}) case message when Hash data.merge!(message) when Exception # message is an exception data[:message] = message.to_s data[:exception] = message.class data[:backtrace] = message.backtrace else data = { :message => message }.merge(data) end # Add extra debugging bits (file, line, method) if level is debug. debugharder(caller[2], data) if @level == :debug publish(data) end
This method is used to pull useful information about the caller of the logging method such as the caller's file, method, and line number.
# File lib/cabin/mixins/logger.rb, line 107 def debugharder(callinfo, data) m = BACKTRACE_RE.match(callinfo) return unless m path, line, method = m[1..3] whence = $:.detect { |p| path.start_with?(p) } if whence # Remove the RUBYLIB path portion of the full file name file = path[whence.length + 1..-1] else # We get here if the path is not in $: file = path end data[:file] = file data[:line] = line data[:method] = method end
# File lib/cabin/mixins/logger.rb, line 76 def log_with_level(level, message, data={}) # Invoke 'info?' etc to ask if we should act. data[:level] = level _log(message, data) end