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.
- data/lib/loggable.rb +9 -1
- data/test/test_loggable.rb +2 -3
- metadata +1 -1
data/lib/loggable.rb
CHANGED
@@ -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
|
-
|
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
|
data/test/test_loggable.rb
CHANGED
@@ -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
|
43
|
+
assert_equal Logger::INFO, Loggable.default.level
|
44
44
|
|
45
45
|
Loggable.default = nil
|
46
46
|
ENV["LOG_LEVEL"] = "debug"
|
47
|
-
assert_equal
|
48
|
-
|
47
|
+
assert_equal Logger::DEBUG, Loggable.default.level
|
49
48
|
end
|
50
49
|
|
51
50
|
def test_class_methods
|