tee_logger 2.7.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbdb5ccee15e5eed47f3e89efbaac90990ce39f2
4
- data.tar.gz: 152388538388e14fa2acc29cc3e0daab42a00419
3
+ metadata.gz: fac48b2aa959b362ac7fa364c0a343a2f1588616
4
+ data.tar.gz: d14d1e2b0458879b5ddcbd11ae59a9514d29c2e5
5
5
  SHA512:
6
- metadata.gz: bd286237550da02a4a6db31bfdc2f9870f9397faa894abe9100a218ae542722430dae565c3cee70fa2f5a807f94d11d9ec1f77a12b9bfeabe5bce4381c68d1eb
7
- data.tar.gz: 2da99911ebf7d6f02143df8d12b4160f9877a9572f9fd2b70fb5f7b7937e2e27d99f5383bc7e4168f0d436c0616bdcac8b22b959c15639fa33657459b604fbce
6
+ metadata.gz: 61e4ff27817c8717f338f38a01500c08041a32dbb0243d40c1dc2211be28b4f8638f38b692c9cd3d9ee0747129b1b8b2d59950b1522afebf24b887e0c042fe40
7
+ data.tar.gz: fda1d7ffb55beeecc1bca0241005a40d59adabdc92e1116dcc3939465e1f8959d89ab8ea695dfcde102c53183bcda096ba97d0806ddf3ab0f63df1614fcdce16
data/.gitignore CHANGED
@@ -1,57 +1,57 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- /vendor
12
- tee_logger.log
13
-
14
- ### https://raw.github.com/github/gitignore/d7161533f13c64dd677d367be369f4e900f5b4ea/Global/OSX.gitignore
15
-
16
- .DS_Store
17
- .AppleDouble
18
- .LSOverride
19
-
20
- # Icon must end with two \r
21
- Icon
22
-
23
- # Thumbnails
24
- ._*
25
-
26
- # Files that might appear on external disk
27
- .Spotlight-V100
28
- .Trashes
29
-
30
- # Directories potentially created on remote AFP share
31
- .AppleDB
32
- .AppleDesktop
33
- Network Trash Folder
34
- Temporary Items
35
- .apdisk
36
-
37
-
38
- ### https://raw.github.com/github/gitignore/d7161533f13c64dd677d367be369f4e900f5b4ea/Global/Windows.gitignore
39
-
40
- # Windows image file caches
41
- Thumbs.db
42
- ehthumbs.db
43
-
44
- # Folder config file
45
- Desktop.ini
46
-
47
- # Recycle Bin used on file shares
48
- $RECYCLE.BIN/
49
-
50
- # Windows Installer files
51
- *.cab
52
- *.msi
53
- *.msm
54
- *.msp
55
-
56
- # Windows shortcuts
57
- *.lnk
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ /vendor
12
+ tee_logger.log
13
+
14
+ ### https://raw.github.com/github/gitignore/d7161533f13c64dd677d367be369f4e900f5b4ea/Global/OSX.gitignore
15
+
16
+ .DS_Store
17
+ .AppleDouble
18
+ .LSOverride
19
+
20
+ # Icon must end with two \r
21
+ Icon
22
+
23
+ # Thumbnails
24
+ ._*
25
+
26
+ # Files that might appear on external disk
27
+ .Spotlight-V100
28
+ .Trashes
29
+
30
+ # Directories potentially created on remote AFP share
31
+ .AppleDB
32
+ .AppleDesktop
33
+ Network Trash Folder
34
+ Temporary Items
35
+ .apdisk
36
+
37
+
38
+ ### https://raw.github.com/github/gitignore/d7161533f13c64dd677d367be369f4e900f5b4ea/Global/Windows.gitignore
39
+
40
+ # Windows image file caches
41
+ Thumbs.db
42
+ ehthumbs.db
43
+
44
+ # Folder config file
45
+ Desktop.ini
46
+
47
+ # Recycle Bin used on file shares
48
+ $RECYCLE.BIN/
49
+
50
+ # Windows Installer files
51
+ *.cab
52
+ *.msi
53
+ *.msm
54
+ *.msp
55
+
56
+ # Windows shortcuts
57
+ *.lnk
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --format documentation
1
+ --color
2
+ --format documentation
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
- language: ruby
2
- rvm:
3
- - ruby-head
4
- - 2.2.2
5
- - 2.1.5
6
- - 2.0.0
7
- before_install: gem install bundler -v 1.10.4
8
- notifications:
9
- slack:
10
- secure: zCs6tIIMRaugSasz857bnfcHywMZvz2nztcTJdkvi25kZFysakVgVJ+CNBRZSHjShsnBD1H1i3ywoECKPHUiLlUDQU4ncZQoSS0qM5CcmVlE0JOHzcvY2POTadZWfVn2XvRcCcoI2k7Oy9cS+xFmbs3PP2TqbVfPStB+l9jD+QejWinpLJR05PGi8M2iqZKjxAwJ9TBoLvmHt7UtXMq6edG/Q+SVOUQMEEkLCaWzSvNQYnDiTk1ewkXF0kG5jtVx/OKjQC62ioQIBz6+I6aMfOil2MCpb8u37asXQeML/rMPfBxVuwvBSwGKpRBrJSUG5XeoWg8bbri0WUOrOGCg3LVRtdiHyUNcAYObaB69+YqFOt/F05Dgg6+9Rs53mgZM2zuvsFp2qeSD27wXCy0ZJhFyMv5YJA5paJZjOAH0ki9FWeZjC4XMasntvO7/83rCEFcqGusMckLKcKE/RdEYurzqLruF2W4FGSAvSTbARjQbtYMxmuh1xJrH4KCdCYDvoxYb4xJrGo+q77j+wnpzGBwf8nak2VcGgN6wXadeosNR31WGW+HBwv8LxTJutlXzDjBTyK2ZcaaIZASbF3liEH294ycdf9YcGlxZYxuauPsg0EXa8C0NHXkfL9Zb1CftEgULXvtBL/qNDr/cyhHWbSYZcJw5DfQYt6inBKudmEU=
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 2.2.2
5
+ - 2.1.5
6
+ - 2.0.0
7
+ before_install: gem install bundler -v 1.10.4
8
+ notifications:
9
+ slack:
10
+ secure: zCs6tIIMRaugSasz857bnfcHywMZvz2nztcTJdkvi25kZFysakVgVJ+CNBRZSHjShsnBD1H1i3ywoECKPHUiLlUDQU4ncZQoSS0qM5CcmVlE0JOHzcvY2POTadZWfVn2XvRcCcoI2k7Oy9cS+xFmbs3PP2TqbVfPStB+l9jD+QejWinpLJR05PGi8M2iqZKjxAwJ9TBoLvmHt7UtXMq6edG/Q+SVOUQMEEkLCaWzSvNQYnDiTk1ewkXF0kG5jtVx/OKjQC62ioQIBz6+I6aMfOil2MCpb8u37asXQeML/rMPfBxVuwvBSwGKpRBrJSUG5XeoWg8bbri0WUOrOGCg3LVRtdiHyUNcAYObaB69+YqFOt/F05Dgg6+9Rs53mgZM2zuvsFp2qeSD27wXCy0ZJhFyMv5YJA5paJZjOAH0ki9FWeZjC4XMasntvO7/83rCEFcqGusMckLKcKE/RdEYurzqLruF2W4FGSAvSTbARjQbtYMxmuh1xJrH4KCdCYDvoxYb4xJrGo+q77j+wnpzGBwf8nak2VcGgN6wXadeosNR31WGW+HBwv8LxTJutlXzDjBTyK2ZcaaIZASbF3liEH294ycdf9YcGlxZYxuauPsg0EXa8C0NHXkfL9Zb1CftEgULXvtBL/qNDr/cyhHWbSYZcJw5DfQYt6inBKudmEU=
data/CHANGELOG.md CHANGED
@@ -1,53 +1,59 @@
1
- # v2.7.0
2
- - add datetime_format, datetime_format=
3
-
4
- # v2.6.0
5
- - disabling option add to logging_methods
6
-
7
- # v2.5.0
8
- - level, progname and formatter were changed to instance variable
9
- - refactoring: disabling and enabling
10
- - rm ./lib/tee_logger/constants.rb. Constants move to ./lib/tee_logger.rb
11
-
12
- # v2.4.1
13
- - update README.md
14
- - and YARD comment
15
-
16
- # v2.4.0
17
- - TeeLogger#disable is allow block given
18
-
19
- # v2.3.1
20
- - refactoring TeeLogger#disable
21
-
22
- # v2.3.0
23
- - remove TeeLogger.attr_reader
24
- - and rename instance variable: @logger => @logfile
25
- - implementation `#level` and `level=`
26
- - implementation `#formatter` and `formatter=`
27
-
28
- # v2.2.0
29
- - disabling and enabling
30
-
31
- # v2.1.1
32
- - refactoring of test case
33
- - Introduced capture_stdout
34
- - Introduced FakeFS
35
- - Change logdev of Console for Logger from STDOUT to $ stdout
36
-
37
- # v2.1.0
38
- - Integrate TeeLogger::Base class to TeeLogger::TeeLogger class
39
-
40
- # v2.0.2
41
- - bugfix
42
-
43
- # v2.0.1
44
- - bugfix
45
-
46
- # v2.0.0
47
- - Change to Class from Module
48
-
49
- # v1.1.0
50
- - bugfix
51
-
52
- # v1.0.0
53
- - first
1
+ # v3.0.0
2
+ - [issue #4](https://github.com/k-ta-yamada/tee_logger/issues/4)
3
+ logging method's parametrer disabling_target change to enabling_targe
4
+ - [issue #5](https://github.com/k-ta-yamada/tee_logger/issues/5)
5
+ log message indentation
6
+
7
+ # v2.7.0
8
+ - add datetime_format, datetime_format=
9
+
10
+ # v2.6.0
11
+ - disabling option add to logging_methods
12
+
13
+ # v2.5.0
14
+ - level, progname and formatter were changed to instance variable
15
+ - refactoring: disabling and enabling
16
+ - rm ./lib/tee_logger/constants.rb. Constants move to ./lib/tee_logger.rb
17
+
18
+ # v2.4.1
19
+ - update README.md
20
+ - and YARD comment
21
+
22
+ # v2.4.0
23
+ - TeeLogger#disable is allow block given
24
+
25
+ # v2.3.1
26
+ - refactoring TeeLogger#disable
27
+
28
+ # v2.3.0
29
+ - remove TeeLogger.attr_reader
30
+ - and rename instance variable: @logger => @logfile
31
+ - implementation `#level` and `level=`
32
+ - implementation `#formatter` and `formatter=`
33
+
34
+ # v2.2.0
35
+ - disabling and enabling
36
+
37
+ # v2.1.1
38
+ - refactoring of test case
39
+ - Introduced capture_stdout
40
+ - Introduced FakeFS
41
+ - Change logdev of Console for Logger from STDOUT to $ stdout
42
+
43
+ # v2.1.0
44
+ - Integrate TeeLogger::Base class to TeeLogger::TeeLogger class
45
+
46
+ # v2.0.2
47
+ - bugfix
48
+
49
+ # v2.0.1
50
+ - bugfix
51
+
52
+ # v2.0.0
53
+ - Change to Class from Module
54
+
55
+ # v1.1.0
56
+ - bugfix
57
+
58
+ # v1.0.0
59
+ - first
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,13 +1,13 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in tee_logger.gemspec
4
- gemspec
5
- gem 'codeclimate-test-reporter', group: :test, require: nil
6
- gem 'simplecov-console', group: :test, require: nil
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tee_logger.gemspec
4
+ gemspec
5
+ gem 'codeclimate-test-reporter', group: :test, require: nil
6
+ gem 'simplecov-console', group: :test, require: nil
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 k-ta-yamada
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 k-ta-yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,130 +1,145 @@
1
- [![Gem Version](https://badge.fury.io/rb/tee_logger.svg)](http://badge.fury.io/rb/tee_logger)
2
- [![Build Status](https://travis-ci.org/k-ta-yamada/tee_logger.svg)](https://travis-ci.org/k-ta-yamada/tee_logger)
3
- [![Code Climate](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger)
4
- [![Test Coverage](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg)](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 only when specified
61
- tl.info 'this message is logfile only', :console
62
- tl.info 'this message is console only', :logfile
63
-
64
- # disable console output
65
- tl.disable(:console)
66
- tl.info 'this message is logfile only'
67
-
68
- # enable console output
69
- tl.enable(:console)
70
- tl.info 'this message is logfile and console'
71
-
72
- # disable logfile output
73
- tl.disable(:logfile)
74
- tl.info 'this message is consle only'
75
-
76
- # enable logfile output
77
- tl.enable(:logfile)
78
- tl.info 'this message is logfile and console'
79
-
80
- # disabe in block
81
- tl.disable(:console) do
82
- tl.info 'this message is logfile only'
83
- end
84
- tl.info 'this message is logfile and console'
85
-
86
- # and others like Logger's
87
- tl.debug? # => true
88
- tl.info? # => true
89
- tl.warn? # => true
90
- tl.error? # => true
91
- tl.fatal? # => true
92
-
93
- tl.level # => 0
94
- tl.level = Logger::INFO
95
- tl.debug 'this message is not logging'
96
-
97
- tl.formatter # => nil or Proc
98
- tl.formatter = proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
99
-
100
- tl.datetime_format # => nil or Proc
101
- tl.datetime_format = '%Y%m%d %H%M%S '
102
- ```
103
-
104
-
105
- ## Development
106
-
107
- After checking out the repo, run `bundle install` to install dependencies.
108
- Then, run `rake rspec` to run the tests.
109
- You can also run `budle exec pry -r ./lib/tee_logger` for an interactive prompt
110
- that will allow you to experiment.
111
-
112
- To install this gem onto your local machine, run `bundle exec rake install`.
113
- To release a new version, update the version number in `version.rb`,
114
- and then run `bundle exec rake release`,
115
- which will create a git tag for the version,
116
- push git commits and tags,
117
- and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
-
119
-
120
- ## Contributing
121
-
122
- Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/tee_logger.
123
- This project is intended to be a safe,
124
- welcoming space for collaboration,
125
- and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
126
-
127
-
128
- ## License
129
-
130
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
1
+ [![Gem Version](https://badge.fury.io/rb/tee_logger.svg)](http://badge.fury.io/rb/tee_logger)
2
+ [![Build Status](https://travis-ci.org/k-ta-yamada/tee_logger.svg)](https://travis-ci.org/k-ta-yamada/tee_logger)
3
+ [![Code Climate](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/gpa.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger)
4
+ [![Test Coverage](https://codeclimate.com/github/k-ta-yamada/tee_logger/badges/coverage.svg)](https://codeclimate.com/github/k-ta-yamada/tee_logger/coverage)
5
+
6
+ > Sorry. In from version 2 to version 3, changed usage.
7
+ > see also [CHANGELOG.md](/CHANGELOG.md#v300).
8
+
9
+ - [Rubygems.org](https://rubygems.org/gems/tee_logger)
10
+ - [GitHub](https://github.com/k-ta-yamada/tee_logger)
11
+ - [RubyDoc.info](http://www.rubydoc.info/gems/tee_logger)
12
+
13
+ # TeeLogger
14
+
15
+ logging to file and standard output.
16
+ require standard library only.
17
+
18
+
19
+ ## Characteristic
20
+
21
+ - use standard lib only.
22
+ - like Logger: see usage.
23
+ - enabled or disabled by switching the output of the console and the logfile.
24
+
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```ruby
31
+ gem 'tee_logger'
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```
37
+ $ bundle
38
+ ```
39
+
40
+ Or install it yourself as:
41
+
42
+ ```
43
+ $ gem install tee_logger
44
+ ```
45
+
46
+
47
+ ## Usage
48
+
49
+ ```ruby
50
+ require 'tee_logger'
51
+
52
+ # Logger.new like options(logdev, shift_age, shift_size)
53
+ # options default value is
54
+ # logdev = './tee_logger.log'
55
+ # shift_age = 0
56
+ # shift_size = 1_048_576
57
+ tl = TeeLogger.new
58
+
59
+ # let's logging
60
+ tl.debug 'hello'
61
+ tl.debug(:progname) { 'hello world' }
62
+ tl.progname = 'App'
63
+ tl.debug 'hello tee_logger'
64
+
65
+ # enable only when specified
66
+ tl.info 'this message is console and logfile'
67
+ tl.info 'this message is console only', :console
68
+ tl.info 'this message is logfile only', :logfile
69
+
70
+ # log meassage indent
71
+ tl.info 'hello' # => 'hello'
72
+ tl.info 'hello', 0 # => 'hello'
73
+ tl.info 'hello', 2 # => ' hello'
74
+
75
+ # enabling and indent
76
+ tl.info 'this message is console only', 2, :console
77
+ tl.info 'this message is console only', :console, 2
78
+
79
+ # disable console output
80
+ tl.disable(:console)
81
+ tl.info 'this message is logfile only'
82
+
83
+ # enable console output
84
+ tl.enable(:console)
85
+ tl.info 'this message is logfile and console'
86
+
87
+ # disable logfile output
88
+ tl.disable(:logfile)
89
+ tl.info 'this message is consle only'
90
+
91
+ # enable logfile output
92
+ tl.enable(:logfile)
93
+ tl.info 'this message is logfile and console'
94
+
95
+ # disabe in block
96
+ tl.disable(:console) do
97
+ tl.info 'this message is logfile only'
98
+ end
99
+ tl.info 'this message is logfile and console'
100
+
101
+ # and others like Logger's
102
+ tl.debug? # => true
103
+ tl.info? # => true
104
+ tl.warn? # => true
105
+ tl.error? # => true
106
+ tl.fatal? # => true
107
+
108
+ tl.level # => 0
109
+ tl.level = Logger::INFO
110
+ tl.debug 'this message is not logging'
111
+
112
+ tl.formatter # => nil or Proc
113
+ tl.formatter = proc { |severity, datetime, progname, message| "#{severity}:#{message}" }
114
+
115
+ tl.datetime_format # => nil or Proc
116
+ tl.datetime_format = '%Y%m%d %H%M%S '
117
+ ```
118
+
119
+
120
+ ## Development
121
+
122
+ After checking out the repo, run `bundle install` to install dependencies.
123
+ Then, run `rake rspec` to run the tests.
124
+ You can also run `budle exec pry -r ./lib/tee_logger` for an interactive prompt
125
+ that will allow you to experiment.
126
+
127
+ To install this gem onto your local machine, run `bundle exec rake install`.
128
+ To release a new version, update the version number in `version.rb`,
129
+ and then run `bundle exec rake release`,
130
+ which will create a git tag for the version,
131
+ push git commits and tags,
132
+ and push the `.gem` file to [rubygems.org](https://rubygems.org).
133
+
134
+
135
+ ## Contributing
136
+
137
+ Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/tee_logger.
138
+ This project is intended to be a safe,
139
+ welcoming space for collaboration,
140
+ and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
141
+
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- RSpec::Core::RakeTask.new(:spec)
4
- task default: :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: :spec
data/lib/tee_logger.rb CHANGED
@@ -1,127 +1,132 @@
1
- require 'tee_logger/version'
2
- require 'logger'
3
-
4
- # namespace
5
- module TeeLogger
6
- # no param of filename, set this filename
7
- DEFAULT_FILE = './tee_logger.log'
8
- # Implements targets
9
- LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
10
-
11
- # shortcut for TeeLogger::TeeLogger.new
12
- # @see TeeLogger
13
- def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
14
- TeeLogger.new(logdev, shift_age, shift_size)
15
- end
16
-
17
- # main
18
- # @see http://www.rubydoc.info/stdlib/logger/Logger Logger
19
- class TeeLogger
20
- class << self
21
- # @!macro [attach] logging_methods
22
- # @!method $1(progname = nil, disabling_target = nil, &block)
23
- # logging $1 level message.
24
- # @param progname see also Logger
25
- # @param disabling_target (Symbol) valid values => [:console, :logfile]
26
- # @param &block see also Logger
27
- # @return true
28
- # @see Logger
29
- def define_logging_methods(name)
30
- define_method(name) do |progname = nil, disabling_target = nil, &block|
31
- if disabling_target
32
- disable(disabling_target) { logging(name, progname, &block) }
33
- else
34
- logging(name, progname, &block)
35
- end
36
- end
37
- end
38
- private :define_logging_methods
39
-
40
- # @!macro [attach] loglevel_check_methods
41
- # @!method $1(name)
42
- # @return [Boolean]
43
- def define_loglevel_check_methods(name)
44
- define_method(name) do
45
- @console.send(name)
46
- @logfile.send(name)
47
- end
48
- end
49
- private :define_loglevel_check_methods
50
- end
51
-
52
- attr_reader :level, :progname, :formatter, :datetime_format
53
-
54
- # @param logdev [String]
55
- # @param shift_age [Integer]
56
- # @param shift_size [Integer]
57
- # @see Logger#initialize
58
- def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
59
- @console = Logger.new($stdout)
60
- @logfile = Logger.new(logdev, shift_age, shift_size)
61
- end
62
-
63
- define_logging_methods :debug
64
- define_logging_methods :info
65
- define_logging_methods :warn
66
- define_logging_methods :error
67
- define_logging_methods :fatal
68
-
69
- define_loglevel_check_methods :debug?
70
- define_loglevel_check_methods :info?
71
- define_loglevel_check_methods :warn?
72
- define_loglevel_check_methods :error?
73
- define_loglevel_check_methods :fatal?
74
-
75
- # @param level [Integer]
76
- def level=(level)
77
- @console.level = @logfile.level = @level = level
78
- end
79
- alias_method :sev_threshold, :level
80
- alias_method :sev_threshold=, :level=
81
-
82
- # @param name [String, Symbol]
83
- def progname=(name = nil)
84
- @console.progname = @logfile.progname = @progname = name
85
- end
86
-
87
- # @param formatter
88
- def formatter=(formatter)
89
- @console.formatter = @logfile.formatter = @formatter = formatter
90
- end
91
-
92
- # @param formatter
93
- def datetime_format=(format)
94
- @console.datetime_format =
95
- @logfile.datetime_format =
96
- @datetime_format = format
97
- end
98
-
99
- # @param logdev_name [String, Symbol]
100
- # @yield before logdev_name disable, after logdev_name enable.
101
- def disable(logdev_name)
102
- if block_given?
103
- disable(logdev_name)
104
- yield
105
- enable(logdev_name)
106
- else
107
- logdev_instance(logdev_name).formatter = proc { |_, _, _, _| '' }
108
- end
109
- end
110
-
111
- # @param logdev_name [String, Symbol]
112
- def enable(logdev_name)
113
- logdev_instance(logdev_name).formatter = @formatter
114
- end
115
-
116
- private
117
-
118
- def logging(name, progname, &block)
119
- @console.send(name, progname, &block)
120
- @logfile.send(name, progname, &block)
121
- end
122
-
123
- def logdev_instance(logdev_name)
124
- instance_variable_get("@#{logdev_name}")
125
- end
126
- end
127
- end
1
+ require 'tee_logger/utils'
2
+ require 'tee_logger/version'
3
+ require 'logger'
4
+
5
+ # namespace
6
+ module TeeLogger
7
+ # no param of filename, set this filename
8
+ DEFAULT_FILE = './tee_logger.log'
9
+ # Implements targets
10
+ LOGGING_METHODS = [:debug, :info, :warn, :error, :fatal].freeze
11
+
12
+ # shortcut for TeeLogger::TeeLogger.new
13
+ # @see TeeLogger
14
+ def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
15
+ TeeLogger.new(logdev, shift_age, shift_size)
16
+ end
17
+
18
+ # main
19
+ # @see http://www.rubydoc.info/stdlib/logger/Logger Logger
20
+ class TeeLogger
21
+ class << self
22
+ # @!macro [attach] logging_methods
23
+ # @!method $1(progname = nil, disabling_target = nil, &block)
24
+ # logging $1 level message.
25
+ # @param progname see also Logger
26
+ # @param disabling_target (Symbol) valid values => [:console, :logfile]
27
+ # @param &block see also Logger
28
+ # @return true
29
+ # @see Logger
30
+ def define_logging_methods(name)
31
+ define_method(name) do |progname = nil, *options, &block|
32
+ opts = parse_to_hash_from(options)
33
+
34
+ disabling_target = reverse_target(opts[:enabling_target])
35
+ progname, block = indentation(progname, block, opts[:indent_level])
36
+
37
+ if disabling_target.nil?
38
+ logging(name, progname, &block)
39
+ else
40
+ disable(disabling_target) { logging(name, progname, &block) }
41
+ end
42
+ end
43
+ end
44
+ private :define_logging_methods
45
+
46
+ # @!macro [attach] loglevel_check_methods
47
+ # @!method $1(name)
48
+ # @return [Boolean]
49
+ def define_loglevel_check_methods(name)
50
+ define_method(name) do
51
+ @console.send(name)
52
+ @logfile.send(name)
53
+ end
54
+ end
55
+ private :define_loglevel_check_methods
56
+ end
57
+
58
+ include Utils
59
+ attr_reader :level, :progname, :formatter, :datetime_format
60
+
61
+ # @param logdev [String]
62
+ # @param shift_age [Integer]
63
+ # @param shift_size [Integer]
64
+ # @see Logger#initialize
65
+ def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
66
+ @console = Logger.new($stdout)
67
+ @logfile = Logger.new(logdev, shift_age, shift_size)
68
+ end
69
+
70
+ define_logging_methods :debug
71
+ define_logging_methods :info
72
+ define_logging_methods :warn
73
+ define_logging_methods :error
74
+ define_logging_methods :fatal
75
+
76
+ define_loglevel_check_methods :debug?
77
+ define_loglevel_check_methods :info?
78
+ define_loglevel_check_methods :warn?
79
+ define_loglevel_check_methods :error?
80
+ define_loglevel_check_methods :fatal?
81
+
82
+ # @param level [Integer]
83
+ def level=(level)
84
+ @console.level = @logfile.level = @level = level
85
+ end
86
+ alias_method :sev_threshold, :level
87
+ alias_method :sev_threshold=, :level=
88
+
89
+ # @param name [String, Symbol]
90
+ def progname=(name = nil)
91
+ @console.progname = @logfile.progname = @progname = name
92
+ end
93
+
94
+ # @param formatter
95
+ def formatter=(formatter)
96
+ @console.formatter = @logfile.formatter = @formatter = formatter
97
+ end
98
+
99
+ # @param formatter
100
+ def datetime_format=(format)
101
+ @console.datetime_format =
102
+ @logfile.datetime_format =
103
+ @datetime_format = format
104
+ end
105
+
106
+ # @param logdev_name [String, Symbol]
107
+ # @yield before logdev_name disable, after logdev_name enable.
108
+ def disable(logdev_name)
109
+ correct_name?(logdev_name)
110
+ if block_given?
111
+ disable(logdev_name)
112
+ yield
113
+ enable(logdev_name)
114
+ else
115
+ logdev_instance(logdev_name).formatter = proc { |_, _, _, _| '' }
116
+ end
117
+ end
118
+
119
+ # @param logdev_name [String, Symbol]
120
+ def enable(logdev_name)
121
+ correct_name?(logdev_name)
122
+ logdev_instance(logdev_name).formatter = @formatter
123
+ end
124
+
125
+ private
126
+
127
+ def logging(name, progname, &block)
128
+ @console.send(name, progname, &block)
129
+ @logfile.send(name, progname, &block)
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,64 @@
1
+ # namespace
2
+ module TeeLogger
3
+ # util
4
+ module Utils
5
+ class IncorrectNameError < StandardError; end
6
+
7
+ # defined log devices names
8
+ LOGDEVS = %i(console logfile)
9
+
10
+ private
11
+
12
+ def parse_to_hash_from(options)
13
+ result = { enabling_target: nil, indent_level: 0 }
14
+ options.each_with_object(result) do |val, obj|
15
+ if val.is_a?(Symbol)
16
+ correct_name?(val)
17
+ obj[:enabling_target] = LOGDEVS.include?(val) ? val : nil
18
+ elsif val.is_a?(Fixnum)
19
+ obj[:indent_level] = val
20
+ end
21
+ end
22
+ end
23
+
24
+ def reverse_target(logdev_name)
25
+ case logdev_name
26
+ when :console then :logfile
27
+ when :logfile then :console
28
+ end
29
+ end
30
+
31
+ def indentation(progname, block, indent_level)
32
+ if block.nil?
33
+ progname = "#{' ' * indent_level}#{formatting(progname)}"
34
+ else
35
+ result = block.call
36
+ block = proc { "#{' ' * indent_level}#{formatting(result)}" }
37
+ end
38
+ [progname, block]
39
+ end
40
+
41
+ def formatting(val)
42
+ if val.is_a?(Symbol)
43
+ ":#{val}"
44
+ elsif val.nil?
45
+ 'nil'
46
+ else
47
+ val
48
+ end
49
+ end
50
+
51
+ def correct_name?(logdev_name)
52
+ if LOGDEVS.include?(logdev_name)
53
+ true
54
+ else
55
+ fail IncorrectNameError,
56
+ "logdev_name=[:#{logdev_name}]:logdev_name is :console or :logfile"
57
+ end
58
+ end
59
+
60
+ def logdev_instance(logdev_name)
61
+ instance_variable_get("@#{logdev_name}")
62
+ end
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
- # namespace
2
- module TeeLogger
3
- # version number
4
- VERSION = '2.7.0'
5
- end
1
+ # namespace
2
+ module TeeLogger
3
+ # version number
4
+ VERSION = '3.0.0'
5
+ end
data/tee_logger.gemspec CHANGED
@@ -1,39 +1,39 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tee_logger/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'tee_logger'
8
- spec.version = TeeLogger::VERSION
9
- spec.authors = ['k-ta-yamada']
10
- spec.email = ['key.luvless@gmail.com']
11
-
12
- spec.summary = 'logging to file and standard output.'
13
- spec.description =
14
- 'logging to file and standard output. require standard library only.'
15
-
16
- spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
17
- spec.license = 'MIT'
18
-
19
- # rubocop:disable Metrics/LineLength
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
- # rubocop:enable Metrics/LineLength
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
- spec.require_paths = ['lib']
25
-
26
- spec.add_development_dependency 'bundler', '~> 1.10'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec'
29
- spec.add_development_dependency 'fuubar'
30
-
31
- spec.add_development_dependency 'pry'
32
- spec.add_development_dependency 'pry-doc'
33
- spec.add_development_dependency 'pry-theme'
34
- spec.add_development_dependency 'rubocop'
35
-
36
- spec.add_development_dependency 'capture_stdout'
37
- spec.add_development_dependency 'fakefs'
38
- spec.add_development_dependency 'parallel'
39
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tee_logger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tee_logger'
8
+ spec.version = TeeLogger::VERSION
9
+ spec.authors = ['k-ta-yamada']
10
+ spec.email = ['key.luvless@gmail.com']
11
+
12
+ spec.summary = 'logging to file and standard output.'
13
+ spec.description =
14
+ 'logging to file and standard output. require standard library only.'
15
+
16
+ spec.homepage = 'https://github.com/k-ta-yamada/tee_logger'
17
+ spec.license = 'MIT'
18
+
19
+ # rubocop:disable Metrics/LineLength
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ # rubocop:enable Metrics/LineLength
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'fuubar'
30
+
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'pry-doc'
33
+ spec.add_development_dependency 'pry-theme'
34
+ spec.add_development_dependency 'rubocop'
35
+
36
+ spec.add_development_dependency 'capture_stdout'
37
+ spec.add_development_dependency 'fakefs'
38
+ spec.add_development_dependency 'parallel'
39
+ end
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: 2.7.0
4
+ version: 3.0.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-09-19 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -181,6 +181,7 @@ files:
181
181
  - README.md
182
182
  - Rakefile
183
183
  - lib/tee_logger.rb
184
+ - lib/tee_logger/utils.rb
184
185
  - lib/tee_logger/version.rb
185
186
  - tee_logger.gemspec
186
187
  homepage: https://github.com/k-ta-yamada/tee_logger