tee_logger 3.1.2 → 3.2.0
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 +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +0 -0
- data/CHANGELOG.md +4 -0
- data/README.md +106 -84
- data/lib/tee_logger.rb +42 -31
- data/lib/tee_logger/tee_logger_base.rb +2 -0
- data/lib/tee_logger/utils.rb +1 -1
- data/lib/tee_logger/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a90d6ef3ba88bed38455955c9e7e0654440d9e80
|
4
|
+
data.tar.gz: d99ccca31c41af678fe5111be644decb3e783a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc81f3c5491f42351e90abb301bfc8821238fc237a843f483e29b42f5500464b1682569285bc943db7ba441ce80449e127380dfcf29ad89f881f18be3e6c974
|
7
|
+
data.tar.gz: c6a2a450f5284eea3b19ddd5e71292b1816b5337d1dd3343733b5eb9db580d6c58760357ec5b9d49201bdd7222fd49fe55655b4a9c7a74508f4c35b3ac682aa1
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
File without changes
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
[![Gem Version]
|
2
|
-
[![Build Status]
|
3
|
-
[![Code Climate]
|
4
|
-
[![Test Coverage]
|
5
|
-
[![Inline docs]
|
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]
|
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
|
-
#
|
103
|
-
tl.
|
104
|
-
tl.info
|
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
|
-
|
110
|
-
tl.
|
111
|
-
tl.
|
88
|
+
# disable logfile output
|
89
|
+
tl.disable(:logfile)
|
90
|
+
tl.info 'this message is consle only'
|
112
91
|
|
113
|
-
|
114
|
-
tl.
|
92
|
+
# enable logfile output
|
93
|
+
tl.enable(:logfile)
|
94
|
+
tl.info 'this message is logfile and console'
|
115
95
|
|
116
|
-
|
117
|
-
tl.
|
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
|
-
|
129
|
+
class YourAwesomeClass
|
130
|
+
include TeeLogger
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
138
|
+
module YourAwesomeModule
|
139
|
+
extend TeeLogger
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
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
|
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
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/lib/tee_logger/utils.rb
CHANGED
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.
|
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
|
+
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.
|
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.
|