From c835464096ce2b210e9f74063fda91b16c252552 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 15 May 2019 11:31:46 -0700 Subject: [PATCH] Support ruby 2.4+ style logger levels specified using strings or symbols --- lib/core_ext/logger.rb | 3 +-- spec/compatibility/level_spec.rb | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/core_ext/logger.rb b/lib/core_ext/logger.rb index 3e1ddba..5364dd0 100644 --- a/lib/core_ext/logger.rb +++ b/lib/core_ext/logger.rb @@ -3,7 +3,7 @@ class Logger def level_with_yell=( level ) - self.level_without_yell= Integer(level) + self.level_without_yell= level.is_a?(Yell::Level) ? Integer(level) : level end alias_method :level_without_yell=, :level= alias_method :level=, :level_with_yell= @@ -15,4 +15,3 @@ def add_with_yell( severity, message = nil, progname = nil, &block ) alias_method :add, :add_with_yell end - diff --git a/spec/compatibility/level_spec.rb b/spec/compatibility/level_spec.rb index 42aebff..edb11e4 100644 --- a/spec/compatibility/level_spec.rb +++ b/spec/compatibility/level_spec.rb @@ -2,17 +2,35 @@ require 'logger' describe "backwards compatible level" do - - let(:level) { Yell::Level.new(:error) } let(:logger) { Logger.new($stdout) } before do logger.level = level end - it "should format out the level correctly" do - expect(logger.level).to eq(level.to_i) + context "with a Yell::Level instance" do + let(:level) { Yell::Level.new(:error) } + + it "should format out the level correctly" do + expect(logger.level).to eq(level.to_i) + end end -end + context "with a symbol", :pending => (RUBY_VERSION < "2.3") do + let(:level) { :error } + + it "should format out the level correctly" do + expect(logger.level).to eq(3) + end + end + context "with an integer" do + let(:level) { 2 } + + it "should format out the level correctly" do + expect(logger.level).to eq(2) + end + end + + +end