tee_logger 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +131 -75
- data/lib/tee_logger.rb +7 -19
- data/lib/tee_logger/configuration.rb +40 -0
- data/lib/tee_logger/tee_logger_base.rb +2 -2
- data/lib/tee_logger/utils.rb +0 -2
- data/lib/tee_logger/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9698a06d0147a9728b46a704c455ac4bbb72b0ee
|
4
|
+
data.tar.gz: 909f2f8b60a04dc98fa19bad8085650f9bd2a0ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9df0fcc964c6f734a52936aacb66650575de2475e4a54805199c6772a41037ad0c4617c3455e85b3a35697f3adac7e7baa6c51e9f2f8b0a8ef9461f3189464c
|
7
|
+
data.tar.gz: 1e330f7fa8e445ee507c9604d1dd2b8d7c07dd3294537aed936abdf44c0e495b566bd2df5ada856acf61902ced1768035cb1f8b3b43830db2ad9be35ea1f0c48
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -47,102 +47,158 @@ $ gem install tee_logger
|
|
47
47
|
|
48
48
|
## Usage
|
49
49
|
|
50
|
+
### let's logging
|
50
51
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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'
|
52
|
+
require 'tee_logger'
|
53
|
+
|
54
|
+
# Logger.new like options(logdev, shift_age, shift_size)
|
55
|
+
# options default value is
|
56
|
+
# logdev = './tee_logger.log'
|
57
|
+
# shift_age = 0
|
58
|
+
# shift_size = 1_048_576
|
59
|
+
tl = TeeLogger.new
|
60
|
+
|
61
|
+
tl.debug 'hello'
|
62
|
+
tl.debug(:progname) { 'hello world' }
|
63
|
+
tl.progname = 'App'
|
64
|
+
tl.debug 'hello tee_logger'
|
65
|
+
```
|
83
66
|
|
84
|
-
|
85
|
-
|
86
|
-
|
67
|
+
### enable only when specified
|
68
|
+
```ruby
|
69
|
+
tl.info 'this message is console and logfile'
|
70
|
+
tl.info 'this message is console only', :console
|
71
|
+
tl.info 'this message is logfile only', :logfile
|
72
|
+
```
|
87
73
|
|
88
|
-
|
89
|
-
|
90
|
-
|
74
|
+
### log meassage indent
|
75
|
+
```ruby
|
76
|
+
tl.info 'hello' # => 'hello'
|
77
|
+
tl.info 'hello', 0 # => 'hello'
|
78
|
+
tl.info 'hello', 2 # => ' hello'
|
79
|
+
```
|
91
80
|
|
92
|
-
|
93
|
-
|
94
|
-
|
81
|
+
### enabling and indent
|
82
|
+
```ruby
|
83
|
+
tl.info 'this message is console only', 2, :console
|
84
|
+
tl.info 'this message is console only', :console, 2
|
85
|
+
```
|
95
86
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
87
|
+
### disable console output
|
88
|
+
```ruby
|
89
|
+
tl.disable(:console)
|
90
|
+
tl.info 'this message is logfile only'
|
91
|
+
```
|
101
92
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
tl.fatal? # => true
|
93
|
+
### enable console output
|
94
|
+
```ruby
|
95
|
+
tl.enable(:console)
|
96
|
+
tl.info 'this message is logfile and console'
|
97
|
+
```
|
108
98
|
|
109
|
-
|
110
|
-
|
111
|
-
|
99
|
+
### disable logfile output
|
100
|
+
```ruby
|
101
|
+
tl.disable(:logfile)
|
102
|
+
tl.info 'this message is consle only'
|
103
|
+
```
|
112
104
|
|
113
|
-
|
114
|
-
|
115
|
-
|
105
|
+
### enable logfile output
|
106
|
+
```ruby
|
107
|
+
tl.enable(:logfile)
|
108
|
+
tl.info 'this message is logfile and console'
|
109
|
+
```
|
116
110
|
|
117
|
-
|
118
|
-
|
111
|
+
### disable in block
|
112
|
+
```ruby
|
113
|
+
tl.disable(:console) do
|
114
|
+
tl.info 'this message is logfile only'
|
115
|
+
end
|
116
|
+
tl.info 'this message is logfile and console'
|
117
|
+
```
|
118
|
+
|
119
|
+
### and others like Logger's
|
120
|
+
```ruby
|
121
|
+
# log_level
|
122
|
+
tl.debug? # => true
|
123
|
+
tl.info? # => true
|
124
|
+
tl.warn? # => true
|
125
|
+
tl.error? # => true
|
126
|
+
tl.fatal? # => true
|
127
|
+
|
128
|
+
tl.level # => 0
|
129
|
+
tl.level = Logger::INFO
|
130
|
+
tl.debug 'this message is not logging'
|
131
|
+
|
132
|
+
# formatter
|
133
|
+
tl.formatter # => nil or Proc
|
134
|
+
tl.formatter =
|
135
|
+
proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
|
136
|
+
|
137
|
+
# datetime_formatter
|
138
|
+
tl.datetime_format # => nil or Proc
|
139
|
+
tl.datetime_format = '%Y%m%d %H%M%S '
|
119
140
|
```
|
120
141
|
|
121
142
|
|
122
|
-
## include or extend TeeLogger
|
143
|
+
## include or extend TeeLogger
|
144
|
+
|
145
|
+
> the log file will be in default of `./tee_logger.log`
|
146
|
+
|
147
|
+
### for casual use
|
148
|
+
```ruby
|
149
|
+
require 'tee_logger'
|
150
|
+
|
151
|
+
class YourAwesomeClass
|
152
|
+
# define method #logger for your class.
|
153
|
+
# log file will be in default of `./tee_logger.log`
|
154
|
+
include TeeLogger
|
155
|
+
|
156
|
+
def awesome_method
|
157
|
+
logger.info 'this is message is logging and disp console'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
module YourAwesomeModule
|
162
|
+
# define singleton method .logger for your module.
|
163
|
+
# log file will be in default of `./tee_logger.log`
|
164
|
+
extend TeeLogger
|
123
165
|
|
124
|
-
|
166
|
+
def self.awesome_method
|
167
|
+
logger.info 'this is message is logging and disp console'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
```
|
125
171
|
|
172
|
+
### logfile name setting
|
126
173
|
```ruby
|
127
|
-
|
174
|
+
require 'tee_logger'
|
128
175
|
|
129
|
-
|
130
|
-
|
176
|
+
# Before extend or include the module, allow the setting of logdev
|
177
|
+
# sorry, `TeeLogger.logev` is deprecate.
|
178
|
+
# TeeLogger.logdev = 'log1.log'
|
179
|
+
TeeLogger.configure do |config|
|
180
|
+
config.logdev = 'log1.log'
|
181
|
+
end
|
131
182
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
183
|
+
class YourAwesomeClass
|
184
|
+
include TeeLogger
|
185
|
+
|
186
|
+
def awesome_method
|
187
|
+
logger.info 'this message is output `log1.log`'
|
136
188
|
end
|
189
|
+
end
|
137
190
|
|
138
|
-
|
139
|
-
|
191
|
+
# Before extend or include the module, allow the setting of logdev
|
192
|
+
# sorry, `TeeLogger.logev` is deprecate.
|
193
|
+
TeeLogger.logdev = 'log2.log'
|
194
|
+
module YourAwesomeModule
|
195
|
+
extend TeeLogger
|
140
196
|
|
141
|
-
|
142
|
-
|
143
|
-
logger.info 'this is message is logging and disp console'
|
144
|
-
end
|
197
|
+
def self.awesome_method
|
198
|
+
logger.info 'this message is output `log2.log`'
|
145
199
|
end
|
200
|
+
end
|
201
|
+
|
146
202
|
```
|
147
203
|
|
148
204
|
|
data/lib/tee_logger.rb
CHANGED
@@ -1,42 +1,30 @@
|
|
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 =
|
27
|
+
@logger = TeeLogger.new
|
40
28
|
@logger.progname = mod
|
41
29
|
@logger
|
42
30
|
end
|
@@ -48,7 +36,7 @@ module TeeLogger
|
|
48
36
|
klass.class_eval do
|
49
37
|
define_method(:logger) do
|
50
38
|
return @logger if @logger
|
51
|
-
@logger =
|
39
|
+
@logger = TeeLogger.new
|
52
40
|
@logger.progname = klass.name
|
53
41
|
@logger
|
54
42
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# namespace
|
2
|
+
module TeeLogger
|
3
|
+
# configuration
|
4
|
+
module Configration
|
5
|
+
Configration = Struct.new(:logdev)
|
6
|
+
|
7
|
+
# Yields the global configuration to a block.
|
8
|
+
# @yield [Configuration] global configuration
|
9
|
+
def configure
|
10
|
+
yield configuration if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
# reset configuration
|
14
|
+
def configuration_reset
|
15
|
+
@configuration = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# set TeeLogger::Configuration::Configration's member :logdev.
|
19
|
+
# extend or include TeeLogger then, :logdev is default argument
|
20
|
+
# for Logger.new(logdev).
|
21
|
+
# @param logdev [String, File]
|
22
|
+
def logdev=(logdev)
|
23
|
+
configuration.logdev = logdev
|
24
|
+
end
|
25
|
+
|
26
|
+
extend Gem::Deprecate
|
27
|
+
deprecate :logdev=, 'TeeLogger.configure', 2016, 1
|
28
|
+
|
29
|
+
# @return [String, File] `configuration.logdev` or `DEFAULT_FILE`.
|
30
|
+
def logdev
|
31
|
+
configuration.logdev || DEFAULT_FILE
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def configuration
|
37
|
+
@configuration ||= Configration.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -43,9 +43,9 @@ module TeeLogger
|
|
43
43
|
# @param shift_age [Integer]
|
44
44
|
# @param shift_size [Integer]
|
45
45
|
# @see Logger#initialize
|
46
|
-
def initialize(logdev =
|
46
|
+
def initialize(logdev = nil, shift_age = 0, shift_size = 1_048_576)
|
47
47
|
@console = Logger.new($stdout)
|
48
|
-
@logfile = Logger.new(logdev, shift_age, shift_size)
|
48
|
+
@logfile = Logger.new(logdev || TeeLogger.logdev, shift_age, shift_size)
|
49
49
|
|
50
50
|
@level, @progname, @formatter, @datetime_format = nil
|
51
51
|
end
|
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.2.
|
4
|
+
version: 3.2.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:
|
11
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- README.md
|
184
184
|
- Rakefile
|
185
185
|
- lib/tee_logger.rb
|
186
|
+
- lib/tee_logger/configuration.rb
|
186
187
|
- lib/tee_logger/constants.rb
|
187
188
|
- lib/tee_logger/tee_logger_base.rb
|
188
189
|
- lib/tee_logger/utils.rb
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.5.1
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: logging to file and standard output.
|