stdlogger 0.3.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +64 -0
- data/Rakefile +14 -0
- data/lib/stdlogger.rb +45 -0
- data/lib/stdlogger/error.rb +4 -0
- data/lib/stdlogger/multi_io.rb +15 -0
- data/lib/stdlogger/version.rb +3 -0
- data/stdlogger.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: de506a5086aed8c318df2b21f9a03ac1c81b3c42
|
4
|
+
data.tar.gz: 2f849a1a146adbefd723688dec3d273d2dadd66c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 725bbae7a000d0111bc8733119a611ef8bed82d3f3730e2ea97d4de81bd010347cbfd9cab4036717414734799a22461e0c28d0df98e88f81840180458b7e4833
|
7
|
+
data.tar.gz: 9c2dc13541a4e8028296a8584b3eb650e74df9d3e1115a38c7347355711a2143fe81aa857125f39fdfdb8a53913c70c0f47e9705439d5623468dc1fb7228d16b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.8
|
6
|
+
- 2.2.0
|
7
|
+
before_install: gem install bundler -v 1.11.2
|
8
|
+
notifications:
|
9
|
+
slack:
|
10
|
+
secure: PRQpcAvvve3U7+TvebaDCuhidR8+HnJO3LBXwf21hZbPwEJvu0L4J/tkn5+ICMaFUXK9sc9ORUCbcHUVLC/6dvo4g8jqGASqWyCbNB5yxDo896dnWn5ekwXfvE4KPSp0tnuvCx0bXdhewVG18Zs7RvBRbE19/CNlexZGlbulcHTTjA56LiXopWAmbfZFsOiasjVpwUdXO+npWfstMwGQpWwWiidCD3uWZBXpGoGDxApqGkWYulnwLCIOCJju+yvJ80jtJlyrv/vXsJWEfWd1Y1cdfeCyFV2/t4L6ZcVys6+yb3EfYLvF1Izj7AoV9z1kxBwf4oBnQUeBxVffn1mayh31XUjUdQOtAHbYiVomb0zjWr6R1RlrN1pS9hNIGFAi9Uhw9cMYozAGxDYndhpPrKKqHia3TwyvelgUDQ1Np9dHafWK2ltKdOVcIqKc5vuBzbgeM0pj5tK00LFQc5xla0BoIjj4AlEBZ1DgwS8bsbnIHqV/+S6YcV1lh9iBE4SyvXkDjhnKV9WIiOV5cFcWMn2jz3raM538nzLEXwOOxz8HPF+iShAp0TUKpJ8qmU/1vcDsCm1fHzdlirr3fG5EvlaWAph1zhWeP+y25WRnbvM8MtSc+GrE0kqygnYuO2EBEzru49xBFz3V+099vX7HkG9SdJ2yAf3T9d+QtL+ei5c=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## 0.3.0 (2016/4/5)
|
2
|
+
|
3
|
+
Re-release as `stdlogger`.
|
4
|
+
|
5
|
+
Change:
|
6
|
+
|
7
|
+
- Rename main module from `LoggerWithStdout` to `StdLogger` and method `#logger` to `#create`.
|
8
|
+
|
9
|
+
## 0.2.0 (2016/4/4)
|
10
|
+
|
11
|
+
Re-release as `logger-with-stdout`.
|
12
|
+
|
13
|
+
Change:
|
14
|
+
|
15
|
+
- Provides `LoggerWithStdout#logger` public method which returns `Logger` object.
|
16
|
+
- Removed `Logger::WithStdout` old interface.
|
17
|
+
|
18
|
+
## 0.1.0 (2016/4/3)
|
19
|
+
|
20
|
+
Initial release as `logger-with_stdout`.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 YASUTAKE Kiyoshi
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# stdlogger
|
2
|
+
[](https://travis-ci.org/key-amb/ruby-stdlogger)
|
3
|
+
|
4
|
+
This package enables to create `Logger` object which writes logs to _STDOUT_ in
|
5
|
+
addition to specified log device when _STDOUT_ is TTY.
|
6
|
+
And it can also write logs to _STDERR_ by option.
|
7
|
+
|
8
|
+
Useful for Command-line Tools.
|
9
|
+
|
10
|
+
Rewritten from [logger-with_stdout](https://github.com/key-amb/logger-with_stdout).
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'stdlogger'
|
16
|
+
|
17
|
+
# STDOUT only
|
18
|
+
logger = StdLogger.create
|
19
|
+
# logfile and STDOUT
|
20
|
+
logger = StdLogger.create '/path/to/log'
|
21
|
+
# logdev and STDERR
|
22
|
+
logger = StdLogger.create io_obj, stdout: false, stderr: true
|
23
|
+
# Other options for Logger::new
|
24
|
+
logger = StdLogger.create io_obj, shift_age: 3, shift_size: 1024 * 1024 * 8
|
25
|
+
# Doesn't raise error when STDOUT is not TTY
|
26
|
+
logger = StdLogger.create nil, allow_nodev: true
|
27
|
+
```
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'stdlogger'
|
35
|
+
```
|
36
|
+
|
37
|
+
And then run `bundle` command on your terminal.
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
```sh
|
42
|
+
% gem install stdlogger
|
43
|
+
```
|
44
|
+
|
45
|
+
## Spetial Thanks
|
46
|
+
|
47
|
+
Thanks to [David](http://stackoverflow.com/users/796195/david) who gave me the
|
48
|
+
idea of `MultiIO`.
|
49
|
+
|
50
|
+
It is illustrated as [answer to a question in Stack Overflow](http://stackoverflow.com/a/6407200/6150943).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new [Pull Request](../../pull/new/master)
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The MIT License (MIT)
|
63
|
+
|
64
|
+
Copyright (c) 2016 YASUTAKE Kiyoshi
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rspec/core'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc 'Open an irb session preloaded with the gem library'
|
11
|
+
task :console do
|
12
|
+
sh 'irb -rubygems -I lib -r stdlogger'
|
13
|
+
end
|
14
|
+
task :c => :console
|
data/lib/stdlogger.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
require "stdlogger/error"
|
4
|
+
require "stdlogger/multi_io"
|
5
|
+
require "stdlogger/version"
|
6
|
+
|
7
|
+
module StdLogger
|
8
|
+
|
9
|
+
# When no target device available, this method raises StdLogger::Error
|
10
|
+
# without ':allow_nodev' option.
|
11
|
+
# @param logdev [String, IO] path to logfile or writable IO object.
|
12
|
+
# @param options [Hash]
|
13
|
+
# @option options [String] :stdout (true) log to STDOUT or not.
|
14
|
+
# @option options [String] :stderr (false) log to STDERR or not.
|
15
|
+
# @option options [String] :shift_age (0)
|
16
|
+
# 'shift_age' param for Logger#new
|
17
|
+
# @option options [String] :shift_size (1048576)
|
18
|
+
# 'shift_size' param for Logger#new
|
19
|
+
# @option options [String] :allow_nodev (nil)
|
20
|
+
# don't raise error even if no target device available
|
21
|
+
# @return [Logger]
|
22
|
+
def self.create logdev=nil, options={}
|
23
|
+
stdout = options[:stdout] || true
|
24
|
+
stderr = options[:stderr] || false
|
25
|
+
shift_age = options[:shift_age] || 0
|
26
|
+
shift_size = options[:shift_size] || 1048576
|
27
|
+
|
28
|
+
targets = []
|
29
|
+
if logdev
|
30
|
+
if logdev.class == String
|
31
|
+
targets << File.open(logdev, 'a')
|
32
|
+
else
|
33
|
+
targets << logdev
|
34
|
+
end
|
35
|
+
end
|
36
|
+
targets << $stdout if (stdout and $stdout.tty?)
|
37
|
+
targets << $stderr if (stderr and $stderr.tty?)
|
38
|
+
if targets.empty? and !options[:allow_nodev]
|
39
|
+
raise Error, "No output device found!"
|
40
|
+
end
|
41
|
+
multi_dev = MultiIO.new targets
|
42
|
+
|
43
|
+
Logger.new multi_dev, shift_age, shift_size
|
44
|
+
end
|
45
|
+
end
|
data/stdlogger.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'stdlogger/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "stdlogger"
|
9
|
+
spec.version = StdLogger::VERSION
|
10
|
+
spec.authors = ["YASUTAKE Kiyoshi"]
|
11
|
+
spec.email = ["yasutake.kiyoshi@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Make Logger write logs to STDOUT in addition}
|
14
|
+
spec.description = %q{Creates Logger writing logs to STDOUT or STDERR in addition to target device.}
|
15
|
+
spec.homepage = "https://github.com/key-amb/stdlogger"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stdlogger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- YASUTAKE Kiyoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Creates Logger writing logs to STDOUT or STDERR in addition to target
|
56
|
+
device.
|
57
|
+
email:
|
58
|
+
- yasutake.kiyoshi@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/stdlogger.rb
|
72
|
+
- lib/stdlogger/error.rb
|
73
|
+
- lib/stdlogger/multi_io.rb
|
74
|
+
- lib/stdlogger/version.rb
|
75
|
+
- stdlogger.gemspec
|
76
|
+
homepage: https://github.com/key-amb/stdlogger
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Make Logger write logs to STDOUT in addition
|
100
|
+
test_files: []
|