mini_logger 0.5.4 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mini_logger.rb +35 -55
- data/lib/version.rb +2 -2
- data/test/test_mini_logger.rb +16 -14
- metadata +59 -36
data/lib/mini_logger.rb
CHANGED
@@ -3,8 +3,10 @@ require 'yaml'
|
|
3
3
|
require 'forwardable'
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
extend
|
6
|
+
class MiniLogger
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@logger, :debug, :info, :warn, :error, :fatal, :debug?, :info?, :warn?, :error?, :fatal?
|
8
10
|
|
9
11
|
DEBUG = :debug
|
10
12
|
INFO = :info
|
@@ -28,93 +30,71 @@ module MiniLogger
|
|
28
30
|
::Logger::FATAL => FATAL
|
29
31
|
}
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
def self.standarize_log_level(ll)
|
33
|
+
private
|
34
|
+
def self.standarize_log_level(level)
|
34
35
|
|
35
|
-
case
|
36
|
-
when String then LLM[
|
37
|
-
when Symbol then LLM[
|
36
|
+
case level
|
37
|
+
when String then LLM[level.downcase.to_sym]
|
38
|
+
when Symbol then LLM[level.to_s.downcase.to_sym]
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
|
42
|
-
|
43
|
+
public
|
44
|
+
def self.validate_log_level?(level)
|
43
45
|
|
44
|
-
case
|
45
|
-
when String then LLM.has_key?(
|
46
|
-
when Symbol then LLM.has_key?(
|
46
|
+
case level
|
47
|
+
when String then LLM.has_key?(level.downcase.to_sym)
|
48
|
+
when Symbol then LLM.has_key?(level.to_s.downcase.to_sym)
|
47
49
|
else false
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
|
52
|
-
def configure(*arguments)
|
54
|
+
def self.configure(*arguments)
|
53
55
|
|
54
|
-
configuration =
|
56
|
+
configuration = Hash.new
|
55
57
|
|
56
58
|
case arguments[0]
|
57
|
-
when String
|
58
|
-
|
59
|
-
|
60
|
-
configuration.merge!(arguments[0])
|
61
|
-
else
|
62
|
-
configuration = { :dev=>STDERR, :level=>:debug }
|
59
|
+
when String then configuration.merge!(YAML.load_file(arguments[0]))
|
60
|
+
when Hash then configuration.merge!(arguments[0])
|
61
|
+
else configuration = { :dev=>STDERR, :level=>:debug }
|
63
62
|
end
|
64
63
|
|
65
64
|
configuration = { :log_channel=>STDERR, :log_level=>:info }.merge(configuration)
|
66
65
|
|
67
|
-
configuration[:dev]
|
68
|
-
configuration[:level]
|
66
|
+
configuration[:dev] ||= configuration[:log_channel]
|
67
|
+
configuration[:level] ||= configuration[:log_level]
|
69
68
|
|
70
69
|
raise ArgumentError.new("Invalid log level") unless validate_log_level?(configuration[:level])
|
71
70
|
|
72
|
-
configuration[:dev] = case configuration[:dev]
|
73
|
-
when /
|
74
|
-
when /
|
75
|
-
when :stdout then STDOUT
|
76
|
-
when :stderr then STDERR
|
71
|
+
configuration[:dev] = case configuration[:dev].to_s.downcase
|
72
|
+
when /stdout/ then STDOUT
|
73
|
+
when /stderr/ then STDERR
|
77
74
|
else configuration[:dev]
|
78
75
|
end
|
79
76
|
|
80
|
-
|
81
|
-
@logger.level = standarize_log_level(configuration[:level])
|
82
|
-
|
83
|
-
self
|
77
|
+
self.new(configuration)
|
84
78
|
end
|
85
79
|
|
86
|
-
def
|
80
|
+
def initialize(options)
|
87
81
|
|
88
|
-
|
82
|
+
@logger = ::Logger.new(options[:dev])
|
83
|
+
@logger.level = MiniLogger.standarize_log_level(options[:level])
|
89
84
|
|
90
|
-
|
91
|
-
@logger.level = standarize_log_level(nll)
|
92
|
-
|
93
|
-
self
|
94
|
-
end
|
85
|
+
self
|
95
86
|
end
|
96
87
|
|
97
|
-
def level
|
88
|
+
def level=(level)
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
self
|
105
|
-
end
|
90
|
+
raise ArgumentError.new("Invalid log level #{level.class.name}:'#{level}'") unless MiniLogger.validate_log_level?(level)
|
91
|
+
@logger.level = MiniLogger.standarize_log_level(level)
|
92
|
+
|
93
|
+
self
|
106
94
|
end
|
107
95
|
|
108
96
|
def level
|
109
97
|
|
110
|
-
RLLM[@logger.level]
|
98
|
+
RLLM[@logger.level]
|
111
99
|
end
|
112
|
-
|
113
|
-
def method_missing(method, *arguments, &block)
|
114
|
-
|
115
|
-
if @logger && [:debug, :info, :warn, :error, :fatal, :debug?, :info?, :warn?, :error?, :fatal?].include?(method)
|
116
|
-
|
117
|
-
@logger.send(method, *arguments, &block)
|
118
|
-
end
|
119
|
-
end
|
120
100
|
end
|
data/lib/version.rb
CHANGED
data/test/test_mini_logger.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
2
2
|
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
3
3
|
|
4
|
-
|
5
4
|
require 'rubygems'
|
6
5
|
require 'tmpdir'
|
7
6
|
require 'delorean'
|
@@ -61,13 +60,8 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
61
60
|
assert(test_logger.info?, "Log level:'#{test_logger.level}'")
|
62
61
|
|
63
62
|
##
|
64
|
-
#
|
65
|
-
test_logger = MiniLogger.configure(:
|
66
|
-
assert(test_logger.warn?, "Log level:'#{test_logger.level}")
|
67
|
-
|
68
|
-
##
|
69
|
-
# Mix configuration interface
|
70
|
-
test_logger = MiniLogger.configure(:dev=>STDERR, :log_level=>:error)
|
63
|
+
# New configuration interface
|
64
|
+
test_logger = MiniLogger.configure(:dev=>STDERR, :level=>:error)
|
71
65
|
assert(test_logger.error?, "Log level:'#{test_logger.level}")
|
72
66
|
end
|
73
67
|
|
@@ -122,13 +116,21 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
122
116
|
|
123
117
|
test_logger.level = MiniLogger::ERROR
|
124
118
|
assert test_logger.error?
|
125
|
-
assert_equal(test_logger.level, MiniLogger::ERROR)
|
126
119
|
|
127
|
-
|
128
|
-
assert test_logger.
|
129
|
-
|
130
|
-
|
131
|
-
assert test_logger.
|
120
|
+
test_logger.level=MiniLogger::DEBUG
|
121
|
+
assert test_logger.debug?
|
122
|
+
|
123
|
+
test_logger.level=MiniLogger::INFO
|
124
|
+
assert test_logger.info?
|
125
|
+
|
126
|
+
test_logger.level=MiniLogger::WARN
|
127
|
+
assert test_logger.warn?
|
128
|
+
|
129
|
+
test_logger.level=MiniLogger::ERROR
|
130
|
+
assert test_logger.error?
|
131
|
+
|
132
|
+
test_logger.level=MiniLogger::FATAL
|
133
|
+
assert test_logger.fatal?
|
132
134
|
end
|
133
135
|
|
134
136
|
|
metadata
CHANGED
@@ -1,45 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_logger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Javier Juarez
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: &
|
17
|
+
|
18
|
+
date: 2011-07-07 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
22
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
version_requirements: *id001
|
22
31
|
type: :development
|
32
|
+
name: jeweler
|
23
33
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
name: rcov
|
27
|
-
requirement: &2156648060 !ruby/object:Gem::Requirement
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
36
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
version_requirements: *id002
|
33
45
|
type: :development
|
46
|
+
name: rcov
|
34
47
|
prerelease: false
|
35
|
-
version_requirements: *2156648060
|
36
48
|
description: A minimal standard Logger wrapper perfect for CLI applications
|
37
49
|
email: javier.juarez@gmail.com
|
38
50
|
executables: []
|
51
|
+
|
39
52
|
extensions: []
|
40
|
-
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
41
55
|
- README.rdoc
|
42
|
-
files:
|
56
|
+
files:
|
43
57
|
- lib/mini_logger.rb
|
44
58
|
- lib/version.rb
|
45
59
|
- test/helpers/tail_file_helper.rb
|
@@ -47,28 +61,37 @@ files:
|
|
47
61
|
- test/unit_extensions.rb
|
48
62
|
- README.rdoc
|
49
63
|
homepage: http://github.com/jjuarez/mini_logger
|
50
|
-
licenses:
|
64
|
+
licenses:
|
51
65
|
- MIT
|
52
66
|
post_install_message:
|
53
67
|
rdoc_options: []
|
54
|
-
|
68
|
+
|
69
|
+
require_paths:
|
55
70
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
72
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
81
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
68
89
|
requirements: []
|
90
|
+
|
69
91
|
rubyforge_project: http://github.com/jjuarez/mini_logger
|
70
92
|
rubygems_version: 1.8.5
|
71
93
|
signing_key:
|
72
94
|
specification_version: 3
|
73
95
|
summary: A tiny logger utility for small applications
|
74
96
|
test_files: []
|
97
|
+
|