tee_logger 3.1.1 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +2 -0
- data/.travis.yml +17 -9
- data/CHANGELOG.md +69 -21
- data/Gemfile +0 -2
- data/README.md +105 -25
- data/lib/tee_logger.rb +31 -32
- data/lib/tee_logger/configuration.rb +69 -0
- data/lib/tee_logger/constants.rb +11 -7
- data/lib/tee_logger/tee_logger_base.rb +19 -8
- data/lib/tee_logger/utils.rb +1 -3
- data/lib/tee_logger/version.rb +1 -1
- data/tee_logger.gemspec +9 -4
- metadata +46 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c90876bb1b5e1f7019982d320762c5ac4e133e8e65758d806490bb6535ddd65
|
4
|
+
data.tar.gz: 84d59644444224663ac93be6f2514b90b69c97cb35cedccca07f422f8d202526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cb6c4d2e96e213cc733ee916b55bab201817bdd6eff55d584b56334eb064c4633fbcee71a8a813c1dc35c0dc33eda8a5910e3798b5c99449278cf640868a4f6
|
7
|
+
data.tar.gz: c6406041d667a06fabb06598916129fda741e21104e58834425a6f023c245002e218d8f6638eff65e9bd2a7b7e31b0dbda02920c398787315502c4027bd47e3c
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
3
|
+
cache: bundler
|
4
|
+
|
2
5
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
|
8
|
-
before_install:
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
- 3.0
|
7
|
+
- 2.7
|
8
|
+
- 2.6
|
9
|
+
- 2.5
|
10
|
+
|
11
|
+
before_install:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
|
15
|
+
before_script:
|
16
|
+
- ./cc-test-reporter before-build
|
17
|
+
|
18
|
+
after_script:
|
19
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
@@ -1,77 +1,125 @@
|
|
1
|
-
#
|
1
|
+
# CHANGELOG.md
|
2
|
+
|
3
|
+
## v3.2.3
|
4
|
+
|
5
|
+
2020-01-03 JST
|
6
|
+
|
7
|
+
- Add support for Ruby 3.0
|
8
|
+
|
9
|
+
## v3.2.2
|
10
|
+
|
11
|
+
- [issue #17](https://github.com/k-ta-yamada/tee_logger/issues/17)
|
12
|
+
default settings for extend and include
|
13
|
+
|
14
|
+
## v3.2.1
|
15
|
+
|
16
|
+
- [issue #18](https://github.com/k-ta-yamada/tee_logger/issues/18)
|
17
|
+
use initial value `DEFAULT_FILE`, it's change TeeLogger.logdev
|
18
|
+
|
19
|
+
## v3.2.0
|
20
|
+
|
21
|
+
- [issue #15](https://github.com/k-ta-yamada/tee_logger/issues/15)
|
22
|
+
Before extend or include the module, allow the setting of logdev
|
23
|
+
|
24
|
+
## v3.1.2
|
25
|
+
|
26
|
+
- add .gemspec required_ruby_version = '>= 2.0.0'
|
27
|
+
|
28
|
+
## v3.1.1
|
29
|
+
|
2
30
|
- [[clean] module split](https://github.com/k-ta-yamada/tee_logger/pull/14)
|
3
31
|
|
4
|
-
|
32
|
+
## v3.1.0
|
33
|
+
|
5
34
|
- [issue #12](https://github.com/k-ta-yamada/tee_logger/issues/12)
|
6
35
|
Include and Extend support
|
7
36
|
|
8
|
-
|
37
|
+
## v3.0.3
|
38
|
+
|
9
39
|
- shared_examples_for_tee_logger_spec.rb [ae1e481](https://github.com/k-ta-yamada/tee_logger/commit/ae1e481)
|
10
40
|
- new constant for disabling formatter [478eccb](https://github.com/k-ta-yamada/tee_logger/commit/478eccb)
|
11
41
|
|
12
|
-
|
42
|
+
## v3.0.2
|
43
|
+
|
13
44
|
- refactoring
|
14
45
|
- CONSTANTS move to ./lib/constants.rb
|
15
46
|
|
16
|
-
|
47
|
+
## v3.0.1
|
48
|
+
|
17
49
|
- refactoring for [issue #9](https://github.com/k-ta-yamada/tee_logger/issues/9)
|
18
50
|
|
19
|
-
|
51
|
+
## v3.0.0
|
52
|
+
|
20
53
|
- [issue #4](https://github.com/k-ta-yamada/tee_logger/issues/4)
|
21
54
|
logging method's parametrer disabling_target change to enabling_targe
|
22
55
|
- [issue #5](https://github.com/k-ta-yamada/tee_logger/issues/5)
|
23
56
|
log message indentation
|
24
57
|
|
25
|
-
|
58
|
+
## v2.7.0
|
59
|
+
|
26
60
|
- add datetime_format, datetime_format=
|
27
61
|
|
28
|
-
|
62
|
+
## v2.6.0
|
63
|
+
|
29
64
|
- disabling option add to logging_methods
|
30
65
|
|
31
|
-
|
66
|
+
## v2.5.0
|
67
|
+
|
32
68
|
- level, progname and formatter were changed to instance variable
|
33
69
|
- refactoring: disabling and enabling
|
34
70
|
- rm ./lib/tee_logger/constants.rb. Constants move to ./lib/tee_logger.rb
|
35
71
|
|
36
|
-
|
72
|
+
## v2.4.1
|
73
|
+
|
37
74
|
- update README.md
|
38
75
|
- and YARD comment
|
39
76
|
|
40
|
-
|
77
|
+
## v2.4.0
|
78
|
+
|
41
79
|
- TeeLogger#disable is allow block given
|
42
80
|
|
43
|
-
|
81
|
+
## v2.3.1
|
82
|
+
|
44
83
|
- refactoring TeeLogger#disable
|
45
84
|
|
46
|
-
|
85
|
+
## v2.3.0
|
86
|
+
|
47
87
|
- remove TeeLogger.attr_reader
|
48
88
|
- and rename instance variable: @logger => @logfile
|
49
89
|
- implementation `#level` and `level=`
|
50
90
|
- implementation `#formatter` and `formatter=`
|
51
91
|
|
52
|
-
|
92
|
+
## v2.2.0
|
93
|
+
|
53
94
|
- disabling and enabling
|
54
95
|
|
55
|
-
|
96
|
+
## v2.1.1
|
97
|
+
|
56
98
|
- refactoring of test case
|
57
99
|
- Introduced capture_stdout
|
58
100
|
- Introduced FakeFS
|
59
101
|
- Change logdev of Console for Logger from STDOUT to $ stdout
|
60
102
|
|
61
|
-
|
103
|
+
## v2.1.0
|
104
|
+
|
62
105
|
- Integrate TeeLogger::Base class to TeeLogger::TeeLogger class
|
63
106
|
|
64
|
-
|
107
|
+
## v2.0.2
|
108
|
+
|
65
109
|
- bugfix
|
66
110
|
|
67
|
-
|
111
|
+
## v2.0.1
|
112
|
+
|
68
113
|
- bugfix
|
69
114
|
|
70
|
-
|
115
|
+
## v2.0.0
|
116
|
+
|
71
117
|
- Change to Class from Module
|
72
118
|
|
73
|
-
|
119
|
+
## v1.1.0
|
120
|
+
|
74
121
|
- bugfix
|
75
122
|
|
76
|
-
|
123
|
+
## v1.0.0
|
124
|
+
|
77
125
|
- first
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
[![Gem Version]
|
2
|
-
[![Build Status]
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
1
|
+
[![Gem Version][gem_version-svg]][gem_version]
|
2
|
+
[![Build Status][travis-svg]][travis]
|
3
|
+
[![Downloads][downloads-svg]][gem_version]
|
4
|
+
[![Inline docs][inch-ci-svg]][inch-ci]
|
5
|
+
[![Code Climate][codeclimate-svg]][codeclimate]
|
6
|
+
[![Test Coverage][codeclimate_cov-svg]][codeclimate_cov]
|
6
7
|
|
7
8
|
> Sorry. In from version 2 to version 3, changed usage.
|
8
|
-
> see also [CHANGELOG.md]
|
9
|
+
> see also [CHANGELOG.md][tee_logger-changelog].
|
9
10
|
|
10
11
|
- [Rubygems.org](https://rubygems.org/gems/tee_logger)
|
11
12
|
- [GitHub](https://github.com/k-ta-yamada/tee_logger)
|
12
|
-
- [RubyDoc.info](
|
13
|
+
- [RubyDoc.info](https://www.rubydoc.info/gems/tee_logger)
|
13
14
|
|
14
15
|
# TeeLogger
|
15
16
|
|
@@ -47,6 +48,7 @@ $ gem install tee_logger
|
|
47
48
|
|
48
49
|
## Usage
|
49
50
|
|
51
|
+
### let's logging
|
50
52
|
```ruby
|
51
53
|
require 'tee_logger'
|
52
54
|
|
@@ -57,49 +59,67 @@ require 'tee_logger'
|
|
57
59
|
# shift_size = 1_048_576
|
58
60
|
tl = TeeLogger.new
|
59
61
|
|
60
|
-
# let's logging
|
61
62
|
tl.debug 'hello'
|
62
63
|
tl.debug(:progname) { 'hello world' }
|
63
64
|
tl.progname = 'App'
|
64
65
|
tl.debug 'hello tee_logger'
|
66
|
+
```
|
65
67
|
|
66
|
-
|
68
|
+
### enable only when specified
|
69
|
+
```ruby
|
67
70
|
tl.info 'this message is console and logfile'
|
68
71
|
tl.info 'this message is console only', :console
|
69
72
|
tl.info 'this message is logfile only', :logfile
|
73
|
+
```
|
70
74
|
|
71
|
-
|
75
|
+
### log meassage indent
|
76
|
+
```ruby
|
72
77
|
tl.info 'hello' # => 'hello'
|
73
78
|
tl.info 'hello', 0 # => 'hello'
|
74
79
|
tl.info 'hello', 2 # => ' hello'
|
80
|
+
```
|
75
81
|
|
76
|
-
|
82
|
+
### enabling and indent
|
83
|
+
```ruby
|
77
84
|
tl.info 'this message is console only', 2, :console
|
78
85
|
tl.info 'this message is console only', :console, 2
|
86
|
+
```
|
79
87
|
|
80
|
-
|
88
|
+
### disable console output
|
89
|
+
```ruby
|
81
90
|
tl.disable(:console)
|
82
91
|
tl.info 'this message is logfile only'
|
92
|
+
```
|
83
93
|
|
84
|
-
|
94
|
+
### enable console output
|
95
|
+
```ruby
|
85
96
|
tl.enable(:console)
|
86
97
|
tl.info 'this message is logfile and console'
|
98
|
+
```
|
87
99
|
|
88
|
-
|
100
|
+
### disable logfile output
|
101
|
+
```ruby
|
89
102
|
tl.disable(:logfile)
|
90
103
|
tl.info 'this message is consle only'
|
104
|
+
```
|
91
105
|
|
92
|
-
|
106
|
+
### enable logfile output
|
107
|
+
```ruby
|
93
108
|
tl.enable(:logfile)
|
94
109
|
tl.info 'this message is logfile and console'
|
110
|
+
```
|
95
111
|
|
96
|
-
|
112
|
+
### disable in block
|
113
|
+
```ruby
|
97
114
|
tl.disable(:console) do
|
98
115
|
tl.info 'this message is logfile only'
|
99
116
|
end
|
100
117
|
tl.info 'this message is logfile and console'
|
118
|
+
```
|
101
119
|
|
102
|
-
|
120
|
+
### and others like Logger's
|
121
|
+
```ruby
|
122
|
+
# log_level
|
103
123
|
tl.debug? # => true
|
104
124
|
tl.info? # => true
|
105
125
|
tl.warn? # => true
|
@@ -110,40 +130,83 @@ tl.level # => 0
|
|
110
130
|
tl.level = Logger::INFO
|
111
131
|
tl.debug 'this message is not logging'
|
112
132
|
|
133
|
+
# formatter
|
113
134
|
tl.formatter # => nil or Proc
|
114
|
-
tl.formatter =
|
135
|
+
tl.formatter =
|
136
|
+
proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
|
115
137
|
|
138
|
+
# datetime_formatter
|
116
139
|
tl.datetime_format # => nil or Proc
|
117
140
|
tl.datetime_format = '%Y%m%d %H%M%S '
|
118
141
|
```
|
119
142
|
|
120
143
|
|
121
|
-
## include or extend TeeLogger
|
144
|
+
## include or extend TeeLogger
|
122
145
|
|
123
|
-
>
|
146
|
+
> the log file will be in default of `./tee_logger.log`
|
124
147
|
|
148
|
+
### for casual use
|
125
149
|
```ruby
|
126
150
|
require 'tee_logger'
|
127
151
|
|
128
152
|
class YourAwesomeClass
|
153
|
+
# define method #logger for your class.
|
154
|
+
# log file will be in default of `./tee_logger.log`
|
129
155
|
include TeeLogger
|
130
156
|
|
131
157
|
def awesome_method
|
132
|
-
# do somthing
|
133
158
|
logger.info 'this is message is logging and disp console'
|
134
159
|
end
|
135
160
|
end
|
136
161
|
|
137
162
|
module YourAwesomeModule
|
163
|
+
# define singleton method .logger for your module.
|
164
|
+
# log file will be in default of `./tee_logger.log`
|
138
165
|
extend TeeLogger
|
139
166
|
|
140
167
|
def self.awesome_method
|
141
|
-
# do somthing
|
142
168
|
logger.info 'this is message is logging and disp console'
|
143
169
|
end
|
144
170
|
end
|
145
171
|
```
|
146
172
|
|
173
|
+
### configuration logfile name, progname, level, formatter, and datetime_format.
|
174
|
+
```ruby
|
175
|
+
require 'tee_logger'
|
176
|
+
|
177
|
+
# Before extend or include the module, allow the configuration.
|
178
|
+
# TeeLogger.logdev = 'log1.log'
|
179
|
+
TeeLogger.configure do |config|
|
180
|
+
config.logdev = 'log1.log'
|
181
|
+
config.level = Logger::Severity::INFO
|
182
|
+
config.progname = 'AwesomeApp'
|
183
|
+
config.formatter = proc { |s, t, p, m| "#{s} #{t} #{p} #{m}\n" }
|
184
|
+
# config.datetime_format = '%Y%m%d %H%M%S '
|
185
|
+
end
|
186
|
+
|
187
|
+
class YourAwesomeClass
|
188
|
+
include TeeLogger
|
189
|
+
|
190
|
+
def awesome_method
|
191
|
+
logger.info 'this message is output `log1.log`'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# reset configuration
|
196
|
+
TeeLogger.configuration_reset
|
197
|
+
|
198
|
+
# NOTE: sorry, `TeeLogger.logev` is deprecate.
|
199
|
+
TeeLogger.logdev = 'log2.log'
|
200
|
+
module YourAwesomeModule
|
201
|
+
extend TeeLogger
|
202
|
+
|
203
|
+
def self.awesome_method
|
204
|
+
logger.info 'this message is output `log2.log`'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
```
|
209
|
+
|
147
210
|
|
148
211
|
## Development
|
149
212
|
|
@@ -162,12 +225,29 @@ and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
162
225
|
|
163
226
|
## Contributing
|
164
227
|
|
165
|
-
Bug reports and pull requests are welcome on GitHub
|
228
|
+
Bug reports and pull requests are welcome on GitHub
|
229
|
+
at https://github.com/k-ta-yamada/tee_logger.
|
166
230
|
This project is intended to be a safe,
|
167
231
|
welcoming space for collaboration,
|
168
|
-
and contributors are expected to adhere to the
|
232
|
+
and contributors are expected to adhere to the
|
233
|
+
[Contributor Covenant](https://contributor-covenant.org) code of conduct.
|
169
234
|
|
170
235
|
|
171
236
|
## License
|
172
237
|
|
173
|
-
The gem is available as open source under the terms of the
|
238
|
+
The gem is available as open source under the terms of the
|
239
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
240
|
+
|
241
|
+
|
242
|
+
[gem_version]: https://badge.fury.io/rb/tee_logger
|
243
|
+
[gem_version-svg]: https://badge.fury.io/rb/tee_logger.svg
|
244
|
+
[travis]: https://travis-ci.org/k-ta-yamada/tee_logger
|
245
|
+
[travis-svg]: https://travis-ci.org/k-ta-yamada/tee_logger.svg
|
246
|
+
[codeclimate]: https://codeclimate.com/github/k-ta-yamada/tee_logger
|
247
|
+
[codeclimate-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg
|
248
|
+
[codeclimate_cov]: https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage
|
249
|
+
[codeclimate_cov-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg
|
250
|
+
[inch-ci]: https://inch-ci.org/github/k-ta-yamada/tee_logger
|
251
|
+
[inch-ci-svg]: https://inch-ci.org/github/k-ta-yamada/tee_logger.svg?branch=master
|
252
|
+
[downloads-svg]: https://ruby-gem-downloads-badge.herokuapp.com/tee_logger?type=total&total_label=&color=brightgreen
|
253
|
+
[tee_logger-changelog]: https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md
|
data/lib/tee_logger.rb
CHANGED
@@ -1,45 +1,44 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'tee_logger/version'
|
2
3
|
require 'tee_logger/constants'
|
4
|
+
require 'tee_logger/configuration'
|
3
5
|
require 'tee_logger/utils'
|
4
6
|
require 'tee_logger/tee_logger_base'
|
5
|
-
require 'logger'
|
6
7
|
|
7
8
|
# namespace
|
8
9
|
module TeeLogger
|
9
|
-
|
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
|
10
|
+
extend Configration
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
# shortcut for TeeLogger::TeeLoggerBase.new
|
13
|
+
# @param logdev [String]
|
14
|
+
# @param shift_age [Integer]
|
15
|
+
# @param shift_size [Integer]
|
16
|
+
# @return [TeeLogger::TeeLoggerBase]
|
17
|
+
# @see TeeLoggerBase
|
18
|
+
def self.new(logdev = nil, shift_age = 0, shift_size = 1_048_576)
|
19
|
+
TeeLoggerBase.new(logdev, shift_age, shift_size)
|
20
|
+
end
|
21
|
+
|
22
|
+
# define singleton method .logger for your module.
|
23
|
+
# and TeeLogger.progname is your module name.
|
24
|
+
def self.extended(mod)
|
25
|
+
mod.define_singleton_method(:logger) do
|
26
|
+
return @logger if @logger
|
27
|
+
@logger = TeeLogger.new
|
28
|
+
@logger.progname = TeeLogger.progname || mod
|
29
|
+
@logger
|
31
30
|
end
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
33
|
+
# define instance method #logger for your class.
|
34
|
+
# and TeeLogger.progname is your class name.
|
35
|
+
def self.included(klass)
|
36
|
+
klass.class_eval do
|
37
|
+
define_method(:logger) do
|
38
|
+
return @logger if @logger
|
39
|
+
@logger = TeeLogger.new
|
40
|
+
@logger.progname = TeeLogger.progname || klass.name
|
41
|
+
@logger
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# namespace
|
2
|
+
module TeeLogger
|
3
|
+
# configuration
|
4
|
+
module Configration
|
5
|
+
extend Gem::Deprecate
|
6
|
+
|
7
|
+
# @attr logdev [String, File]
|
8
|
+
# @attr level [Logger::Severity, Integer]
|
9
|
+
# @attr progname [String, Symbol]
|
10
|
+
# @attr formatter [Logger::Formatter, Proc]
|
11
|
+
# @attr datetime_format [String]
|
12
|
+
Configration = Struct.new(:logdev,
|
13
|
+
:level,
|
14
|
+
:progname,
|
15
|
+
:formatter,
|
16
|
+
:datetime_format)
|
17
|
+
|
18
|
+
# Yields the global configuration to a block.
|
19
|
+
# @yield [Configuration] global configuration
|
20
|
+
def configure
|
21
|
+
yield configuration if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
# reset configuration
|
25
|
+
def configuration_reset
|
26
|
+
@configuration = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# set TeeLogger::Configuration::Configration's member :logdev.
|
30
|
+
# extend or include TeeLogger then, :logdev is default argument
|
31
|
+
# for Logger.new(logdev).
|
32
|
+
# @param logdev [String, File]
|
33
|
+
def logdev=(logdev)
|
34
|
+
configuration.logdev = logdev
|
35
|
+
end
|
36
|
+
deprecate :logdev=, 'TeeLogger.configure', 2016, 1
|
37
|
+
|
38
|
+
# @return [String, File] `configuration.logdev` or `DEFAULT_FILE`.
|
39
|
+
def logdev
|
40
|
+
configuration.logdev || DEFAULT_FILE
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return `configuration.level`
|
44
|
+
def level
|
45
|
+
configuration.level
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return `configuration.progname`
|
49
|
+
def progname
|
50
|
+
configuration.progname
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return `configuration.formatter`
|
54
|
+
def formatter
|
55
|
+
configuration.formatter
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return `configuration.datetime_format`
|
59
|
+
def datetime_format
|
60
|
+
configuration.datetime_format
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def configuration
|
66
|
+
@configuration ||= Configration.new
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/tee_logger/constants.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
# namespace
|
2
2
|
module TeeLogger
|
3
3
|
# no param of filename, set this filename
|
4
|
-
DEFAULT_FILE = './tee_logger.log'
|
4
|
+
DEFAULT_FILE = './tee_logger.log'.freeze
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# configured attributes
|
7
|
+
CONFIGURED_ATTRIBUTES =
|
8
|
+
[:level, :progname, :formatter, :datetime_format].freeze
|
9
|
+
|
10
|
+
# implements targets
|
11
|
+
LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
|
8
12
|
|
9
13
|
# defined logdev names
|
10
|
-
LOGDEV_NAMES = [:console, :logfile]
|
14
|
+
LOGDEV_NAMES = [:console, :logfile].freeze
|
11
15
|
|
12
16
|
# defined paired of logdev name
|
13
|
-
LOGDEV_REVERSE = { console: :logfile, logfile: :console }
|
17
|
+
LOGDEV_REVERSE = { console: :logfile, logfile: :console }.freeze
|
14
18
|
|
15
19
|
# empty format
|
16
20
|
FORMATTER_FOR_DISABLING = proc { |_severity, _time, _progname, _msg| '' }
|
17
21
|
|
18
22
|
# using TeeLogger::Utils.extract_options
|
19
|
-
# @
|
20
|
-
# @
|
23
|
+
# @attr logdev_name [Symbol]
|
24
|
+
# @attr indent_level [Fixnum]
|
21
25
|
ParsedOption = Struct.new(:logdev_name, :indent_level)
|
22
26
|
|
23
27
|
# LOGDEV_NAMES not included error
|
@@ -37,15 +37,19 @@ module TeeLogger
|
|
37
37
|
end
|
38
38
|
|
39
39
|
include Utils
|
40
|
-
attr_reader :level, :progname, :formatter, :datetime_format
|
40
|
+
# attr_reader :level, :progname, :formatter, :datetime_format
|
41
|
+
attr_reader(*CONFIGURED_ATTRIBUTES)
|
41
42
|
|
42
43
|
# @param logdev [String]
|
43
44
|
# @param shift_age [Integer]
|
44
45
|
# @param shift_size [Integer]
|
45
46
|
# @see Logger#initialize
|
46
|
-
def initialize(logdev =
|
47
|
+
def initialize(logdev = nil, shift_age = 0, shift_size = 1_048_576)
|
47
48
|
@console = Logger.new($stdout)
|
48
|
-
@logfile = Logger.new(logdev, shift_age, shift_size)
|
49
|
+
@logfile = Logger.new(logdev || TeeLogger.logdev, shift_age, shift_size)
|
50
|
+
|
51
|
+
@level, @progname, @formatter, @datetime_format = nil
|
52
|
+
configuration
|
49
53
|
end
|
50
54
|
|
51
55
|
define_logging_methods :debug
|
@@ -64,8 +68,8 @@ module TeeLogger
|
|
64
68
|
def level=(level)
|
65
69
|
@console.level = @logfile.level = @level = level
|
66
70
|
end
|
67
|
-
|
68
|
-
|
71
|
+
alias sev_threshold level
|
72
|
+
alias sev_threshold= level=
|
69
73
|
|
70
74
|
# @param name [String, Symbol]
|
71
75
|
def progname=(name = nil)
|
@@ -77,11 +81,11 @@ module TeeLogger
|
|
77
81
|
@console.formatter = @logfile.formatter = @formatter = formatter
|
78
82
|
end
|
79
83
|
|
80
|
-
# @param
|
81
|
-
def datetime_format=(
|
84
|
+
# @param datetime_format
|
85
|
+
def datetime_format=(datetime_format)
|
82
86
|
@console.datetime_format =
|
83
87
|
@logfile.datetime_format =
|
84
|
-
@datetime_format =
|
88
|
+
@datetime_format = datetime_format
|
85
89
|
end
|
86
90
|
|
87
91
|
# @param logdev_name [String, Symbol]
|
@@ -105,6 +109,13 @@ module TeeLogger
|
|
105
109
|
|
106
110
|
private
|
107
111
|
|
112
|
+
def configuration
|
113
|
+
CONFIGURED_ATTRIBUTES.each do |method_name|
|
114
|
+
value = TeeLogger.send(method_name)
|
115
|
+
send("#{method_name}=", value) unless value.nil?
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
108
119
|
def logging(name, progname, logdev_name = nil, &block)
|
109
120
|
if logdev_name
|
110
121
|
disable(logdev_name) { logging(name, progname, &block) }
|
data/lib/tee_logger/utils.rb
CHANGED
@@ -2,15 +2,13 @@
|
|
2
2
|
module TeeLogger
|
3
3
|
# util
|
4
4
|
module Utils
|
5
|
-
module_function
|
6
|
-
|
7
5
|
# @param options [Array]
|
8
6
|
# @return [ParsedOption]
|
9
7
|
def extract_options(options)
|
10
8
|
options.each_with_object(ParsedOption.new(nil, 0)) do |val, obj|
|
11
9
|
case val
|
12
10
|
when Symbol then obj.logdev_name = name_reverse(val)
|
13
|
-
when
|
11
|
+
when Integer then obj.indent_level = val
|
14
12
|
else incorrect_option_error(val)
|
15
13
|
end
|
16
14
|
end
|
data/lib/tee_logger/version.rb
CHANGED
data/tee_logger.gemspec
CHANGED
@@ -9,9 +9,12 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['k-ta-yamada']
|
10
10
|
spec.email = ['key.luvless@gmail.com']
|
11
11
|
|
12
|
+
spec.required_ruby_version = '>= 2.5.0'
|
13
|
+
|
12
14
|
spec.summary = 'logging to file and standard output.'
|
13
|
-
|
14
|
-
|
15
|
+
# rubocop:disable Metrics/LineLength
|
16
|
+
spec.description = 'logging to file and standard output. require standard library only.'
|
17
|
+
# rubocop:enable Metrics/LineLength
|
15
18
|
|
16
19
|
spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
|
17
20
|
spec.license = 'MIT'
|
@@ -23,10 +26,12 @@ Gem::Specification.new do |spec|
|
|
23
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
27
|
spec.require_paths = ['lib']
|
25
28
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'rake'
|
28
31
|
spec.add_development_dependency 'rspec'
|
29
32
|
spec.add_development_dependency 'fuubar'
|
33
|
+
spec.add_development_dependency 'simplecov'
|
34
|
+
spec.add_development_dependency 'simplecov-console'
|
30
35
|
|
31
36
|
spec.add_development_dependency 'pry'
|
32
37
|
spec.add_development_dependency 'pry-doc'
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tee_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- k-ta-yamada
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-03 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
|
-
version: '
|
19
|
+
version: '0'
|
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
|
-
version: '
|
26
|
+
version: '0'
|
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
|
-
version: '
|
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
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov-console
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: pry
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,6 +201,8 @@ extra_rdoc_files: []
|
|
173
201
|
files:
|
174
202
|
- ".gitignore"
|
175
203
|
- ".rspec"
|
204
|
+
- ".rubocop.yml"
|
205
|
+
- ".rubocop_todo.yml"
|
176
206
|
- ".travis.yml"
|
177
207
|
- CHANGELOG.md
|
178
208
|
- CODE_OF_CONDUCT.md
|
@@ -181,6 +211,7 @@ files:
|
|
181
211
|
- README.md
|
182
212
|
- Rakefile
|
183
213
|
- lib/tee_logger.rb
|
214
|
+
- lib/tee_logger/configuration.rb
|
184
215
|
- lib/tee_logger/constants.rb
|
185
216
|
- lib/tee_logger/tee_logger_base.rb
|
186
217
|
- lib/tee_logger/utils.rb
|
@@ -190,7 +221,7 @@ homepage: https://github.com/k-ta-yamada/tee_logger
|
|
190
221
|
licenses:
|
191
222
|
- MIT
|
192
223
|
metadata: {}
|
193
|
-
post_install_message:
|
224
|
+
post_install_message:
|
194
225
|
rdoc_options: []
|
195
226
|
require_paths:
|
196
227
|
- lib
|
@@ -198,17 +229,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
229
|
requirements:
|
199
230
|
- - ">="
|
200
231
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
232
|
+
version: 2.5.0
|
202
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
234
|
requirements:
|
204
235
|
- - ">="
|
205
236
|
- !ruby/object:Gem::Version
|
206
237
|
version: '0'
|
207
238
|
requirements: []
|
208
|
-
|
209
|
-
|
210
|
-
signing_key:
|
239
|
+
rubygems_version: 3.2.3
|
240
|
+
signing_key:
|
211
241
|
specification_version: 4
|
212
242
|
summary: logging to file and standard output.
|
213
243
|
test_files: []
|
214
|
-
has_rdoc:
|