teelogger 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +31 -2
- data/features/step_definitions/steps.rb +5 -1
- data/lib/teelogger/version.rb +1 -1
- data/lib/teelogger.rb +63 -39
- data/teelogger.gemspec +1 -0
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3fd651818a8e11a6ad874d35362838ed39da690
|
4
|
+
data.tar.gz: d627b5c6b302d20bd190cbfa6165f39e1aa72940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49cf31f0ff41a5ba0317eeb82315326c6c84d7c8bf0936fc7932da728d421427afbba4d51ec0975134932d25532c8f65936c2156fdcbca54c4ba3112d76af9cb
|
7
|
+
data.tar.gz: c9052b12275d86b7d4b831c9cfba8163b0c94fe05d50fcf82ae4ae55be3e976c79f75e6a1ea37873b4b2148ca9485d05db2c521441bdc8390e5e59eed6c2016f
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Teelogger
|
2
2
|
|
3
|
-
|
3
|
+
Mini wrapper around Ruby Logger for logging to multiple destinations.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/teelogger.svg)](http://badge.fury.io/rb/teelogger)
|
6
|
+
[![Build Status](https://travis-ci.org/spriteCloud/teelogger.svg?branch=master)](https://travis-ci.org/spriteCloud/teelogger)
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -18,7 +21,33 @@ Or install it yourself as:
|
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
Behaves just like Ruby's Logger, and like a hash of String => Logger.
|
25
|
+
|
26
|
+
A typical use might be to log to STDOUT, but also to a file:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'teelogger'
|
30
|
+
|
31
|
+
log = TeeLogger::TeeLogger.new(STDOUT, "filename.log")
|
32
|
+
log.level = Logger::WARN # applies to all outputs
|
33
|
+
log.level = "INFO" # convenience shortcut
|
34
|
+
```
|
35
|
+
|
36
|
+
By using the instance as a hash, you can also set individual log levels
|
37
|
+
for individual loggers:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'teelogger'
|
41
|
+
|
42
|
+
log = TeeLogger::TeeLogger.new(STDOUT, "filename.log")
|
43
|
+
log.each do |name, logger|
|
44
|
+
if name.include?("filename.log")
|
45
|
+
logger.level = "WARN"
|
46
|
+
else
|
47
|
+
logger.level = "DEBUG"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
22
51
|
|
23
52
|
## Contributing
|
24
53
|
|
data/lib/teelogger/version.rb
CHANGED
data/lib/teelogger.rb
CHANGED
@@ -33,6 +33,37 @@ module TeeLogger
|
|
33
33
|
@default_level = Logger::Severity::INFO
|
34
34
|
@loggers
|
35
35
|
|
36
|
+
##
|
37
|
+
# Convert a log level to its string name
|
38
|
+
def self.string_level(level)
|
39
|
+
if level.is_a? String
|
40
|
+
return level
|
41
|
+
end
|
42
|
+
|
43
|
+
Logger::Severity.constants.each do |const|
|
44
|
+
if level == Logger.const_get(const)
|
45
|
+
return const
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Convert a string log level to its constant value
|
54
|
+
def self.convert_level(val)
|
55
|
+
if val.is_a? String
|
56
|
+
begin
|
57
|
+
val = Logger.const_get(val)
|
58
|
+
rescue NameError
|
59
|
+
val = Logger::Severity::WARN
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
return val
|
64
|
+
end
|
65
|
+
|
66
|
+
|
36
67
|
|
37
68
|
##
|
38
69
|
# Add a logger to the current loggers.
|
@@ -48,8 +79,8 @@ module TeeLogger
|
|
48
79
|
logger = Logger.new(file)
|
49
80
|
|
50
81
|
# Initialize logger
|
51
|
-
logger.unknown "Logging to '#{arg}' initialized with level #{string_level(@default_level)}."
|
52
|
-
logger.level = convert_level(@default_level)
|
82
|
+
logger.unknown "Logging to '#{arg}' initialized with level #{TeeLogger.string_level(@default_level)}."
|
83
|
+
logger.level = TeeLogger.convert_level(@default_level)
|
53
84
|
else
|
54
85
|
# We have some other object - let's hope it's an IO object
|
55
86
|
key = arg.to_s
|
@@ -58,8 +89,8 @@ module TeeLogger
|
|
58
89
|
logger = Logger.new(arg)
|
59
90
|
|
60
91
|
# Initialize logger
|
61
|
-
logger.unknown "Logging to #{key} initialized with level #{string_level(@default_level)}."
|
62
|
-
logger.level = convert_level(@default_level)
|
92
|
+
logger.unknown "Logging to #{key} initialized with level #{TeeLogger.string_level(@default_level)}."
|
93
|
+
logger.level = TeeLogger.convert_level(@default_level)
|
63
94
|
end
|
64
95
|
|
65
96
|
if not key.nil? and not logger.nil?
|
@@ -85,42 +116,11 @@ module TeeLogger
|
|
85
116
|
end
|
86
117
|
end
|
87
118
|
|
88
|
-
##
|
89
|
-
# Convert a log level to its string name
|
90
|
-
def string_level(level)
|
91
|
-
if level.is_a? String
|
92
|
-
return level
|
93
|
-
end
|
94
|
-
|
95
|
-
Logger::Severity.constants.each do |const|
|
96
|
-
if level == Logger.const_get(const)
|
97
|
-
return const
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
return nil
|
102
|
-
end
|
103
|
-
|
104
|
-
##
|
105
|
-
# Convert a string log level to its constant value
|
106
|
-
def convert_level(val)
|
107
|
-
if val.is_a? String
|
108
|
-
begin
|
109
|
-
val = Logger.const_get(val)
|
110
|
-
rescue NameError
|
111
|
-
val = Logger::Severity::WARN
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
return val
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
119
|
##
|
120
120
|
# Set log level; override this to also accept strings
|
121
121
|
def level=(val)
|
122
122
|
# Convert strings to the constant value
|
123
|
-
val = convert_level(val)
|
123
|
+
val = TeeLogger.convert_level(val)
|
124
124
|
|
125
125
|
# Update the default log level
|
126
126
|
@default_level = val
|
@@ -139,10 +139,26 @@ module TeeLogger
|
|
139
139
|
end
|
140
140
|
|
141
141
|
|
142
|
+
##
|
143
|
+
# For each log level, define an appropriate logging function
|
144
|
+
Logger::Severity.constants.each do |const|
|
145
|
+
meth = TeeLogger.string_level(const.to_s).downcase
|
146
|
+
|
147
|
+
define_method(meth) { |*args, &block|
|
148
|
+
dispatch(meth, *args, &block)
|
149
|
+
}
|
150
|
+
if "unknown" != meth
|
151
|
+
define_method("#{meth}?") { |*args, &block|
|
152
|
+
dispatch(meth, *args, &block)
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
142
158
|
##
|
143
159
|
# Every function this class doesn't have should be mapped to the original
|
144
160
|
# logger
|
145
|
-
def
|
161
|
+
def respond_to_missing?(meth, include_private = false)
|
146
162
|
if @loggers.nil? or @loggers.empty?
|
147
163
|
raise "No loggers created, can't do anything."
|
148
164
|
end
|
@@ -151,17 +167,24 @@ module TeeLogger
|
|
151
167
|
|
152
168
|
# All loggers are the same, so we need to check only one of them.
|
153
169
|
@loggers.each do |key, logger|
|
154
|
-
if logger.respond_to?
|
170
|
+
if logger.respond_to?(meth_name, include_private)
|
155
171
|
return true
|
156
172
|
end
|
157
173
|
break
|
158
174
|
end
|
159
175
|
|
160
176
|
# If this didn't work, we're also emulating a hash
|
161
|
-
return @loggers.respond_to?
|
177
|
+
return @loggers.respond_to?(meth_name, include_private)
|
162
178
|
end
|
163
179
|
|
164
180
|
def method_missing(meth, *args, &block)
|
181
|
+
dispatch(meth, *args, &block)
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
|
187
|
+
def dispatch(meth, *args, &block)
|
165
188
|
meth_name = meth.to_s
|
166
189
|
|
167
190
|
if @loggers.nil? or @loggers.empty?
|
@@ -195,5 +218,6 @@ module TeeLogger
|
|
195
218
|
# hash.
|
196
219
|
return @loggers.send(meth_name, *args, &block)
|
197
220
|
end
|
221
|
+
|
198
222
|
end
|
199
223
|
end
|
data/teelogger.gemspec
CHANGED
metadata
CHANGED
@@ -1,55 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teelogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Finkhaeuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: cucumber
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: Mini wrapper around Ruby Logger for logging to multiple destinations.
|
@@ -59,7 +73,8 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
-
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
63
78
|
- Gemfile
|
64
79
|
- LICENSE
|
65
80
|
- README.md
|
@@ -80,17 +95,17 @@ require_paths:
|
|
80
95
|
- lib
|
81
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
97
|
requirements:
|
83
|
-
- -
|
98
|
+
- - '>='
|
84
99
|
- !ruby/object:Gem::Version
|
85
100
|
version: '0'
|
86
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
102
|
requirements:
|
88
|
-
- -
|
103
|
+
- - '>='
|
89
104
|
- !ruby/object:Gem::Version
|
90
105
|
version: '0'
|
91
106
|
requirements: []
|
92
107
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.4.3
|
94
109
|
signing_key:
|
95
110
|
specification_version: 4
|
96
111
|
summary: Mini wrapper around Ruby Logger for logging to multiple destinations.
|