Sha256: 40e958ecb8a51bb71cbf21e8ccdc5251e1d2bb8d8fea8478d42475f5a9ce1b7b
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
# Store logger messages in specs for possible later output class MockLogger attr_accessor :messages, :errors def self.configure_log(name, _config = {}) @name = name end def initialize @messages = [] @errors = [] end def clear @messages.clear @errors.clear end %w(debug info warn).each do |level| class_eval <<-RUBY def #{level}(msg = nil, &block) msg = yield if msg.nil? && block_given? @messages << '[#{level.upcase}] :: ' + (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' + msg end RUBY end %w(error fatal).each do |level| class_eval <<-ERRORS def #{level}(msg = nil, &block) msg = yield if msg.nil? && block_given? @messages << '[#{level.upcase}] :: ' + (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' + msg @errors << '[#{level.upcase}] :: ' + (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' + msg end ERRORS end %w(debug info warn error fatal).each do |level| class_eval <<-LEVELS def #{level}? true end LEVELS end end
Version data entries
5 entries across 5 versions & 1 rubygems