tee_logger 2.4.0 → 2.4.1
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/CHANGELOG.md +4 -0
- data/README.md +112 -106
- data/lib/tee_logger/constants.rb +10 -10
- data/lib/tee_logger/version.rb +5 -5
- data/lib/tee_logger.rb +122 -121
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e038d2637ea600e0ee63ecff7d2be02d8692658b
|
4
|
+
data.tar.gz: 347e52f9ddd2ef5c76a4320951867d409062b368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553e57ad94ea5cff19078c08d4b414a1df6d045d720a10743c9c1dbb15961d55cc00e2ab49dff9d02079e3b7a2253961166ad3753f8f44c060716bd4314b732f
|
7
|
+
data.tar.gz: 67aca467869d1aeef54ab6f225de2cb0a08d4d8e33307f48e75d75145b191ebfeb577d4b121df7b2b04452b796c2acbd3ffab1ae1ce3285c507f62188e356cdc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,106 +1,112 @@
|
|
1
|
-
[](http://badge.fury.io/rb/tee_logger)
|
2
|
-
[](https://travis-ci.org/k-ta-yamada/tee_logger)
|
3
|
-
[](https://codeclimate.com/github/k-ta-yamada/tee_logger)
|
4
|
-
[](https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage)
|
5
|
-
|
6
|
-
> Sorry, I changed Usage from version 2.0.0
|
7
|
-
|
8
|
-
- [Rubygems.org](https://rubygems.org/gems/tee_logger)
|
9
|
-
- [GitHub](https://github.com/k-ta-yamada/tee_logger)
|
10
|
-
- [RubyDoc.info](http://www.rubydoc.info/gems/tee_logger)
|
11
|
-
|
12
|
-
# TeeLogger
|
13
|
-
|
14
|
-
logging to file and standard output.
|
15
|
-
require standard library only.
|
16
|
-
|
17
|
-
|
18
|
-
## Characteristic
|
19
|
-
|
20
|
-
- simple: use standard lib only.
|
21
|
-
- like Logger: see usage.
|
22
|
-
- enabled or disabled by switching the output of the console and the logfile.
|
23
|
-
|
24
|
-
|
25
|
-
## Installation
|
26
|
-
|
27
|
-
Add this line to your application's Gemfile:
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
gem 'tee_logger'
|
31
|
-
```
|
32
|
-
|
33
|
-
And then execute:
|
34
|
-
|
35
|
-
$ bundle
|
36
|
-
|
37
|
-
Or install it yourself as:
|
38
|
-
|
39
|
-
$ gem install tee_logger
|
40
|
-
|
41
|
-
|
42
|
-
## Usage
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
require 'tee_logger'
|
46
|
-
|
47
|
-
# Logger.new like options(logdev, shift_age, shift_size)
|
48
|
-
# options default value is
|
49
|
-
# logdev = './tee_logger.log'
|
50
|
-
# shift_age = 0
|
51
|
-
# shift_size = 1_048_576
|
52
|
-
tl = TeeLogger.new
|
53
|
-
|
54
|
-
# let's logging
|
55
|
-
tl.debug 'hello'
|
56
|
-
tl.debug(:progname) { 'hello world' }
|
57
|
-
tl.progname = 'App'
|
58
|
-
tl.debug 'hello tee_logger'
|
59
|
-
|
60
|
-
# disable console output
|
61
|
-
tl.disable(:console)
|
62
|
-
tl.info 'this message is logfile only'
|
63
|
-
|
64
|
-
# enable console output
|
65
|
-
tl.enable(:console)
|
66
|
-
tl.info 'this message is logfile and console'
|
67
|
-
|
68
|
-
# disable logfile output
|
69
|
-
tl.disable(:logfile)
|
70
|
-
tl.info 'this message is consle only'
|
71
|
-
|
72
|
-
# enable logfile output
|
73
|
-
tl.enable(:logfile)
|
74
|
-
tl.info 'this message is logfile and console'
|
75
|
-
|
76
|
-
#
|
77
|
-
tl.
|
78
|
-
tl.info
|
79
|
-
|
80
|
-
tl.
|
81
|
-
|
82
|
-
|
83
|
-
tl.
|
84
|
-
tl.
|
85
|
-
tl.
|
86
|
-
|
87
|
-
tl.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
1
|
+
[](http://badge.fury.io/rb/tee_logger)
|
2
|
+
[](https://travis-ci.org/k-ta-yamada/tee_logger)
|
3
|
+
[](https://codeclimate.com/github/k-ta-yamada/tee_logger)
|
4
|
+
[](https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage)
|
5
|
+
|
6
|
+
> Sorry, I changed Usage from version 2.0.0
|
7
|
+
|
8
|
+
- [Rubygems.org](https://rubygems.org/gems/tee_logger)
|
9
|
+
- [GitHub](https://github.com/k-ta-yamada/tee_logger)
|
10
|
+
- [RubyDoc.info](http://www.rubydoc.info/gems/tee_logger)
|
11
|
+
|
12
|
+
# TeeLogger
|
13
|
+
|
14
|
+
logging to file and standard output.
|
15
|
+
require standard library only.
|
16
|
+
|
17
|
+
|
18
|
+
## Characteristic
|
19
|
+
|
20
|
+
- simple: use standard lib only.
|
21
|
+
- like Logger: see usage.
|
22
|
+
- enabled or disabled by switching the output of the console and the logfile.
|
23
|
+
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'tee_logger'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install tee_logger
|
40
|
+
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'tee_logger'
|
46
|
+
|
47
|
+
# Logger.new like options(logdev, shift_age, shift_size)
|
48
|
+
# options default value is
|
49
|
+
# logdev = './tee_logger.log'
|
50
|
+
# shift_age = 0
|
51
|
+
# shift_size = 1_048_576
|
52
|
+
tl = TeeLogger.new
|
53
|
+
|
54
|
+
# let's logging
|
55
|
+
tl.debug 'hello'
|
56
|
+
tl.debug(:progname) { 'hello world' }
|
57
|
+
tl.progname = 'App'
|
58
|
+
tl.debug 'hello tee_logger'
|
59
|
+
|
60
|
+
# disable console output
|
61
|
+
tl.disable(:console)
|
62
|
+
tl.info 'this message is logfile only'
|
63
|
+
|
64
|
+
# enable console output
|
65
|
+
tl.enable(:console)
|
66
|
+
tl.info 'this message is logfile and console'
|
67
|
+
|
68
|
+
# disable logfile output
|
69
|
+
tl.disable(:logfile)
|
70
|
+
tl.info 'this message is consle only'
|
71
|
+
|
72
|
+
# enable logfile output
|
73
|
+
tl.enable(:logfile)
|
74
|
+
tl.info 'this message is logfile and console'
|
75
|
+
|
76
|
+
# disabe in block
|
77
|
+
tl.disable(:console) do
|
78
|
+
tl.info 'this message is logfile only'
|
79
|
+
end
|
80
|
+
tl.info 'this message is logfile and console'
|
81
|
+
|
82
|
+
# and others like Logger's
|
83
|
+
tl.debug? # => true
|
84
|
+
tl.info?
|
85
|
+
tl.warn?
|
86
|
+
tl.error?
|
87
|
+
tl.fatal?
|
88
|
+
|
89
|
+
tl.level # => 0
|
90
|
+
tl.level = Logger::INFO
|
91
|
+
tl.debug 'this message is not logging'
|
92
|
+
|
93
|
+
tl.formatter # => nil or Proc
|
94
|
+
tl.formatter = proc {|severity, datetime, progname, message| "#{severity}:#{message}" }
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
## Development
|
99
|
+
|
100
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
101
|
+
|
102
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
103
|
+
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/tee_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
108
|
+
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/tee_logger/constants.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
# namespace
|
4
|
-
module TeeLogger
|
5
|
-
# no param of filename, set this filename
|
6
|
-
DEFAULT_FILE = './tee_logger.log'
|
7
|
-
|
8
|
-
# Implements targets
|
9
|
-
LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
|
10
|
-
end
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# namespace
|
4
|
+
module TeeLogger
|
5
|
+
# no param of filename, set this filename
|
6
|
+
DEFAULT_FILE = './tee_logger.log'
|
7
|
+
|
8
|
+
# Implements targets
|
9
|
+
LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
|
10
|
+
end
|
data/lib/tee_logger/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# namespace
|
2
|
-
module TeeLogger
|
3
|
-
# version number
|
4
|
-
VERSION = '2.4.
|
5
|
-
end
|
1
|
+
# namespace
|
2
|
+
module TeeLogger
|
3
|
+
# version number
|
4
|
+
VERSION = '2.4.1'
|
5
|
+
end
|
data/lib/tee_logger.rb
CHANGED
@@ -1,121 +1,122 @@
|
|
1
|
-
require 'tee_logger/version'
|
2
|
-
require 'tee_logger/constants'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
# namespace
|
6
|
-
module TeeLogger
|
7
|
-
# shortcut for TeeLogger::TeeLogger.new
|
8
|
-
# @see TeeLogger
|
9
|
-
def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
|
10
|
-
TeeLogger.new(logdev, shift_age, shift_size)
|
11
|
-
end
|
12
|
-
|
13
|
-
# main
|
14
|
-
# @see http://www.rubydoc.info/stdlib/logger/Logger Logger
|
15
|
-
class TeeLogger
|
16
|
-
# @param logdev String
|
17
|
-
# @param shift_age Integer
|
18
|
-
# @param shift_size Integer
|
19
|
-
# @see Logger#initialize
|
20
|
-
def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
|
21
|
-
@logfile = Logger.new(logdev, shift_age, shift_size)
|
22
|
-
@console = Logger.new($stdout)
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
private
|
27
|
-
|
28
|
-
# @!macro [attach] loglevel_check_methods
|
29
|
-
# @!method $1(name)
|
30
|
-
# @return [Boolean]
|
31
|
-
def define_loglevel_check_methods(name)
|
32
|
-
define_method(name) do
|
33
|
-
@logfile.send(name)
|
34
|
-
@console.send(name)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# @!macro [attach] logging_methods
|
39
|
-
# @!method $1(progname = nil, &block)
|
40
|
-
# logging $1 level message.
|
41
|
-
# @return true
|
42
|
-
def define_logging_methods(name)
|
43
|
-
define_method(name) do |progname = nil, &block|
|
44
|
-
@logfile.send(name, progname, &block)
|
45
|
-
@console.send(name, progname, &block)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
define_loglevel_check_methods :debug?
|
51
|
-
define_loglevel_check_methods :info?
|
52
|
-
define_loglevel_check_methods :warn?
|
53
|
-
define_loglevel_check_methods :error?
|
54
|
-
define_loglevel_check_methods :fatal?
|
55
|
-
|
56
|
-
define_logging_methods :debug
|
57
|
-
define_logging_methods :info
|
58
|
-
define_logging_methods :warn
|
59
|
-
define_logging_methods :error
|
60
|
-
define_logging_methods :fatal
|
61
|
-
|
62
|
-
# TODO: which value?
|
63
|
-
# @return [Integer]
|
64
|
-
def level
|
65
|
-
@logfile.level
|
66
|
-
@console.level
|
67
|
-
end
|
68
|
-
|
69
|
-
# @param level [Integer]
|
70
|
-
def level=(level)
|
71
|
-
@logfile.level = level
|
72
|
-
@console.level = level
|
73
|
-
end
|
74
|
-
alias_method :sev_threshold, :level
|
75
|
-
alias_method :sev_threshold=, :level=
|
76
|
-
|
77
|
-
# TODO: both values?
|
78
|
-
# @return [String]
|
79
|
-
def progname
|
80
|
-
@logfile.progname
|
81
|
-
@console.progname
|
82
|
-
end
|
83
|
-
|
84
|
-
# @param name [String, Symbol]
|
85
|
-
def progname=(name = nil)
|
86
|
-
@logfile.progname = name
|
87
|
-
@console.progname = name
|
88
|
-
end
|
89
|
-
|
90
|
-
# TODO: both values?
|
91
|
-
# @return [String]
|
92
|
-
def formatter
|
93
|
-
@logfile.formatter
|
94
|
-
@console.formatter
|
95
|
-
end
|
96
|
-
|
97
|
-
# @param formatter
|
98
|
-
def formatter=(formatter)
|
99
|
-
@logfile.formatter = formatter
|
100
|
-
@console.formatter = formatter
|
101
|
-
end
|
102
|
-
|
103
|
-
# @todo Too miscellaneous
|
104
|
-
# @param target [String, Symbol]
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
# @
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
1
|
+
require 'tee_logger/version'
|
2
|
+
require 'tee_logger/constants'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
# namespace
|
6
|
+
module TeeLogger
|
7
|
+
# shortcut for TeeLogger::TeeLogger.new
|
8
|
+
# @see TeeLogger
|
9
|
+
def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
|
10
|
+
TeeLogger.new(logdev, shift_age, shift_size)
|
11
|
+
end
|
12
|
+
|
13
|
+
# main
|
14
|
+
# @see http://www.rubydoc.info/stdlib/logger/Logger Logger
|
15
|
+
class TeeLogger
|
16
|
+
# @param logdev String
|
17
|
+
# @param shift_age Integer
|
18
|
+
# @param shift_size Integer
|
19
|
+
# @see Logger#initialize
|
20
|
+
def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
|
21
|
+
@logfile = Logger.new(logdev, shift_age, shift_size)
|
22
|
+
@console = Logger.new($stdout)
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
private
|
27
|
+
|
28
|
+
# @!macro [attach] loglevel_check_methods
|
29
|
+
# @!method $1(name)
|
30
|
+
# @return [Boolean]
|
31
|
+
def define_loglevel_check_methods(name)
|
32
|
+
define_method(name) do
|
33
|
+
@logfile.send(name)
|
34
|
+
@console.send(name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @!macro [attach] logging_methods
|
39
|
+
# @!method $1(progname = nil, &block)
|
40
|
+
# logging $1 level message.
|
41
|
+
# @return true
|
42
|
+
def define_logging_methods(name)
|
43
|
+
define_method(name) do |progname = nil, &block|
|
44
|
+
@logfile.send(name, progname, &block)
|
45
|
+
@console.send(name, progname, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
define_loglevel_check_methods :debug?
|
51
|
+
define_loglevel_check_methods :info?
|
52
|
+
define_loglevel_check_methods :warn?
|
53
|
+
define_loglevel_check_methods :error?
|
54
|
+
define_loglevel_check_methods :fatal?
|
55
|
+
|
56
|
+
define_logging_methods :debug
|
57
|
+
define_logging_methods :info
|
58
|
+
define_logging_methods :warn
|
59
|
+
define_logging_methods :error
|
60
|
+
define_logging_methods :fatal
|
61
|
+
|
62
|
+
# TODO: which value?
|
63
|
+
# @return [Integer]
|
64
|
+
def level
|
65
|
+
@logfile.level
|
66
|
+
@console.level
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param level [Integer]
|
70
|
+
def level=(level)
|
71
|
+
@logfile.level = level
|
72
|
+
@console.level = level
|
73
|
+
end
|
74
|
+
alias_method :sev_threshold, :level
|
75
|
+
alias_method :sev_threshold=, :level=
|
76
|
+
|
77
|
+
# TODO: both values?
|
78
|
+
# @return [String]
|
79
|
+
def progname
|
80
|
+
@logfile.progname
|
81
|
+
@console.progname
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param name [String, Symbol]
|
85
|
+
def progname=(name = nil)
|
86
|
+
@logfile.progname = name
|
87
|
+
@console.progname = name
|
88
|
+
end
|
89
|
+
|
90
|
+
# TODO: both values?
|
91
|
+
# @return [String]
|
92
|
+
def formatter
|
93
|
+
@logfile.formatter
|
94
|
+
@console.formatter
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param formatter
|
98
|
+
def formatter=(formatter)
|
99
|
+
@logfile.formatter = formatter
|
100
|
+
@console.formatter = formatter
|
101
|
+
end
|
102
|
+
|
103
|
+
# @todo Too miscellaneous
|
104
|
+
# @param target [String, Symbol]
|
105
|
+
# @yield before target disable, after target enable.
|
106
|
+
def disable(target)
|
107
|
+
if block_given?
|
108
|
+
disable(target)
|
109
|
+
yield
|
110
|
+
enable(target)
|
111
|
+
else
|
112
|
+
instance_variable_get("@#{target}").formatter = proc { |_, _, _, _| '' }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# @todo Too miscellaneous
|
117
|
+
# @param target [String, Symbol]
|
118
|
+
def enable(target)
|
119
|
+
instance_variable_get("@#{target}").formatter = Logger::Formatter.new
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|