fizx-loggable 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/loggable.rb +9 -1
  2. data/test/test_loggable.rb +2 -3
  3. metadata +1 -1
@@ -17,12 +17,20 @@ require "logger"
17
17
  def default
18
18
  return @default_logger if @default_logger
19
19
  @default_logger ||= Logger.new(STDOUT)
20
- @default_logger.level = ENV["LOG_LEVEL"] if ENV["LOG_LEVEL"]
20
+ level = to_log_level(ENV["LOG_LEVEL"])
21
+ @default_logger.level = level if level
21
22
  @default_logger
22
23
  end
24
+
23
25
  def default=(l)
24
26
  @default_logger = l
25
27
  end
28
+
29
+ def to_log_level(str)
30
+ Logger.const_get(str.upcase)
31
+ rescue NameError
32
+ nil
33
+ end
26
34
  end
27
35
 
28
36
  def l
@@ -40,12 +40,11 @@ class TestLoggable < Test::Unit::TestCase
40
40
  def test_env
41
41
  Loggable.default = nil
42
42
  ENV["LOG_LEVEL"] = "info"
43
- assert_equal "info", Loggable.default.level
43
+ assert_equal Logger::INFO, Loggable.default.level
44
44
 
45
45
  Loggable.default = nil
46
46
  ENV["LOG_LEVEL"] = "debug"
47
- assert_equal "debug", Loggable.default.level
48
-
47
+ assert_equal Logger::DEBUG, Loggable.default.level
49
48
  end
50
49
 
51
50
  def test_class_methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fizx-loggable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Maxwell