tee_logger 3.2.0 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop_todo.yml +2 -0
- data/.travis.yml +15 -7
- data/CHANGELOG.md +70 -23
- data/Gemfile +0 -2
- data/README.md +205 -101
- data/lib/tee_logger/configuration.rb +69 -0
- data/lib/tee_logger/constants.rb +11 -7
- data/lib/tee_logger/tee_logger_base.rb +17 -8
- data/lib/tee_logger/utils.rb +1 -3
- data/lib/tee_logger/version.rb +1 -1
- data/lib/tee_logger.rb +9 -21
- data/tee_logger.gemspec +9 -3
- metadata +44 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc70b6c37a05823b6818f4c50fdd84ab2f7daa918850d08c2005df58ecd4e0db
|
4
|
+
data.tar.gz: 68a01c36f6e721f2c9de7dfdc48000a47cf50fdb8ce808484a40d4ba816ea7b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5c9c18eb38fe4a92ff9cefd7004c5abc4cde8993e30cf92607861b64ed15952db96f0d00d409259983be84015a1c37d6d841c4a4d5dd8a7257f2a5eddb4f2ac
|
7
|
+
data.tar.gz: f543787f7d4b0ee9bbe73ccf33a4e4bbef5130c1b716ee04e816a0d50bcd6bf95d49881608ca397fd62c8edb5ad5dbb9e79633346b04e48af0aaaec44302669b
|
data/.rubocop_todo.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
language: ruby
|
2
|
+
|
2
3
|
cache: bundler
|
4
|
+
|
3
5
|
rvm:
|
4
|
-
-
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
- 3.0
|
7
|
+
- 2.7
|
8
|
+
- 2.6
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
12
|
+
- chmod +x ./cc-test-reporter
|
13
|
+
|
14
|
+
before_script:
|
15
|
+
- ./cc-test-reporter before-build
|
16
|
+
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
@@ -1,84 +1,131 @@
|
|
1
|
-
#
|
1
|
+
# CHANGELOG.md
|
2
|
+
|
3
|
+
## v3.2.4
|
4
|
+
|
5
|
+
2021-09-04 JST
|
6
|
+
|
7
|
+
- required_ruby_version change to `>= 2.6.0` because Ruby 2.5 reaches EOL.
|
8
|
+
|
9
|
+
## v3.2.3
|
10
|
+
|
11
|
+
2020-01-03 JST
|
12
|
+
|
13
|
+
- Add support for Ruby 3.0
|
14
|
+
|
15
|
+
## v3.2.2
|
16
|
+
|
17
|
+
- [issue #17](https://github.com/k-ta-yamada/tee_logger/issues/17)
|
18
|
+
default settings for extend and include
|
19
|
+
|
20
|
+
## v3.2.1
|
21
|
+
|
22
|
+
- [issue #18](https://github.com/k-ta-yamada/tee_logger/issues/18)
|
23
|
+
use initial value `DEFAULT_FILE`, it's change TeeLogger.logdev
|
24
|
+
|
25
|
+
## v3.2.0
|
26
|
+
|
2
27
|
- [issue #15](https://github.com/k-ta-yamada/tee_logger/issues/15)
|
3
28
|
Before extend or include the module, allow the setting of logdev
|
4
29
|
|
5
|
-
|
30
|
+
## v3.1.2
|
31
|
+
|
6
32
|
- add .gemspec required_ruby_version = '>= 2.0.0'
|
7
33
|
|
8
|
-
|
34
|
+
## v3.1.1
|
35
|
+
|
9
36
|
- [[clean] module split](https://github.com/k-ta-yamada/tee_logger/pull/14)
|
10
37
|
|
11
|
-
|
38
|
+
## v3.1.0
|
39
|
+
|
12
40
|
- [issue #12](https://github.com/k-ta-yamada/tee_logger/issues/12)
|
13
41
|
Include and Extend support
|
14
42
|
|
15
|
-
|
43
|
+
## v3.0.3
|
44
|
+
|
16
45
|
- shared_examples_for_tee_logger_spec.rb [ae1e481](https://github.com/k-ta-yamada/tee_logger/commit/ae1e481)
|
17
46
|
- new constant for disabling formatter [478eccb](https://github.com/k-ta-yamada/tee_logger/commit/478eccb)
|
18
47
|
|
19
|
-
|
48
|
+
## v3.0.2
|
49
|
+
|
20
50
|
- refactoring
|
21
51
|
- CONSTANTS move to ./lib/constants.rb
|
22
52
|
|
23
|
-
|
53
|
+
## v3.0.1
|
54
|
+
|
24
55
|
- refactoring for [issue #9](https://github.com/k-ta-yamada/tee_logger/issues/9)
|
25
56
|
|
26
|
-
|
57
|
+
## v3.0.0
|
58
|
+
|
27
59
|
- [issue #4](https://github.com/k-ta-yamada/tee_logger/issues/4)
|
28
60
|
logging method's parametrer disabling_target change to enabling_targe
|
29
61
|
- [issue #5](https://github.com/k-ta-yamada/tee_logger/issues/5)
|
30
62
|
log message indentation
|
31
63
|
|
32
|
-
|
64
|
+
## v2.7.0
|
65
|
+
|
33
66
|
- add datetime_format, datetime_format=
|
34
67
|
|
35
|
-
|
68
|
+
## v2.6.0
|
69
|
+
|
36
70
|
- disabling option add to logging_methods
|
37
71
|
|
38
|
-
|
72
|
+
## v2.5.0
|
73
|
+
|
39
74
|
- level, progname and formatter were changed to instance variable
|
40
75
|
- refactoring: disabling and enabling
|
41
76
|
- rm ./lib/tee_logger/constants.rb. Constants move to ./lib/tee_logger.rb
|
42
77
|
|
43
|
-
|
78
|
+
## v2.4.1
|
79
|
+
|
44
80
|
- update README.md
|
45
81
|
- and YARD comment
|
46
82
|
|
47
|
-
|
83
|
+
## v2.4.0
|
84
|
+
|
48
85
|
- TeeLogger#disable is allow block given
|
49
86
|
|
50
|
-
|
87
|
+
## v2.3.1
|
88
|
+
|
51
89
|
- refactoring TeeLogger#disable
|
52
90
|
|
53
|
-
|
91
|
+
## v2.3.0
|
92
|
+
|
54
93
|
- remove TeeLogger.attr_reader
|
55
94
|
- and rename instance variable: @logger => @logfile
|
56
95
|
- implementation `#level` and `level=`
|
57
96
|
- implementation `#formatter` and `formatter=`
|
58
97
|
|
59
|
-
|
98
|
+
## v2.2.0
|
99
|
+
|
60
100
|
- disabling and enabling
|
61
101
|
|
62
|
-
|
102
|
+
## v2.1.1
|
103
|
+
|
63
104
|
- refactoring of test case
|
64
105
|
- Introduced capture_stdout
|
65
106
|
- Introduced FakeFS
|
66
107
|
- Change logdev of Console for Logger from STDOUT to $ stdout
|
67
108
|
|
68
|
-
|
109
|
+
## v2.1.0
|
110
|
+
|
69
111
|
- Integrate TeeLogger::Base class to TeeLogger::TeeLogger class
|
70
112
|
|
71
|
-
|
113
|
+
## v2.0.2
|
114
|
+
|
72
115
|
- bugfix
|
73
116
|
|
74
|
-
|
117
|
+
## v2.0.1
|
118
|
+
|
75
119
|
- bugfix
|
76
120
|
|
77
|
-
|
121
|
+
## v2.0.0
|
122
|
+
|
78
123
|
- Change to Class from Module
|
79
124
|
|
80
|
-
|
125
|
+
## v1.1.0
|
126
|
+
|
81
127
|
- bugfix
|
82
128
|
|
83
|
-
|
129
|
+
## v1.0.0
|
130
|
+
|
84
131
|
- first
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,57 @@
|
|
1
|
+
# TeeLogger
|
2
|
+
|
1
3
|
[![Gem Version][gem_version-svg]][gem_version]
|
2
4
|
[![Build Status][travis-svg]][travis]
|
5
|
+
[![Downloads][downloads-svg]][gem_version]
|
6
|
+
[![Inline docs][inch-ci-svg]][inch-ci]
|
3
7
|
[![Code Climate][codeclimate-svg]][codeclimate]
|
4
8
|
[![Test Coverage][codeclimate_cov-svg]][codeclimate_cov]
|
5
|
-
[![Inline docs][inch-ci-svg]][inch-ci]
|
6
9
|
|
7
10
|
> Sorry. In from version 2 to version 3, changed usage.
|
8
11
|
> see also [CHANGELOG.md][tee_logger-changelog].
|
9
12
|
|
10
13
|
- [Rubygems.org](https://rubygems.org/gems/tee_logger)
|
11
14
|
- [GitHub](https://github.com/k-ta-yamada/tee_logger)
|
12
|
-
- [RubyDoc.info](
|
13
|
-
|
14
|
-
# TeeLogger
|
15
|
+
- [RubyDoc.info](https://www.rubydoc.info/gems/tee_logger)
|
15
16
|
|
16
17
|
logging to file and standard output.
|
17
18
|
require standard library only.
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
<!-- TOC -->
|
21
|
+
|
22
|
+
- [1. Characteristic](#1-characteristic)
|
23
|
+
- [2. Installation](#2-installation)
|
24
|
+
- [3. Usage](#3-usage)
|
25
|
+
- [3.1. let's logging](#31-lets-logging)
|
26
|
+
- [3.2. enable only when specified](#32-enable-only-when-specified)
|
27
|
+
- [3.3. log meassage indent](#33-log-meassage-indent)
|
28
|
+
- [3.4. enabling and indent](#34-enabling-and-indent)
|
29
|
+
- [3.5. disable console output](#35-disable-console-output)
|
30
|
+
- [3.6. enable console output](#36-enable-console-output)
|
31
|
+
- [3.7. disable logfile output](#37-disable-logfile-output)
|
32
|
+
- [3.8. enable logfile output](#38-enable-logfile-output)
|
33
|
+
- [3.9. disable in block](#39-disable-in-block)
|
34
|
+
- [3.10. and others like Logger's](#310-and-others-like-loggers)
|
35
|
+
- [4. include or extend TeeLogger](#4-include-or-extend-teelogger)
|
36
|
+
- [4.1. for casual use](#41-for-casual-use)
|
37
|
+
- [4.2. configuration logfile name, progname, level, formatter, and datetime_format](#42-configuration-logfile-name-progname-level-formatter-and-datetime_format)
|
38
|
+
- [5. Development](#5-development)
|
39
|
+
- [6. Contributing](#6-contributing)
|
40
|
+
- [7. License](#7-license)
|
41
|
+
|
42
|
+
<!-- /TOC -->
|
43
|
+
|
44
|
+
---
|
45
|
+
|
46
|
+
## 1. Characteristic
|
21
47
|
|
22
48
|
- use standard lib only.
|
23
49
|
- like Logger: see usage.
|
24
50
|
- enabled or disabled by switching the output of the console and the logfile.
|
25
51
|
|
52
|
+
---
|
26
53
|
|
27
|
-
## Installation
|
54
|
+
## 2. Installation
|
28
55
|
|
29
56
|
Add this line to your application's Gemfile:
|
30
57
|
|
@@ -34,119 +61,195 @@ gem 'tee_logger'
|
|
34
61
|
|
35
62
|
And then execute:
|
36
63
|
|
37
|
-
```
|
38
|
-
|
64
|
+
```sh
|
65
|
+
bundle
|
39
66
|
```
|
40
67
|
|
41
68
|
Or install it yourself as:
|
42
69
|
|
70
|
+
```sh
|
71
|
+
gem install tee_logger
|
72
|
+
```
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
## 3. Usage
|
77
|
+
|
78
|
+
### 3.1. let's logging
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
require 'tee_logger'
|
82
|
+
|
83
|
+
# Logger.new like options(logdev, shift_age, shift_size)
|
84
|
+
# options default value is
|
85
|
+
# logdev = './tee_logger.log'
|
86
|
+
# shift_age = 0
|
87
|
+
# shift_size = 1_048_576
|
88
|
+
tl = TeeLogger.new
|
89
|
+
|
90
|
+
tl.debug 'hello'
|
91
|
+
tl.debug(:progname) { 'hello world' }
|
92
|
+
tl.progname = 'App'
|
93
|
+
tl.debug 'hello tee_logger'
|
43
94
|
```
|
44
|
-
|
95
|
+
|
96
|
+
### 3.2. enable only when specified
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
tl.info 'this message is console and logfile'
|
100
|
+
tl.info 'this message is console only', :console
|
101
|
+
tl.info 'this message is logfile only', :logfile
|
45
102
|
```
|
46
103
|
|
104
|
+
### 3.3. log meassage indent
|
47
105
|
|
48
|
-
|
106
|
+
```ruby
|
107
|
+
tl.info 'hello' # => 'hello'
|
108
|
+
tl.info 'hello', 0 # => 'hello'
|
109
|
+
tl.info 'hello', 2 # => ' hello'
|
110
|
+
```
|
111
|
+
|
112
|
+
### 3.4. enabling and indent
|
49
113
|
|
50
114
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
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'
|
115
|
+
tl.info 'this message is console only', 2, :console
|
116
|
+
tl.info 'this message is console only', :console, 2
|
117
|
+
```
|
83
118
|
|
84
|
-
|
85
|
-
tl.enable(:console)
|
86
|
-
tl.info 'this message is logfile and console'
|
119
|
+
### 3.5. disable console output
|
87
120
|
|
88
|
-
|
89
|
-
|
90
|
-
|
121
|
+
```ruby
|
122
|
+
tl.disable(:console)
|
123
|
+
tl.info 'this message is logfile only'
|
124
|
+
```
|
91
125
|
|
92
|
-
|
93
|
-
tl.enable(:logfile)
|
94
|
-
tl.info 'this message is logfile and console'
|
126
|
+
### 3.6. enable console output
|
95
127
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
128
|
+
```ruby
|
129
|
+
tl.enable(:console)
|
130
|
+
tl.info 'this message is logfile and console'
|
131
|
+
```
|
132
|
+
|
133
|
+
### 3.7. disable logfile output
|
101
134
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
135
|
+
```ruby
|
136
|
+
tl.disable(:logfile)
|
137
|
+
tl.info 'this message is consle only'
|
138
|
+
```
|
139
|
+
|
140
|
+
### 3.8. enable logfile output
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
tl.enable(:logfile)
|
144
|
+
tl.info 'this message is logfile and console'
|
145
|
+
```
|
146
|
+
|
147
|
+
### 3.9. disable in block
|
108
148
|
|
109
|
-
|
110
|
-
|
111
|
-
tl.
|
149
|
+
```ruby
|
150
|
+
tl.disable(:console) do
|
151
|
+
tl.info 'this message is logfile only'
|
152
|
+
end
|
153
|
+
tl.info 'this message is logfile and console'
|
154
|
+
```
|
112
155
|
|
113
|
-
|
114
|
-
tl.formatter =
|
115
|
-
proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
|
156
|
+
### 3.10. and others like Logger's
|
116
157
|
|
117
|
-
|
118
|
-
|
158
|
+
```ruby
|
159
|
+
# log_level
|
160
|
+
tl.debug? # => true
|
161
|
+
tl.info? # => true
|
162
|
+
tl.warn? # => true
|
163
|
+
tl.error? # => true
|
164
|
+
tl.fatal? # => true
|
165
|
+
|
166
|
+
tl.level # => 0
|
167
|
+
tl.level = Logger::INFO
|
168
|
+
tl.debug 'this message is not logging'
|
169
|
+
|
170
|
+
# formatter
|
171
|
+
tl.formatter # => nil or Proc
|
172
|
+
tl.formatter =
|
173
|
+
proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
|
174
|
+
|
175
|
+
# datetime_formatter
|
176
|
+
tl.datetime_format # => nil or Proc
|
177
|
+
tl.datetime_format = '%Y%m%d %H%M%S '
|
119
178
|
```
|
120
179
|
|
180
|
+
---
|
121
181
|
|
122
|
-
## include or extend TeeLogger
|
182
|
+
## 4. include or extend TeeLogger
|
123
183
|
|
124
|
-
>
|
184
|
+
> the log file will be in default of `./tee_logger.log`
|
185
|
+
|
186
|
+
### 4.1. for casual use
|
125
187
|
|
126
188
|
```ruby
|
127
|
-
|
189
|
+
require 'tee_logger'
|
190
|
+
|
191
|
+
class YourAwesomeClass
|
192
|
+
# define method #logger for your class.
|
193
|
+
# log file will be in default of `./tee_logger.log`
|
194
|
+
include TeeLogger
|
195
|
+
|
196
|
+
def awesome_method
|
197
|
+
logger.info 'this is message is logging and disp console'
|
198
|
+
end
|
199
|
+
end
|
128
200
|
|
129
|
-
|
130
|
-
|
201
|
+
module YourAwesomeModule
|
202
|
+
# define singleton method .logger for your module.
|
203
|
+
# log file will be in default of `./tee_logger.log`
|
204
|
+
extend TeeLogger
|
131
205
|
|
132
|
-
|
133
|
-
|
134
|
-
logger.info 'this is message is logging and disp console'
|
135
|
-
end
|
206
|
+
def self.awesome_method
|
207
|
+
logger.info 'this is message is logging and disp console'
|
136
208
|
end
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
### 4.2. configuration logfile name, progname, level, formatter, and datetime_format
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
require 'tee_logger'
|
216
|
+
|
217
|
+
# Before extend or include the module, allow the configuration.
|
218
|
+
# TeeLogger.logdev = 'log1.log'
|
219
|
+
TeeLogger.configure do |config|
|
220
|
+
config.logdev = 'log1.log'
|
221
|
+
config.level = Logger::Severity::INFO
|
222
|
+
config.progname = 'AwesomeApp'
|
223
|
+
config.formatter = proc { |s, t, p, m| "#{s} #{t} #{p} #{m}\n" }
|
224
|
+
# config.datetime_format = '%Y%m%d %H%M%S '
|
225
|
+
end
|
226
|
+
|
227
|
+
class YourAwesomeClass
|
228
|
+
include TeeLogger
|
229
|
+
|
230
|
+
def awesome_method
|
231
|
+
logger.info 'this message is output `log1.log`'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# reset configuration
|
236
|
+
TeeLogger.configuration_reset
|
137
237
|
|
138
|
-
|
139
|
-
|
238
|
+
# NOTE: sorry, `TeeLogger.logev` is deprecate.
|
239
|
+
TeeLogger.logdev = 'log2.log'
|
240
|
+
module YourAwesomeModule
|
241
|
+
extend TeeLogger
|
140
242
|
|
141
|
-
|
142
|
-
|
143
|
-
logger.info 'this is message is logging and disp console'
|
144
|
-
end
|
243
|
+
def self.awesome_method
|
244
|
+
logger.info 'this message is output `log2.log`'
|
145
245
|
end
|
246
|
+
end
|
247
|
+
|
146
248
|
```
|
147
249
|
|
250
|
+
---
|
148
251
|
|
149
|
-
## Development
|
252
|
+
## 5. Development
|
150
253
|
|
151
254
|
After checking out the repo, run `bundle install` to install dependencies.
|
152
255
|
Then, run `rake rspec` to run the tests.
|
@@ -160,36 +263,37 @@ which will create a git tag for the version,
|
|
160
263
|
push git commits and tags,
|
161
264
|
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
162
265
|
|
266
|
+
---
|
163
267
|
|
164
|
-
## Contributing
|
268
|
+
## 6. Contributing
|
165
269
|
|
166
270
|
Bug reports and pull requests are welcome on GitHub
|
167
271
|
at https://github.com/k-ta-yamada/tee_logger.
|
168
272
|
This project is intended to be a safe,
|
169
273
|
welcoming space for collaboration,
|
170
274
|
and contributors are expected to adhere to the
|
171
|
-
[Contributor Covenant](
|
275
|
+
[Contributor Covenant](https://contributor-covenant.org) code of conduct.
|
172
276
|
|
277
|
+
---
|
173
278
|
|
174
|
-
## License
|
279
|
+
## 7. License
|
175
280
|
|
176
281
|
The gem is available as open source under the terms of the
|
177
|
-
[MIT License](
|
178
|
-
|
282
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
179
283
|
|
180
|
-
|
181
|
-
[gem_version-svg]: https://badge.fury.io/rb/tee_logger.svg
|
284
|
+
---
|
182
285
|
|
183
|
-
|
184
|
-
[travis-svg]: https://travis-ci.org/k-ta-yamada/tee_logger.svg
|
286
|
+
eof
|
185
287
|
|
288
|
+
[gem_version]: https://badge.fury.io/rb/tee_logger
|
289
|
+
[gem_version-svg]: https://badge.fury.io/rb/tee_logger.svg
|
290
|
+
[travis]: https://app.travis-ci.com/k-ta-yamada/tee_logger
|
291
|
+
[travis-svg]: https://app.travis-ci.com/k-ta-yamada/tee_logger.svg?branch=master
|
186
292
|
[codeclimate]: https://codeclimate.com/github/k-ta-yamada/tee_logger
|
187
293
|
[codeclimate-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg
|
188
|
-
|
189
294
|
[codeclimate_cov]: https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage
|
190
295
|
[codeclimate_cov-svg]: https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg
|
191
|
-
|
192
|
-
[inch-ci]:
|
193
|
-
[
|
194
|
-
|
296
|
+
[inch-ci]: https://inch-ci.org/github/k-ta-yamada/tee_logger
|
297
|
+
[inch-ci-svg]: https://inch-ci.org/github/k-ta-yamada/tee_logger.svg?branch=master
|
298
|
+
[downloads-svg]: https://ruby-gem-downloads-badge.herokuapp.com/tee_logger?type=total&total_label=&color=brightgreen
|
195
299
|
[tee_logger-changelog]: https://github.com/k-ta-yamada/tee_logger/blob/master/CHANGELOG.md
|
@@ -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,17 +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)
|
49
50
|
|
50
51
|
@level, @progname, @formatter, @datetime_format = nil
|
52
|
+
configuration
|
51
53
|
end
|
52
54
|
|
53
55
|
define_logging_methods :debug
|
@@ -66,8 +68,8 @@ module TeeLogger
|
|
66
68
|
def level=(level)
|
67
69
|
@console.level = @logfile.level = @level = level
|
68
70
|
end
|
69
|
-
|
70
|
-
|
71
|
+
alias sev_threshold level
|
72
|
+
alias sev_threshold= level=
|
71
73
|
|
72
74
|
# @param name [String, Symbol]
|
73
75
|
def progname=(name = nil)
|
@@ -79,11 +81,11 @@ module TeeLogger
|
|
79
81
|
@console.formatter = @logfile.formatter = @formatter = formatter
|
80
82
|
end
|
81
83
|
|
82
|
-
# @param
|
83
|
-
def datetime_format=(
|
84
|
+
# @param datetime_format
|
85
|
+
def datetime_format=(datetime_format)
|
84
86
|
@console.datetime_format =
|
85
87
|
@logfile.datetime_format =
|
86
|
-
@datetime_format =
|
88
|
+
@datetime_format = datetime_format
|
87
89
|
end
|
88
90
|
|
89
91
|
# @param logdev_name [String, Symbol]
|
@@ -107,6 +109,13 @@ module TeeLogger
|
|
107
109
|
|
108
110
|
private
|
109
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
|
+
|
110
119
|
def logging(name, progname, logdev_name = nil, &block)
|
111
120
|
if logdev_name
|
112
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/lib/tee_logger.rb
CHANGED
@@ -1,43 +1,31 @@
|
|
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
|
10
|
+
extend Configration
|
11
|
+
|
9
12
|
# shortcut for TeeLogger::TeeLoggerBase.new
|
10
13
|
# @param logdev [String]
|
11
14
|
# @param shift_age [Integer]
|
12
15
|
# @param shift_size [Integer]
|
13
16
|
# @return [TeeLogger::TeeLoggerBase]
|
14
17
|
# @see TeeLoggerBase
|
15
|
-
def self.new(logdev =
|
18
|
+
def self.new(logdev = nil, shift_age = 0, shift_size = 1_048_576)
|
16
19
|
TeeLoggerBase.new(logdev, shift_age, shift_size)
|
17
20
|
end
|
18
21
|
|
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
22
|
# define singleton method .logger for your module.
|
35
23
|
# and TeeLogger.progname is your module name.
|
36
24
|
def self.extended(mod)
|
37
25
|
mod.define_singleton_method(:logger) do
|
38
26
|
return @logger if @logger
|
39
|
-
@logger =
|
40
|
-
@logger.progname = mod
|
27
|
+
@logger = TeeLogger.new
|
28
|
+
@logger.progname = TeeLogger.progname || mod
|
41
29
|
@logger
|
42
30
|
end
|
43
31
|
end
|
@@ -48,8 +36,8 @@ module TeeLogger
|
|
48
36
|
klass.class_eval do
|
49
37
|
define_method(:logger) do
|
50
38
|
return @logger if @logger
|
51
|
-
@logger =
|
52
|
-
@logger.progname = klass.name
|
39
|
+
@logger = TeeLogger.new
|
40
|
+
@logger.progname = TeeLogger.progname || klass.name
|
53
41
|
@logger
|
54
42
|
end
|
55
43
|
end
|
data/tee_logger.gemspec
CHANGED
@@ -9,7 +9,7 @@ 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.
|
12
|
+
spec.required_ruby_version = '>= 2.6.0'
|
13
13
|
|
14
14
|
spec.summary = 'logging to file and standard output.'
|
15
15
|
# rubocop:disable Metrics/LineLength
|
@@ -26,10 +26,16 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
-
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
31
|
spec.add_development_dependency 'rspec'
|
32
32
|
spec.add_development_dependency 'fuubar'
|
33
|
+
# Workaround for cc-test-reporter with SimpleCov 0.18.
|
34
|
+
# Stop upgrading SimpleCov until the following issue will be resolved.
|
35
|
+
# https://github.com/codeclimate/test-reporter/issues/418
|
36
|
+
# https://github.com/codeclimate/test-reporter/issues/413
|
37
|
+
spec.add_development_dependency 'simplecov', '= 0.17'
|
38
|
+
spec.add_development_dependency 'simplecov-console'
|
33
39
|
|
34
40
|
spec.add_development_dependency 'pry'
|
35
41
|
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.2.
|
4
|
+
version: 3.2.4
|
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-09-04 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.17'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.17'
|
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
|
@@ -183,6 +211,7 @@ files:
|
|
183
211
|
- README.md
|
184
212
|
- Rakefile
|
185
213
|
- lib/tee_logger.rb
|
214
|
+
- lib/tee_logger/configuration.rb
|
186
215
|
- lib/tee_logger/constants.rb
|
187
216
|
- lib/tee_logger/tee_logger_base.rb
|
188
217
|
- lib/tee_logger/utils.rb
|
@@ -192,7 +221,7 @@ homepage: https://github.com/k-ta-yamada/tee_logger
|
|
192
221
|
licenses:
|
193
222
|
- MIT
|
194
223
|
metadata: {}
|
195
|
-
post_install_message:
|
224
|
+
post_install_message:
|
196
225
|
rdoc_options: []
|
197
226
|
require_paths:
|
198
227
|
- lib
|
@@ -200,17 +229,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
229
|
requirements:
|
201
230
|
- - ">="
|
202
231
|
- !ruby/object:Gem::Version
|
203
|
-
version: 2.
|
232
|
+
version: 2.6.0
|
204
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
234
|
requirements:
|
206
235
|
- - ">="
|
207
236
|
- !ruby/object:Gem::Version
|
208
237
|
version: '0'
|
209
238
|
requirements: []
|
210
|
-
|
211
|
-
|
212
|
-
signing_key:
|
239
|
+
rubygems_version: 3.2.3
|
240
|
+
signing_key:
|
213
241
|
specification_version: 4
|
214
242
|
summary: logging to file and standard output.
|
215
243
|
test_files: []
|
216
|
-
has_rdoc:
|