lib/timber/logger.rb in timber-2.1.0.rc4 vs lib/timber/logger.rb in timber-2.1.0.rc5

- old
+ new

@@ -230,10 +230,17 @@ end super end + def level=(value) + if value.is_a?(Symbol) + value = level_from_symbol(value) + end + super + end + # Convenience method for adding context. Please see {{Timber::CurrentContext.with}} for # a more detailed description and examples. def with_context(context, &block) Timber::CurrentContext.with(context, &block) end @@ -267,8 +274,20 @@ private def environment_level level = ([ENV['LOG_LEVEL'].to_s.upcase, "DEBUG"] & %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]).compact.first self.class.const_get(level) + end + + def level_from_symbol(value) + case value + when :debug; DEBUG + when :info; INFO + when :warn; WARN + when :error; ERROR + when :fatal; FATAL + when :unknown; UNKNOWN + else; raise ArgumentError.new("level #{value.inspect} is not a valid logger level") + end end end end \ No newline at end of file