tee_logger 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42308c52d2bc5ef56c767672b7ae3176649252a9
4
- data.tar.gz: 2e8b699ed7291753b0e6c0b124ddcebf612617b0
3
+ metadata.gz: 874f1b444b9aabcee203bb8353f3aa9dad7e949c
4
+ data.tar.gz: ca390ff17b91be912c99777dd02e67d27289ad5f
5
5
  SHA512:
6
- metadata.gz: 346a26ebc18965a8a0b12f449b159c42a8caab094abea47cc1318ff4ea04ed3607d5a18d6d4013b63224c00a2b7bfea46a86811dcebf471ae536c1c299a2fe67
7
- data.tar.gz: dd67b9fc88b165ddd134870fa42806207a1b19ff9a9f1319e68c2c795ba1e88f9519efd842ee1a41a40fa455a3be36142f3237aaf0bb4304da2b5b51a24f185a
6
+ metadata.gz: 39ff82dd2e8177e79941cf0c01f42fd9883e07836ae76aa884ff61830047f0354ace54c384019849eb130d13560b0b4ee3e2a5ff337d1762f45ef8e53378982d
7
+ data.tar.gz: a2e62ecde98d03f0471bcf28ec22ab849ed0ad994eaa6d8292c80bd5b0106338f2b816f74746f887cf579a26d794f3e96522067bb74a7ab14f25aa8f223e1f1b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v3.1.1
2
+ - [[clean] module split](https://github.com/k-ta-yamada/tee_logger/pull/14)
3
+
1
4
  # v3.1.0
2
5
  - [issue #12](https://github.com/k-ta-yamada/tee_logger/issues/12)
3
6
  Include and Extend support
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/k-ta-yamada/tee_logger.svg)](https://travis-ci.org/k-ta-yamada/tee_logger)
3
3
  [![Code Climate](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger)
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
+ [![Inline docs](http://inch-ci.org/github/k-ta-yamada/tee_logger.svg?branch=master)](http://inch-ci.org/github/k-ta-yamada/tee_logger)
5
6
 
6
7
  > Sorry. In from version 2 to version 3, changed usage.
7
8
  > see also [CHANGELOG.md](https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md).
@@ -117,6 +118,33 @@ tl.datetime_format = '%Y%m%d %H%M%S '
117
118
  ```
118
119
 
119
120
 
121
+ ## include or extend TeeLogger for casual use
122
+
123
+ > TODO: the log file will be in default of `./tee_logger.log`
124
+
125
+ ```ruby
126
+ require 'tee_logger'
127
+
128
+ class YourAwesomeClass
129
+ include TeeLogger
130
+
131
+ def awesome_method
132
+ # do somthing
133
+ logger.info 'this is message is logging and disp console'
134
+ end
135
+ end
136
+
137
+ module YourAwesomeModule
138
+ extend TeeLogger
139
+
140
+ def self.awesome_method
141
+ # do somthing
142
+ logger.info 'this is message is logging and disp console'
143
+ end
144
+ end
145
+ ```
146
+
147
+
120
148
  ## Development
121
149
 
122
150
  After checking out the repo, run `bundle install` to install dependencies.
@@ -2,19 +2,27 @@
2
2
  module TeeLogger
3
3
  # no param of filename, set this filename
4
4
  DEFAULT_FILE = './tee_logger.log'
5
+
5
6
  # Implements targets
6
7
  LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal]
8
+
7
9
  # defined logdev names
8
10
  LOGDEV_NAMES = [:console, :logfile]
11
+
9
12
  # defined paired of logdev name
10
13
  LOGDEV_REVERSE = { console: :logfile, logfile: :console }
11
14
 
15
+ # empty format
12
16
  FORMATTER_FOR_DISABLING = proc { |_severity, _time, _progname, _msg| '' }
13
17
 
14
- # using private method #parse_to_hash
18
+ # using TeeLogger::Utils.extract_options
19
+ # @param logdev_name [Symbol]
20
+ # @param indent_level [Fixnum]
15
21
  ParsedOption = Struct.new(:logdev_name, :indent_level)
22
+
16
23
  # LOGDEV_NAMES not included error
17
24
  class IncorrectNameError < StandardError; end
25
+
18
26
  # option's class is not allow
19
27
  class IncorrectOptionError < StandardError; end
20
28
  end
@@ -0,0 +1,117 @@
1
+ # namespace
2
+ module TeeLogger
3
+ # main
4
+ # @see http://www.rubydoc.info/stdlib/logger/Logger Logger
5
+ class TeeLoggerBase
6
+ class << self
7
+ # @!macro [attach] logging_methods
8
+ # @!method $1(progname = nil, *options, &block)
9
+ # logging $1 level message.
10
+ # @param progname see also Logger
11
+ # @param options [Array]
12
+ # @option options [Fixnum] indent_level
13
+ # @option options [Symbol] enabling_target
14
+ # valid values => [:console, :logfile]
15
+ # @param &block see also Logger
16
+ # @return true
17
+ # @see Logger
18
+ def define_logging_methods(name)
19
+ define_method(name) do |progname = nil, *options, &block|
20
+ logdev_name, indent_level = extract_options(options).values
21
+ progname, block = indentation(progname, block, indent_level)
22
+ logging(name, progname, logdev_name, &block)
23
+ end
24
+ end
25
+ private :define_logging_methods
26
+
27
+ # @!macro [attach] loglevel_check_methods
28
+ # @!method $1(name)
29
+ # @return [Boolean]
30
+ def define_loglevel_check_methods(name)
31
+ define_method(name) do
32
+ @console.send(name)
33
+ @logfile.send(name)
34
+ end
35
+ end
36
+ private :define_loglevel_check_methods
37
+ end
38
+
39
+ include Utils
40
+ attr_reader :level, :progname, :formatter, :datetime_format
41
+
42
+ # @param logdev [String]
43
+ # @param shift_age [Integer]
44
+ # @param shift_size [Integer]
45
+ # @see Logger#initialize
46
+ def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
47
+ @console = Logger.new($stdout)
48
+ @logfile = Logger.new(logdev, shift_age, shift_size)
49
+ end
50
+
51
+ define_logging_methods :debug
52
+ define_logging_methods :info
53
+ define_logging_methods :warn
54
+ define_logging_methods :error
55
+ define_logging_methods :fatal
56
+
57
+ define_loglevel_check_methods :debug?
58
+ define_loglevel_check_methods :info?
59
+ define_loglevel_check_methods :warn?
60
+ define_loglevel_check_methods :error?
61
+ define_loglevel_check_methods :fatal?
62
+
63
+ # @param level [Integer]
64
+ def level=(level)
65
+ @console.level = @logfile.level = @level = level
66
+ end
67
+ alias_method :sev_threshold, :level
68
+ alias_method :sev_threshold=, :level=
69
+
70
+ # @param name [String, Symbol]
71
+ def progname=(name = nil)
72
+ @console.progname = @logfile.progname = @progname = name
73
+ end
74
+
75
+ # @param formatter
76
+ def formatter=(formatter)
77
+ @console.formatter = @logfile.formatter = @formatter = formatter
78
+ end
79
+
80
+ # @param formatter
81
+ def datetime_format=(format)
82
+ @console.datetime_format =
83
+ @logfile.datetime_format =
84
+ @datetime_format = format
85
+ end
86
+
87
+ # @param logdev_name [String, Symbol]
88
+ # @yield before logdev_name disable, after logdev_name enable.
89
+ def disable(logdev_name)
90
+ correct_name?(logdev_name)
91
+ if block_given?
92
+ disable(logdev_name)
93
+ yield
94
+ enable(logdev_name)
95
+ else
96
+ logdev_instance(logdev_name).formatter = FORMATTER_FOR_DISABLING
97
+ end
98
+ end
99
+
100
+ # @param logdev_name [String, Symbol]
101
+ def enable(logdev_name)
102
+ correct_name?(logdev_name)
103
+ logdev_instance(logdev_name).formatter = @formatter
104
+ end
105
+
106
+ private
107
+
108
+ def logging(name, progname, logdev_name = nil, &block)
109
+ if logdev_name
110
+ disable(logdev_name) { logging(name, progname, &block) }
111
+ else
112
+ @console.send(name, progname, &block)
113
+ @logfile.send(name, progname, &block)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -16,9 +16,9 @@ module TeeLogger
16
16
  end
17
17
  end
18
18
 
19
- # @params progname
20
- # @params block
21
- # @params indent_level [Fixnum]
19
+ # @param progname
20
+ # @param block
21
+ # @param indent_level [Fixnum]
22
22
  # @return [Array]
23
23
  def indentation(progname, block, indent_level)
24
24
  if block.nil?
@@ -30,7 +30,7 @@ module TeeLogger
30
30
  [progname, block]
31
31
  end
32
32
 
33
- # @params val
33
+ # @param val [Object]
34
34
  # @return [String]
35
35
  def formatting(val)
36
36
  case val
@@ -40,32 +40,32 @@ module TeeLogger
40
40
  end
41
41
  end
42
42
 
43
- # @params val [Symbol]
43
+ # @param val [Symbol]
44
44
  # @return [Symbol]
45
45
  def name_reverse(val)
46
46
  correct_name?(val)
47
47
  LOGDEV_REVERSE[val]
48
48
  end
49
49
 
50
- # @params name [Symbol]
50
+ # @param name [Symbol]
51
51
  # @return [true]
52
52
  def correct_name?(name)
53
53
  LOGDEV_NAMES.include?(name) ? true : incorrect_name_error(name)
54
54
  end
55
55
 
56
- # @params name [Symbol]
56
+ # @param name [Symbol]
57
57
  def incorrect_name_error(name)
58
58
  fail IncorrectNameError,
59
59
  "logdev_name is :console or :logfile. logdev_name=[:#{name}]"
60
60
  end
61
61
 
62
- # @params name [Symbol]
62
+ # @param val [Symbol]
63
63
  def incorrect_option_error(val)
64
64
  fail IncorrectOptionError,
65
65
  "option params is Symbol or Fixnum. class=[#{val.class}]"
66
66
  end
67
67
 
68
- # @params logdev_name [Symbol]
68
+ # @param logdev_name [Symbol]
69
69
  # @return [Logger]
70
70
  def logdev_instance(logdev_name)
71
71
  instance_variable_get("@#{logdev_name}")
@@ -1,5 +1,5 @@
1
1
  # namespace
2
2
  module TeeLogger
3
3
  # version number
4
- VERSION = '3.1.0'
4
+ VERSION = '3.1.1'
5
5
  end
data/lib/tee_logger.rb CHANGED
@@ -1,153 +1,45 @@
1
1
  require 'tee_logger/version'
2
2
  require 'tee_logger/constants'
3
3
  require 'tee_logger/utils'
4
+ require 'tee_logger/tee_logger_base'
4
5
  require 'logger'
5
6
 
6
7
  # namespace
7
8
  module TeeLogger
8
- # shortcut for TeeLogger::TeeLogger.new
9
- # @see TeeLogger
10
- def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
11
- TeeLogger.new(logdev, shift_age, shift_size)
12
- end
13
-
14
- # define singleton method .logger for your module.
15
- # and TeeLogger.progname is your module name.
16
- def self.extended(mod)
17
- mod.class_eval do
18
- define_singleton_method(:logger) do |logdev = DEFAULT_FILE|
19
- return @logger if @logger
20
- @logger = TeeLogger.new(logdev)
21
- @logger.progname = self
22
- @logger
23
- end
24
- end
25
- end
26
-
27
- # define instance method #logger for your class.
28
- # and TeeLogger.progname is your class name.
29
- def self.included(klass)
30
- klass.class_eval do
31
- define_method(:logger) do |logdev = DEFAULT_FILE|
32
- return @logger if @logger
33
- @logger = TeeLogger.new(logdev)
34
- @logger.progname = self.class.name
35
- @logger
36
- end
37
- end
38
- end
39
-
40
- # main
41
- # @see http://www.rubydoc.info/stdlib/logger/Logger Logger
42
- class TeeLogger
43
- class << self
44
- # @!macro [attach] logging_methods
45
- # @!method $1(progname = nil, *options, &block)
46
- # logging $1 level message.
47
- # @param progname see also Logger
48
- # @param options [Array]
49
- # @option options [Fixnum] indent_level
50
- # @option options [Symbol] enabling_target
51
- # valid values => [:console, :logfile]
52
- # @param &block see also Logger
53
- # @return true
54
- # @see Logger
55
- def define_logging_methods(name)
56
- define_method(name) do |progname = nil, *options, &block|
57
- logdev_name, indent_level = extract_options(options).values
58
- progname, block = indentation(progname, block, indent_level)
59
- logging(name, progname, logdev_name, &block)
60
- end
61
- end
62
- private :define_logging_methods
63
-
64
- # @!macro [attach] loglevel_check_methods
65
- # @!method $1(name)
66
- # @return [Boolean]
67
- def define_loglevel_check_methods(name)
68
- define_method(name) do
69
- @console.send(name)
70
- @logfile.send(name)
71
- end
72
- end
73
- private :define_loglevel_check_methods
74
- end
75
-
76
- include Utils
77
- attr_reader :level, :progname, :formatter, :datetime_format
78
-
9
+ class << self
10
+ # shortcut for TeeLogger::TeeLoggerBase.new
79
11
  # @param logdev [String]
80
12
  # @param shift_age [Integer]
81
13
  # @param shift_size [Integer]
82
- # @see Logger#initialize
83
- def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
84
- @console = Logger.new($stdout)
85
- @logfile = Logger.new(logdev, shift_age, shift_size)
86
- end
87
-
88
- define_logging_methods :debug
89
- define_logging_methods :info
90
- define_logging_methods :warn
91
- define_logging_methods :error
92
- define_logging_methods :fatal
93
-
94
- define_loglevel_check_methods :debug?
95
- define_loglevel_check_methods :info?
96
- define_loglevel_check_methods :warn?
97
- define_loglevel_check_methods :error?
98
- define_loglevel_check_methods :fatal?
99
-
100
- # @param level [Integer]
101
- def level=(level)
102
- @console.level = @logfile.level = @level = level
103
- end
104
- alias_method :sev_threshold, :level
105
- alias_method :sev_threshold=, :level=
106
-
107
- # @param name [String, Symbol]
108
- def progname=(name = nil)
109
- @console.progname = @logfile.progname = @progname = name
110
- end
111
-
112
- # @param formatter
113
- def formatter=(formatter)
114
- @console.formatter = @logfile.formatter = @formatter = formatter
115
- end
116
-
117
- # @param formatter
118
- def datetime_format=(format)
119
- @console.datetime_format =
120
- @logfile.datetime_format =
121
- @datetime_format = format
122
- end
123
-
124
- # @param logdev_name [String, Symbol]
125
- # @yield before logdev_name disable, after logdev_name enable.
126
- def disable(logdev_name)
127
- correct_name?(logdev_name)
128
- if block_given?
129
- disable(logdev_name)
130
- yield
131
- enable(logdev_name)
132
- else
133
- logdev_instance(logdev_name).formatter = FORMATTER_FOR_DISABLING
14
+ # @return [TeeLogger::TeeLoggerBase]
15
+ # @see TeeLoggerBase
16
+ def new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
17
+ TeeLoggerBase.new(logdev, shift_age, shift_size)
18
+ end
19
+
20
+ # define singleton method .logger for your module.
21
+ # and TeeLogger.progname is your module name.
22
+ def extended(mod)
23
+ mod.class_eval do
24
+ define_singleton_method(:logger) do |logdev = DEFAULT_FILE|
25
+ return @logger if @logger
26
+ @logger = TeeLoggerBase.new(logdev)
27
+ @logger.progname = self
28
+ @logger
29
+ end
134
30
  end
135
31
  end
136
32
 
137
- # @param logdev_name [String, Symbol]
138
- def enable(logdev_name)
139
- correct_name?(logdev_name)
140
- logdev_instance(logdev_name).formatter = @formatter
141
- end
142
-
143
- private
144
-
145
- def logging(name, progname, logdev_name = nil, &block)
146
- if logdev_name
147
- disable(logdev_name) { logging(name, progname, &block) }
148
- else
149
- @console.send(name, progname, &block)
150
- @logfile.send(name, progname, &block)
33
+ # define instance method #logger for your class.
34
+ # and TeeLogger.progname is your class name.
35
+ def included(klass)
36
+ klass.class_eval do
37
+ define_method(:logger) do |logdev = DEFAULT_FILE|
38
+ return @logger if @logger
39
+ @logger = TeeLoggerBase.new(logdev)
40
+ @logger.progname = self.class.name
41
+ @logger
42
+ end
151
43
  end
152
44
  end
153
45
  end
data/tee_logger.gemspec CHANGED
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'pry'
32
32
  spec.add_development_dependency 'pry-doc'
33
33
  spec.add_development_dependency 'pry-theme'
34
+ spec.add_development_dependency 'pry-byebug'
34
35
  spec.add_development_dependency 'rubocop'
35
36
 
36
37
  spec.add_development_dependency 'capture_stdout'
37
38
  spec.add_development_dependency 'fakefs'
38
- spec.add_development_dependency 'parallel'
39
39
  end
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.1.0
4
+ version: 3.1.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-11-06 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rubocop
112
+ name: pry-byebug
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: capture_stdout
126
+ name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: fakefs
140
+ name: capture_stdout
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: parallel
154
+ name: fakefs
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -182,6 +182,7 @@ files:
182
182
  - Rakefile
183
183
  - lib/tee_logger.rb
184
184
  - lib/tee_logger/constants.rb
185
+ - lib/tee_logger/tee_logger_base.rb
185
186
  - lib/tee_logger/utils.rb
186
187
  - lib/tee_logger/version.rb
187
188
  - tee_logger.gemspec
@@ -205,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  version: '0'
206
207
  requirements: []
207
208
  rubyforge_project:
208
- rubygems_version: 2.2.2
209
+ rubygems_version: 2.4.8
209
210
  signing_key:
210
211
  specification_version: 4
211
212
  summary: logging to file and standard output.