split_logger 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +10 -0
- data/lib/split_logger.rb +2 -4
- data/lib/split_logger/split_logger.rb +16 -8
- data/lib/split_logger/version.rb +3 -0
- data/split_logger.gemspec +25 -0
- data/test/split_logger/split_logger_test.rb +89 -0
- data/test/test_helper.rb +4 -0
- metadata +100 -44
- data/LICENSE +0 -21
- data/README +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b87bbab6f95cf2e064a6cf98c45729050ad5322c
|
4
|
+
data.tar.gz: 1aba659765ea606fe5e61235fa48025218aaf422
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5cd4281649eaaa4ebeee7012bd1c105e6df875d99755058924ead90763d8b44d4d0e4358ef7535d9edaa7e85dfe822e48b9336b66891a57b1be9829c41ff61e7
|
7
|
+
data.tar.gz: 05e26a889a9ce292a3213d23ce8c57a9c474fbd3f9153693bf4c3b016881295f138033383f3a837856e2d3a13ea2766c5bc668c163679a2f04a678806824f5ce
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.log
|
2
|
+
.DS_Store
|
3
|
+
doc
|
4
|
+
tmp
|
5
|
+
pkg
|
6
|
+
*.gem
|
7
|
+
*.pid
|
8
|
+
coverage
|
9
|
+
coverage.data
|
10
|
+
build/*
|
11
|
+
*.pbxuser
|
12
|
+
*.mode1v3
|
13
|
+
.svn
|
14
|
+
profile
|
15
|
+
.console_history
|
16
|
+
.sass-cache/*
|
17
|
+
.rake_tasks~
|
18
|
+
*.log.lck
|
19
|
+
solr/
|
20
|
+
.jhw-cache/
|
21
|
+
jhw.*
|
22
|
+
*.sublime*
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
split_logger (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
metaclass (0.0.2)
|
10
|
+
minitest (5.2.1)
|
11
|
+
mocha (1.0.0)
|
12
|
+
metaclass (~> 0.0.1)
|
13
|
+
rake (10.1.1)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.5)
|
20
|
+
minitest
|
21
|
+
mocha
|
22
|
+
rake
|
23
|
+
split_logger!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mark Bates
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# SplitLogger
|
2
|
+
[![Build Status](https://travis-ci.org/markbates/split_logger.png)](https://travis-ci.org/markbates/split_logger) [![Code Climate](https://codeclimate.com/github/markbates/split_logger.png)](https://codeclimate.com/github/markbates/split_logger)
|
3
|
+
|
4
|
+
This gem let's you write to multiple log destinations at the same time.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'split_logger'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```console
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```console
|
23
|
+
$ gem install split_logger
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
You can set up loggers in one of two ways:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
logger = SplitLogger.new
|
32
|
+
logger.add(std: Logger.new(STDOUT))
|
33
|
+
logger.add(file: Logger.new("/path/to/log"))
|
34
|
+
logger.level = ::Logger::INFO
|
35
|
+
|
36
|
+
logger.info "Hello Logs"
|
37
|
+
```
|
38
|
+
|
39
|
+
or you can pass them all into the initializer:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
logger = SplitLogger.new({
|
43
|
+
std: Logger.new(STDOUT),
|
44
|
+
file: Logger.new("/path/to/log")
|
45
|
+
})
|
46
|
+
logger.level = ::Logger::INFO
|
47
|
+
|
48
|
+
logger.info "Hello Logs"
|
49
|
+
```
|
50
|
+
|
51
|
+
### Rails
|
52
|
+
|
53
|
+
By default the Rails logger is automatically added when creating a new `SplitLogger`.
|
54
|
+
|
55
|
+
Of course, if you don't want the Rails logger it can easily be removed.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
logger.remove(:rails_default_logger)
|
59
|
+
```
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it ( http://github.com/<my-github-username>/split_logger/fork )
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/split_logger.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class SplitLogger
|
2
|
-
|
2
|
+
|
3
3
|
attr_accessor :logger_list
|
4
|
-
|
4
|
+
attr_reader :level
|
5
|
+
|
5
6
|
def initialize(loggers = {})
|
6
7
|
self.logger_list = {}
|
7
8
|
loggers.each do |name, logger|
|
@@ -11,22 +12,29 @@ class SplitLogger
|
|
11
12
|
self.add(:rails_default_logger, RAILS_DEFAULT_LOGGER)
|
12
13
|
end
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
def add(name, logger)
|
16
17
|
self.logger_list[name.to_sym] = logger
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
def remove(name)
|
20
21
|
name = name.to_sym
|
21
22
|
if self.logger_list.has_key?(name)
|
22
23
|
self.logger_list.delete(name)
|
23
24
|
end
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
def list
|
27
28
|
self.logger_list
|
28
29
|
end
|
29
|
-
|
30
|
+
|
31
|
+
def level=(level)
|
32
|
+
@level = level
|
33
|
+
self.logger_list.each do |name, logger|
|
34
|
+
logger.level = level
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
[:debug, :info, :warn, :error, :fatal].each do |level|
|
31
39
|
define_method(level) do |*args|
|
32
40
|
self.logger_list.each do |name, logger|
|
@@ -40,5 +48,5 @@ class SplitLogger
|
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
43
|
-
|
44
|
-
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'split_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "split_logger"
|
8
|
+
spec.version = SplitLogger::VERSION
|
9
|
+
spec.authors = ["Mark Bates"]
|
10
|
+
spec.email = ["mark@markbates.com"]
|
11
|
+
spec.summary = %q{This gem let's you write to multiple log destinations at the same time.}
|
12
|
+
spec.description = %q{This gem let's you write to multiple log destinations at the same time.}
|
13
|
+
spec.homepage = "http://github.com/markbates/split_logger"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "mocha"
|
25
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
describe SplitLogger do
|
5
|
+
|
6
|
+
let(:sp) {SplitLogger.new}
|
7
|
+
|
8
|
+
describe 'add' do
|
9
|
+
|
10
|
+
it 'should add a logger to the list' do
|
11
|
+
sp.list.size.must_equal 0
|
12
|
+
sp.add(:std, ::Logger.new(STDOUT))
|
13
|
+
sp.list.size.must_equal 1
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'list' do
|
19
|
+
|
20
|
+
it 'should return a list of all loggers' do
|
21
|
+
std = mock('std logger')
|
22
|
+
sp.add(:std, std)
|
23
|
+
sp.list.must_equal(std: std)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'remove' do
|
29
|
+
|
30
|
+
it 'should remove a logger from the list' do
|
31
|
+
std = mock('std logger')
|
32
|
+
sp.add(:std, std)
|
33
|
+
other = mock('other logger')
|
34
|
+
sp.add(:other, other)
|
35
|
+
sp.list.must_equal(std: std, other: other)
|
36
|
+
sp.remove(:other)
|
37
|
+
sp.list.must_equal(std: std)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'Rails' do
|
43
|
+
|
44
|
+
before(:each) do
|
45
|
+
Object.send(:remove_const, 'RAILS_DEFAULT_LOGGER') if defined?(RAILS_DEFAULT_LOGGER)
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
Object.send(:remove_const, 'RAILS_DEFAULT_LOGGER') if defined?(RAILS_DEFAULT_LOGGER)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should automatically add the RAILS_DEFAULT_LOGGER to the list, if defined' do
|
53
|
+
RAILS_DEFAULT_LOGGER = mock('rails_default_logger')
|
54
|
+
sp.list.must_equal(rails_default_logger: RAILS_DEFAULT_LOGGER)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
[:debug, :info, :warn, :error, :fatal].each do |level|
|
60
|
+
|
61
|
+
describe level do
|
62
|
+
|
63
|
+
it "should call #{level} on each logger" do
|
64
|
+
std = mock('std logger')
|
65
|
+
other = mock('other logger')
|
66
|
+
std.expects(level).with('this is my message')
|
67
|
+
other.expects(level).with('this is my message')
|
68
|
+
sp.add(:std, std)
|
69
|
+
sp.add(:other, other)
|
70
|
+
sp.send(level, 'this is my message')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should remove a bad logger from the list and write a message to the other loggers' do
|
74
|
+
std = mock('std logger')
|
75
|
+
std.expects(level).with('this is my message')
|
76
|
+
std.expects(level).with("Ah! Crap!")
|
77
|
+
std.expects(level).with("Removed logger 'oops' from the logger list!")
|
78
|
+
oops = mock('oops')
|
79
|
+
oops.expects(level).with('this is my message').raises('Ah! Crap!')
|
80
|
+
sp.add(:std, std)
|
81
|
+
sp.add(:oops, oops)
|
82
|
+
sp.send(level, 'this is my message')
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,59 +1,115 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: split_logger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Mark Bates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
date: 2014-01-22 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem let's you write to multiple log destinations at the same time.
|
70
|
+
email:
|
71
|
+
- mark@markbates.com
|
18
72
|
executables: []
|
19
|
-
|
20
73
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
|
26
|
-
-
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
27
83
|
- lib/split_logger.rb
|
28
|
-
-
|
29
|
-
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
84
|
+
- lib/split_logger/split_logger.rb
|
85
|
+
- lib/split_logger/version.rb
|
86
|
+
- split_logger.gemspec
|
87
|
+
- test/split_logger/split_logger_test.rb
|
88
|
+
- test/test_helper.rb
|
89
|
+
homepage: http://github.com/markbates/split_logger
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
34
93
|
post_install_message:
|
35
94
|
rdoc_options: []
|
36
|
-
|
37
|
-
require_paths:
|
95
|
+
require_paths:
|
38
96
|
- lib
|
39
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
41
99
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
|
45
|
-
|
46
|
-
requirements:
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
47
104
|
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
version:
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
51
107
|
requirements: []
|
52
|
-
|
53
|
-
|
54
|
-
rubygems_version: 1.3.5
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.0
|
55
110
|
signing_key:
|
56
|
-
specification_version:
|
57
|
-
summary:
|
58
|
-
test_files:
|
59
|
-
|
111
|
+
specification_version: 4
|
112
|
+
summary: This gem let's you write to multiple log destinations at the same time.
|
113
|
+
test_files:
|
114
|
+
- test/split_logger/split_logger_test.rb
|
115
|
+
- test/test_helper.rb
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2009 markbates
|
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
DELETED