tee_logger 3.1.2 → 3.2.0

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: 86ce84adde4f699ebfbb78b876b2772f6d35e8af
4
- data.tar.gz: d9eefa9bc74cd88ee68becce4495c7ca35aa6542
3
+ metadata.gz: a90d6ef3ba88bed38455955c9e7e0654440d9e80
4
+ data.tar.gz: d99ccca31c41af678fe5111be644decb3e783a4c
5
5
  SHA512:
6
- metadata.gz: afb40f06dd8f92fd504271acbbdefcffd47d4ee2120ca84b16c75f4b1d0669fcdd0cb973f8081beeef4e22de49c4bcb43c753190a54a97936e01c2688904d93a
7
- data.tar.gz: b6d9e611a97c4c088511f5566acaf0f798301235b8332daab62fa9d6679918a5baae4c989f001790c4c4cf5a4c233f6c9fe8bba1fdedc8c646c1ebf901ac9331
6
+ metadata.gz: fcc81f3c5491f42351e90abb301bfc8821238fc237a843f483e29b42f5500464b1682569285bc943db7ba441ce80449e127380dfcf29ad89f881f18be3e6c974
7
+ data.tar.gz: c6a2a450f5284eea3b19ddd5e71292b1816b5337d1dd3343733b5eb9db580d6c58760357ec5b9d49201bdd7222fd49fe55655b4a9c7a74508f4c35b3ac682aa1
data/.gitignore CHANGED
@@ -55,3 +55,6 @@ $RECYCLE.BIN/
55
55
 
56
56
  # Windows shortcuts
57
57
  *.lnk
