mini_logger 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/mini_logger.rb +39 -42
- data/lib/version.rb +1 -1
- data/test/test_mini_logger.rb +4 -0
- metadata +2 -2
data/README.rdoc
CHANGED
data/lib/mini_logger.rb
CHANGED
@@ -5,63 +5,60 @@ require 'logger'
|
|
5
5
|
module MiniLogger
|
6
6
|
extend self
|
7
7
|
|
8
|
-
|
9
|
-
:debug
|
10
|
-
:info
|
11
|
-
:warn
|
12
|
-
:error
|
13
|
-
:faltal
|
8
|
+
LLM = {
|
9
|
+
:debug =>Logger::DEBUG,
|
10
|
+
:info =>Logger::INFO,
|
11
|
+
:warn =>Logger::WARN,
|
12
|
+
:error =>Logger::ERROR,
|
13
|
+
:faltal =>Logger::FATAL
|
14
14
|
}
|
15
15
|
|
16
|
-
DEBUG
|
17
|
-
INFO
|
18
|
-
WARN
|
19
|
-
ERROR
|
20
|
-
FATAL
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@logger.level ||= log_level
|
35
|
-
@logger.datetime_format ||= dt_format
|
16
|
+
DEBUG = :debug
|
17
|
+
INFO = :info
|
18
|
+
WARN = :warn
|
19
|
+
ERROR = :error
|
20
|
+
FATAL = :fatal
|
21
|
+
|
22
|
+
private
|
23
|
+
def validate_log_level?( log_level )
|
24
|
+
LLM.has_key?( log_level )
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_log_level( log_level )
|
28
|
+
LLM[log_level]
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
public
|
33
|
+
def configure( atts = { } )
|
36
34
|
|
35
|
+
@logger = Logger.new( atts[:log_channel] ? atts[:log_channel] : STDERR )
|
36
|
+
@logger.level = validate_log_level?( atts[:log_level] ) ? get_log_level( atts[:log_level] ) : Logger::INFO
|
37
37
|
self
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
self.configure unless @logger
|
43
|
-
|
40
|
+
def level( )
|
41
|
+
@logger || configure
|
44
42
|
@logger.level
|
45
|
-
end
|
46
|
-
|
43
|
+
end
|
47
44
|
|
48
45
|
def level=( new_log_level )
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
if
|
53
|
-
@logger.level = new_log_level
|
54
|
-
else
|
47
|
+
@logger || configure
|
48
|
+
|
49
|
+
if( validate_log_level?( new_log_level ) )
|
50
|
+
@logger.level = get_log_level( new_log_level )
|
51
|
+
else
|
55
52
|
raise ArgumentError.new( "Bad log level: #{new_log_level}" )
|
56
|
-
end
|
53
|
+
end
|
57
54
|
end
|
58
55
|
|
59
|
-
|
60
56
|
def method_missing( method, *arguments, &block )
|
61
57
|
|
62
|
-
|
58
|
+
@logger || configure
|
63
59
|
|
64
|
-
|
65
|
-
|
60
|
+
if( [ :debug, :debug?, :info, :info?, :warn, :warn?, :error, :error?, :fatal ].include?( method ) )
|
61
|
+
@logger.send( method, *arguments, &block )
|
62
|
+
end
|
66
63
|
end
|
67
64
|
end
|
data/lib/version.rb
CHANGED
data/test/test_mini_logger.rb
CHANGED
@@ -14,6 +14,10 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
14
14
|
@mini_logger_debug = MiniLogger.configure( :log_channel=>"/dev/null", :log_level=>MiniLogger::DEBUG )
|
15
15
|
end
|
16
16
|
|
17
|
+
should "a info log level" do
|
18
|
+
assert( MiniLogger.configure.info? )
|
19
|
+
end
|
20
|
+
|
17
21
|
should "write a debug line" do
|
18
22
|
assert( @mini_logger_debug.debug( "debug" ) )
|
19
23
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mini_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Javier Juarez
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-16 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|