require "logger" module Boty module Logger attr_writer :logger def self.adapter=(adapter) @adapter = adapter end def self.adapter @adapter ||= ::Logger.new(STDOUT).tap { |logger| logger.level = ::Logger::DEBUG } end def logger Logger.adapter end def log_error(error, message) logger.error do "#{message}\n#{error.message}" end logger.debug do error.backtrace.reduce("") { |a, e| a << "#{e}\n" } end end class Multi < ::Logger def initialize(adapters) @adapters = adapters end def level=(level) @adapters.each do |adapter| adapter.level = level end end def add(*args, &block) @adapters.each do |adapter| adapter.add(*args, &block) end end end class Memory < ::Logger attr_reader :logs def initialize(*) @logs = [] end def add(*args, &block) @logs << if block_given? block.call else args[2] end end end class Null < ::Logger def initialize(*); end def add(*, &block); end end end end