fizx-loggable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/lib/loggable.rb +5 -2
- data/test/test_loggable.rb +11 -0
- metadata +1 -1
data/README
CHANGED
data/lib/loggable.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "logger"
|
2
|
-
module Loggable
|
2
|
+
module Loggable
|
3
3
|
module ClassMethods
|
4
4
|
def logger
|
5
5
|
@logger || Loggable.default
|
@@ -15,10 +15,13 @@ module Loggable
|
|
15
15
|
|
16
16
|
module LoggableMethods
|
17
17
|
def default
|
18
|
+
return @default_logger if @default_logger
|
18
19
|
@default_logger ||= Logger.new(STDOUT)
|
20
|
+
@default_logger.level = ENV["LOG_LEVEL"] if ENV["LOG_LEVEL"]
|
21
|
+
@default_logger
|
19
22
|
end
|
20
23
|
def default=(l)
|
21
|
-
@
|
24
|
+
@default_logger = l
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
data/test/test_loggable.rb
CHANGED
@@ -32,4 +32,15 @@ class TestLoggable < Test::Unit::TestCase
|
|
32
32
|
l.info "info"
|
33
33
|
l.debug "debug"
|
34
34
|
end
|
35
|
+
|
36
|
+
def test_env
|
37
|
+
Loggable.default = nil
|
38
|
+
ENV["LOG_LEVEL"] = "info"
|
39
|
+
assert_equal "info", Loggable.default.level
|
40
|
+
|
41
|
+
Loggable.default = nil
|
42
|
+
ENV["LOG_LEVEL"] = "debug"
|
43
|
+
assert_equal "debug", Loggable.default.level
|
44
|
+
|
45
|
+
end
|
35
46
|
end
|