58
+
59
+ *tags*
60
+ *.log
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/AsciiComments:
4
+ Enabled: false
data/.rubocop_todo.yml ADDED
File without changes
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v3.2.0
2
+ - [issue #15](https://github.com/k-ta-yamada/tee_logger/issues/15)
3
+ Before extend or include the module, allow the setting of logdev
4
+
1
5
  # v3.1.2
2
6
  - add .gemspec required_ruby_version = '>= 2.0.0'
3
7
 
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
- [![Gem Version](https://badge.fury.io/rb/tee_logger.svg)](http://badge.fury.io/rb/tee_logger)
2
- [![Build Status](https://travis-ci.org/k-ta-yamada/tee_logger.svg)](https://travis-ci.org/k-ta-yamada/tee_logger)
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
- [![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)
1
+ [![Gem Version][gem_version-svg]][gem_version]
2
+ [![Build Status][travis-svg]][travis]
3
+ [![Code Climate][codeclimate-svg]][codeclimate]
4
+ [![Test Coverage][codeclimate_cov-svg]][codeclimate_cov]
5
+ [![Inline docs][inch-ci-svg]][inch-ci]
6
6
 
7
7
  > Sorry. In from version 2 to version 3, changed usage.
8
- > see also [CHANGELOG.md](https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md).
8
+ > see also [CHANGELOG.md][tee_logger-changelog].
9
9
 
10
10
  - [Rubygems.org](https://rubygems.org/gems/tee_logger)
11
11
  - [GitHub](https://github.com/k-ta-yamada/tee_logger)
@@ -48,73 +48,74 @@ $ gem install tee_logger
48
48
  ## Usage
49
49
 
50
50
  ```ruby
51
- require 'tee_logger'
52
-
53
- # Logger.new like options(logdev, shift_age, shift_size)
54
- # options default value is
55
- # logdev = './tee_logger.log'
56
- # shift_age = 0
57
- # shift_size = 1_048_576
58
- tl = TeeLogger.new
59
-
60
- # let's logging
61
- tl.debug 'hello'
62
- tl.debug(:progname) { 'hello world' }
63
- tl.progname = 'App'
64
- tl.debug 'hello tee_logger'
65
-
66
- # enable only when specified
67
- tl.info 'this message is console and logfile'
68
- tl.info 'this message is console only', :console
69
- tl.info 'this message is logfile only', :logfile
70
-
71
- # log meassage indent
72
- tl.info 'hello' # => 'hello'
73
- tl.info 'hello', 0 # => 'hello'
74
- tl.info 'hello', 2 # => ' hello'
75
-
76
- # enabling and indent
77
- tl.info 'this message is console only', 2, :console
78
- tl.info 'this message is console only', :console, 2
79
-
80
- # disable console output
81
- tl.disable(:console)
82
- tl.info 'this message is logfile only'
83
-
84
- # enable console output
85
- tl.enable(:console)
86
- tl.info 'this message is logfile and console'
87
-
88
- # disable logfile output
89
- tl.disable(:logfile)
90
- tl.info 'this message is consle only'
91
-
92
- # enable logfile output
93
- tl.enable(:logfile)
94
- tl.info 'this message is logfile and console'
95
-
96
- # disabe in block
97
- tl.disable(:console) do
51
+ require 'tee_logger'
52
+
53
+ # Logger.new like options(logdev, shift_age, shift_size)
54
+ # options default value is
55
+ # logdev = './tee_logger.log'
56
+ # shift_age = 0
57
+ # shift_size = 1_048_576
58
+ tl = TeeLogger.new
59
+
60
+ # let's logging
61
+ tl.debug 'hello'
62
+ tl.debug(:progname) { 'hello world' }
63
+ tl.progname = 'App'
64
+ tl.debug 'hello tee_logger'
65
+
66
+ # enable only when specified
67
+ tl.info 'this message is console and logfile'
68
+ tl.info 'this message is console only', :console
69
+ tl.info 'this message is logfile only', :logfile
70
+
71
+ # log meassage indent
72
+ tl.info 'hello' # => 'hello'
73
+ tl.info 'hello', 0 # => 'hello'
74
+ tl.info 'hello', 2 # => ' hello'
75
+
76
+ # enabling and indent
77
+ tl.info 'this message is console only', 2, :console
78
+ tl.info 'this message is console only', :console, 2
79
+
80
+ # disable console output
81
+ tl.disable(:console)
98
82
  tl.info 'this message is logfile only'
99
- end
100
- tl.info 'this message is logfile and console'
101
83
 
102
- # and others like Logger's
103
- tl.debug? # => true
104
- tl.info? # => true
105
- tl.warn? # => true
106
- tl.error? # => true
107
- tl.fatal? # => true
84
+ # enable console output
85
+ tl.enable(:console)
86
+ tl.info 'this message is logfile and console'
108
87
 
109
- tl.level # => 0
110
- tl.level = Logger::INFO
111
- tl.debug 'this message is not logging'
88
+ # disable logfile output
89
+ tl.disable(:logfile)
90
+ tl.info 'this message is consle only'
112
91
 
113
- tl.formatter # => nil or Proc
114
- tl.formatter = proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
92
+ # enable logfile output
93
+ tl.enable(:logfile)
94
+ tl.info 'this message is logfile and console'
115
95
 
116
- tl.datetime_format # => nil or Proc
117
- tl.datetime_format = '%Y%m%d %H%M%S '
96
+ # disabe in block
97
+ tl.disable(:console) do
98
+ tl.info 'this message is logfile only'
99
+ end
100
+ tl.info 'this message is logfile and console'
101
+
102
+ # and others like Logger's
103
+ tl.debug? # => true
104
+ tl.info? # => true
105
+ tl.warn? # => true
106
+ tl.error? # => true
107
+ tl.fatal? # => true
108
+
109
+ tl.level # => 0
110
+ tl.level = Logger::INFO
111
+ tl.debug 'this message is not logging'
112
+
113
+ tl.formatter # => nil or Proc
114
+ tl.formatter =
115
+ proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
116
+
117
+ tl.datetime_format # => nil or Proc
118
+ tl.datetime_format = '%Y%m%d %H%M%S '
118
119
  ```
119
120
 
120
121
 
@@ -123,25 +124,25 @@ tl.datetime_format = '%Y%m%d %H%M%S '
123
124
  > TODO: the log file will be in default of `./tee_logger.log`
124
125
 
125
126
  ```ruby
126
- require 'tee_logger'
127
+ require 'tee_logger'
127
128
 
128
- class YourAwesomeClass
129
- include TeeLogger
129
+ class YourAwesomeClass
130
+ include TeeLogger
130
131
 
131
- def awesome_method
132
- # do somthing
133
- logger.info 'this is message is logging and disp console'
132
+ def awesome_method
133
+ # do somthing
134
+ logger.info 'this is message is logging and disp console'
135
+ end
134
136
  end
135
- end
136
137
 
137
- module YourAwesomeModule
138
- extend TeeLogger
138
+ module YourAwesomeModule
139
+ extend TeeLogger
139
140
 
140
- def self.awesome_method
141
- # do somthing
142
- logger.info 'this is message is logging and disp console'
141
+ def self.awesome_method
142
+ # do somthing
143
+ logger.info 'this is message is logging and disp console'
144
+ end
143
145
  end
144
- end
145
146
  ```
146
147
 
147
148
 
@@ -162,12 +163,33 @@ and push the `.gem` file to [rubygems.org](https://rubygems.org).
162
163
 
163
164
  ## Contributing
164
165
 
165
- Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/tee_logger.
166
+ Bug reports and pull requests are welcome on GitHub
167
+ at https://github.com/k-ta-yamada/tee_logger.
166
168
  This project is intended to be a safe,
167
169
  welcoming space for collaboration,
168
- and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
170
+ and contributors are expected to adhere to the
171
+ [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
172
 
170
173
 
171
174
  ## License
172
175
 
173
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
176
+ The gem is available as open source under the terms of the
177
+ [MIT License](http://opensource.org/licenses/MIT).
178
+
179
+
180
+ [gem_version]: http://badge.fury.io/rb/tee_logger
181
+ [gem_version-svg]: https://badge.fury.io/rb/tee_logger.svg
182
+
183
+ [travis]: https://travis-ci.org/k-ta-yamada/tee_logger
184
+ [travis-svg]: https://travis-ci.org/k-ta-yamada/tee_logger.svg
185
+
186
+ [codeclimate]: https://codeclimate.com/github/k-ta-yamada/tee_logger
187
+ [codeclimate-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg
188
+
189
+ [codeclimate_cov]: https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage
190
+ [codeclimate_cov-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg
191
+
192
+ [inch-ci]: http://inch-ci.org/github/k-ta-yamada/tee_logger
193
+ [inch-ci-svg]: http://inch-ci.org/github/k-ta-yamada/tee_logger.svg?branch=master
194
+
195
+ [tee_logger-changelog]: https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md
data/lib/tee_logger.rb CHANGED
@@ -6,40 +6,51 @@ require 'logger'
6
6
 
7
7
  # namespace
8
8
  module TeeLogger
9
- class << self
10
- # shortcut for TeeLogger::TeeLoggerBase.new
11
- # @param logdev [String]
12
- # @param shift_age [Integer]
13
- # @param shift_size [Integer]
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
9
+ # shortcut for TeeLogger::TeeLoggerBase.new
10
+ # @param logdev [String]
11
+ # @param shift_age [Integer]
12
+ # @param shift_size [Integer]
13
+ # @return [TeeLogger::TeeLoggerBase]
14
+ # @see TeeLoggerBase
15
+ def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
16
+ TeeLoggerBase.new(logdev, shift_age, shift_size)
17
+ end
19
18
 
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
30
- end
19
+ @logdev = nil
20
+
21
+ # @return [String, File] instance variable @logdev.
22
+ def self.logdev
23
+ @logdev
24
+ end
25
+
26
+ # set TeeLogger's class instance variable @logdev.
27
+ # extend or include TeeLogger then, @logdev is default argument
28
+ # for Logger.new(logdev).
29
+ # @param logdev [String, File]
30
+ def self.logdev=(logdev)
31
+ @logdev = logdev
32
+ end
33
+
34
+ # define singleton method .logger for your module.
35
+ # and TeeLogger.progname is your module name.
36
+ def self.extended(mod)
37
+ mod.define_singleton_method(:logger) do
38
+ return @logger if @logger
39
+ @logger = TeeLoggerBase.new(TeeLogger.logdev || DEFAULT_FILE)
40
+ @logger.progname = mod
41
+ @logger
31
42
  end
43
+ end
32
44
 
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
45
+ # define instance method #logger for your class.
46
+ # and TeeLogger.progname is your class name.
47
+ def self.included(klass)
48
+ klass.class_eval do
49
+ define_method(:logger) do
50
+ return @logger if @logger
51
+ @logger = TeeLoggerBase.new(TeeLogger.logdev || DEFAULT_FILE)
52
+ @logger.progname = klass.name
53
+ @logger
43
54
  end
44
55
  end
45
56
  end
@@ -46,6 +46,8 @@ module TeeLogger
46
46
  def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
47
47
  @console = Logger.new($stdout)
48
48
  @logfile = Logger.new(logdev, shift_age, shift_size)
49
+
50
+ @level, @progname, @formatter, @datetime_format = nil
49
51
  end
50
52
 
51
53
  define_logging_methods :debug
@@ -2,7 +2,7 @@
2
2
  module TeeLogger
3
3
  # util
4
4
  module Utils
5
- module_function
5
+ # module_function
6
6
 
7
7
  # @param options [Array]
8
8
  # @return [ParsedOption]
@@ -1,5 +1,5 @@
1
1
  # namespace
2
2
  module TeeLogger
3
3
  # version number
4
- VERSION = '3.1.2'
4
+ VERSION = '3.2.0'
5
5
  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.2
4
+ version: 3.2.0
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-26 00:00:00.000000000 Z
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -173,6 +173,8 @@ extra_rdoc_files: []
173
173
  files:
174
174
  - ".gitignore"
175
175
  - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".rubocop_todo.yml"
176
178
  - ".travis.yml"
177
179
  - CHANGELOG.md
178
180
  - CODE_OF_CONDUCT.md
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
208
  version: '0'
207
209
  requirements: []
208
210
  rubyforge_project:
209
- rubygems_version: 2.2.2
211
+ rubygems_version: 2.4.5.1
210
212
  signing_key:
211
213
  specification_version: 4
212
214
  summary: logging to file and standard output.