tee_logger 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/tee_logger.rb +15 -15
- data/lib/tee_logger/utils.rb +35 -30
- data/lib/tee_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a6bbfeaad4ce3cc439f815a4d72468ea056dd47
|
4
|
+
data.tar.gz: 9a559bcaa02d344745ba5ec2d0f3f2fc397dde92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e217bda8ad154e33bb6e819e1b563c1b0d15026be829651b2b8c66bd13d3d50ada1581c50e8bf4629df76b606df4ebe59347bd161ca23090ee6082403cca17
|
7
|
+
data.tar.gz: 64a1db311741ce7907741c68fa7016fc8391c864fdfb295f5c70b7f73a586ff29d4707e012040323e6e0a9bfd2e2263196c3ed486f4d48901c598ee5a7cbf3a3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Test Coverage](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage)
|
5
5
|
|
6
6
|
> Sorry. In from version 2 to version 3, changed usage.
|
7
|
-
> see also [CHANGELOG.md](/CHANGELOG.md
|
7
|
+
> see also [CHANGELOG.md](https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md).
|
8
8
|
|
9
9
|
- [Rubygems.org](https://rubygems.org/gems/tee_logger)
|
10
10
|
- [GitHub](https://github.com/k-ta-yamada/tee_logger)
|
data/lib/tee_logger.rb
CHANGED
@@ -20,25 +20,21 @@ module TeeLogger
|
|
20
20
|
class TeeLogger
|
21
21
|
class << self
|
22
22
|
# @!macro [attach] logging_methods
|
23
|
-
# @!method $1(progname = nil,
|
23
|
+
# @!method $1(progname = nil, *options, &block)
|
24
24
|
# logging $1 level message.
|
25
25
|
# @param progname see also Logger
|
26
|
-
# @param
|
26
|
+
# @param options [Array]
|
27
|
+
# @option options [Fixnum] indent_level
|
28
|
+
# @option options [Symbol] enabling_target
|
29
|
+
# valid values => [:console, :logfile]
|
27
30
|
# @param &block see also Logger
|
28
31
|
# @return true
|
29
32
|
# @see Logger
|
30
33
|
def define_logging_methods(name)
|
31
34
|
define_method(name) do |progname = nil, *options, &block|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
progname, block = indentation(progname, block, opts[:indent_level])
|
36
|
-
|
37
|
-
if disabling_target.nil?
|
38
|
-
logging(name, progname, &block)
|
39
|
-
else
|
40
|
-
disable(disabling_target) { logging(name, progname, &block) }
|
41
|
-
end
|
35
|
+
logdev_name, indent_level = extract_options(options).values
|
36
|
+
progname, block = indentation(progname, block, indent_level)
|
37
|
+
logging(name, progname, logdev_name, &block)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
private :define_logging_methods
|
@@ -124,9 +120,13 @@ module TeeLogger
|
|
124
120
|
|
125
121
|
private
|
126
122
|
|
127
|
-
def logging(name, progname, &block)
|
128
|
-
|
129
|
-
|
123
|
+
def logging(name, progname, logdev_name = nil, &block)
|
124
|
+
if logdev_name
|
125
|
+
disable(logdev_name) { logging(name, progname, &block) }
|
126
|
+
else
|
127
|
+
@console.send(name, progname, &block)
|
128
|
+
@logfile.send(name, progname, &block)
|
129
|
+
end
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
data/lib/tee_logger/utils.rb
CHANGED
@@ -2,32 +2,29 @@
|
|
2
2
|
module TeeLogger
|
3
3
|
# util
|
4
4
|
module Utils
|
5
|
+
# LOGDEV_NAMES not incuded error
|
5
6
|
class IncorrectNameError < StandardError; end
|
6
|
-
|
7
|
+
#
|
8
|
+
class IncorrectOptionError < StandardError; end
|
9
|
+
# using private method #parse_to_hash
|
10
|
+
ParsedOption = Struct.new(:logdev_name, :indent_level)
|
7
11
|
# defined log devices names
|
8
|
-
|
12
|
+
LOGDEV_NAMES = [:console, :logfile]
|
13
|
+
# defined reverse names
|
14
|
+
LOGDEV_REVERSE = { console: :logfile, logfile: :console }
|
9
15
|
|
10
16
|
private
|
11
17
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
elsif val.is_a?(Fixnum)
|
19
|
-
obj[:indent_level] = val
|
18
|
+
def extract_options(options)
|
19
|
+
options.each_with_object(ParsedOption.new(nil, 0)) do |val, obj|
|
20
|
+
case val
|
21
|
+
when Symbol then obj.logdev_name = name_reverse(val)
|
22
|
+
when Fixnum then obj.indent_level = val
|
23
|
+
else incorrect_option_error(val)
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
def reverse_target(logdev_name)
|
25
|
-
case logdev_name
|
26
|
-
when :console then :logfile
|
27
|
-
when :logfile then :console
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
28
|
def indentation(progname, block, indent_level)
|
32
29
|
if block.nil?
|
33
30
|
progname = "#{' ' * indent_level}#{formatting(progname)}"
|
@@ -39,22 +36,30 @@ module TeeLogger
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def formatting(val)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
else
|
47
|
-
val
|
39
|
+
case val
|
40
|
+
when Symbol then ":#{val}"
|
41
|
+
when nil then 'nil'
|
42
|
+
else val
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
def name_reverse(val)
|
47
|
+
correct_name?(val)
|
48
|
+
LOGDEV_REVERSE[val]
|
49
|
+
end
|
50
|
+
|
51
|
+
def correct_name?(name)
|
52
|
+
LOGDEV_NAMES.include?(name) ? true : incorrect_name_error(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
def incorrect_name_error(name)
|
56
|
+
fail IncorrectNameError,
|
57
|
+
"logdev_name is :console or :logfile. logdev_name=[:#{name}]"
|
58
|
+
end
|
59
|
+
|
60
|
+
def incorrect_option_error(val)
|
61
|
+
fail IncorrectOptionError,
|
62
|
+
"option params is Symbol or Fixnum. class=[#{val.class}]"
|
58
63
|
end
|
59
64
|
|
60
65
|
def logdev_instance(logdev_name)
|
data/lib/tee_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tee_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k-ta-yamada
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|