log_box 0.0.1a
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/log_box/version.rb +3 -0
- data/lib/log_box.rb +77 -0
- data/log_box.gemspec +26 -0
- data/spec/log_box_spec.rb +124 -0
- data/spec/spec_helper.rb +1 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTcxODAzNDc2Njc1NzBkZTFlMzE3OTRhM2M3NDRmNWNjNGZmNzAwMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzFmMDQwMTRkYTRjNTVlNTgxZjU3OGFiNzBhNWQ5YTZmNjk0Y2JlYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWUzMjQ1NDA4MTk5Yzc5NThiZGNkODMwMTdhNGUzOWRhZDMwYmQ3NjAxMjY3
|
10
|
+
NWNmNmM0MGM0M2JkYWE4MThjZWQyMzRiYzRiZTM5NzQyMGVkNzg3Zjg1M2Ew
|
11
|
+
NTljY2JkNGE3YmY2NzRmMGQ2NWEwNzdhMjlmYjdiMWI4NGIzNjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmQyMDU4MWYwODM0ZGViNmJiMjA4M2JmMDY3ZWFhYzdmZDE3MDQxNWQ4NmYz
|
14
|
+
ZDliYjVlNDQyYjc1YTdmZDMzZDRmZWQzMWM1MGJkZmQxMWRmOGUwZTMwODdl
|
15
|
+
NDI2NTUzYTkyZTlkYTFjZWQ2YzQ0ZTQ4NGE0YTNhMDk3NmYwOGQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jun Yoshida
|
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,29 @@
|
|
1
|
+
# LogBox
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'log_box'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install log_box
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/log_box.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "log_box/version"
|
2
|
+
require "fluent-logger"
|
3
|
+
require "pp"
|
4
|
+
|
5
|
+
module LogBox
|
6
|
+
DEFAULT_TAG = :thread
|
7
|
+
|
8
|
+
def self.log(obj, options = {})
|
9
|
+
o = { tag: DEFAULT_TAG, time: current_time, log: obj }.merge(options)
|
10
|
+
tag = o.delete :tag
|
11
|
+
init_log_box_tag_if_not tag
|
12
|
+
log_box[tag] << o
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Following log will be stored into fluentd:
|
17
|
+
# {
|
18
|
+
# "_id" : ObjectId("52c4a1f4e1eef37b9900001a"),
|
19
|
+
# "tag" : "delayed_job",
|
20
|
+
# "logs" : [
|
21
|
+
# {
|
22
|
+
# "time" : "2014-01-01 15:16:43 -0800",
|
23
|
+
# "log" : "Ho-ho",
|
24
|
+
# "priority" : 3
|
25
|
+
# }
|
26
|
+
# ],
|
27
|
+
# "time" : ISODate("2014-01-01T23:17:01.000Z")
|
28
|
+
# }
|
29
|
+
def self.flush(options = {})
|
30
|
+
o = { tag: DEFAULT_TAG }.merge(options)
|
31
|
+
tag = o[:tag]
|
32
|
+
o[:logs] = log_box[tag]
|
33
|
+
flush_to_fluentd o
|
34
|
+
delete_log_box_tag tag
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.display
|
38
|
+
pp log_box
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.log_box
|
42
|
+
Thread.current[:_log_box]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def self.current_time
|
48
|
+
Time.now
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.init_log_box
|
52
|
+
Thread.current[:_log_box] = {} # key: tag, value: Array of Hash
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.init_log_box_if_not
|
56
|
+
init_log_box if log_box.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.init_log_box_tag_if_not(tag = :thread)
|
60
|
+
init_log_box_if_not
|
61
|
+
log_box[tag] ||= []
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.delete_log_box_tag(tag = :thread)
|
65
|
+
log_box.delete tag
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.init_log_box_tag(tag = :thread)
|
69
|
+
log_box[tag] = []
|
70
|
+
end
|
71
|
+
|
72
|
+
Logger = Fluent::Logger::FluentLogger.new(nil)
|
73
|
+
|
74
|
+
def self.flush_to_fluentd(result)
|
75
|
+
Logger.post 'log_box', result
|
76
|
+
end
|
77
|
+
end
|
data/log_box.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'log_box/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "log_box"
|
8
|
+
spec.version = LogBox::VERSION
|
9
|
+
spec.authors = ["Jun Yoshida"]
|
10
|
+
spec.email = ["yoshida.jun@gmail.com"]
|
11
|
+
spec.description = %q{group Rails log by Web transaction or any other grouping}
|
12
|
+
spec.summary = %q{separate Rails log per Web transaction}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'fluent-logger'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'log_box'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :include_log do |message|
|
5
|
+
match do |logs|
|
6
|
+
logs ||= []
|
7
|
+
logs.include?({time: current_time_, log: message})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec::Matchers.define :include_key_value do |key, value|
|
12
|
+
match do |logs|
|
13
|
+
logs ||= []
|
14
|
+
logs.map { |log| log[key] }.include? value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe LogBox do
|
19
|
+
let(:current_time_) { '2014-01-23' }
|
20
|
+
let(:default_tag_) { LogBox::DEFAULT_TAG }
|
21
|
+
|
22
|
+
let(:new_tag_) { :new_tag }
|
23
|
+
|
24
|
+
let(:message_1_) { 'hello 1' }
|
25
|
+
let(:message_2_) { 'hello 2' }
|
26
|
+
|
27
|
+
before do
|
28
|
+
LogBox.send(:init_log_box)
|
29
|
+
LogBox.stub(:current_time).and_return(current_time_)
|
30
|
+
end
|
31
|
+
|
32
|
+
def verify(message, tag = default_tag_)
|
33
|
+
expect(LogBox.log_box[tag]).to include_log(message)
|
34
|
+
end
|
35
|
+
|
36
|
+
def verify_not(message, tag = default_tag_)
|
37
|
+
expect(LogBox.log_box[tag]).not_to include_log(message)
|
38
|
+
end
|
39
|
+
|
40
|
+
def log(message, options = {})
|
41
|
+
LogBox.log message, options
|
42
|
+
end
|
43
|
+
|
44
|
+
def try_flush(expected = {})
|
45
|
+
tag = expected.delete(:tag) || default_tag_
|
46
|
+
LogBox.should_receive(:flush_to_fluentd) do |obj_to_fluentd|
|
47
|
+
expect(obj_to_fluentd[:tag]).to eq(tag)
|
48
|
+
expect(obj_to_fluentd).to have_key(:logs)
|
49
|
+
expected.each_pair do |key, value|
|
50
|
+
expect(obj_to_fluentd[:logs]).to include_key_value(key, value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
LogBox.flush tag: tag
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'one box' do
|
57
|
+
describe '#log' do
|
58
|
+
it 'init_log_box' do
|
59
|
+
log message_1_
|
60
|
+
LogBox.send(:init_log_box)
|
61
|
+
verify_not message_1_
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'default tag' do
|
65
|
+
log message_1_
|
66
|
+
verify message_1_
|
67
|
+
verify_not message_2_
|
68
|
+
|
69
|
+
log message_2_
|
70
|
+
verify message_1_
|
71
|
+
verify message_2_
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'new tag' do
|
75
|
+
log message_1_, tag: new_tag_
|
76
|
+
verify message_1_, new_tag_
|
77
|
+
verify_not message_1_
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'additional key value' do
|
81
|
+
log message_1_, tag: new_tag_, new_key: 'new_value'
|
82
|
+
expect(LogBox.log_box[new_tag_]).to include_key_value(:new_key, 'new_value')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#flush' do
|
87
|
+
it 'default tag' do
|
88
|
+
log message_1_
|
89
|
+
try_flush log: message_1_
|
90
|
+
end
|
91
|
+
|
92
|
+
it '2 logs' do
|
93
|
+
log message_1_
|
94
|
+
log message_2_
|
95
|
+
try_flush log: message_1_, log: message_2_
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'multiple boxes' do
|
101
|
+
describe '#log' do
|
102
|
+
it 'default, new_tag' do
|
103
|
+
log message_1_
|
104
|
+
log message_2_, tag: new_tag_
|
105
|
+
|
106
|
+
verify message_1_
|
107
|
+
verify_not message_2_
|
108
|
+
|
109
|
+
verify message_2_, new_tag_
|
110
|
+
verify_not message_1_, new_tag_
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#flush' do
|
115
|
+
it 'default, new_tag' do
|
116
|
+
log message_1_
|
117
|
+
log message_2_, tag: new_tag_
|
118
|
+
|
119
|
+
try_flush tag: default_tag_, log: message_1_
|
120
|
+
try_flush tag: new_tag_, log: message_2_
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rubygems'
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_box
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1a
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun Yoshida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
type: :development
|
15
|
+
prerelease: false
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
type: :development
|
29
|
+
prerelease: false
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
name: fluent-logger
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: group Rails log by Web transaction or any other grouping
|
70
|
+
email:
|
71
|
+
- yoshida.jun@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/log_box.rb
|
82
|
+
- lib/log_box/version.rb
|
83
|
+
- log_box.gemspec
|
84
|
+
- spec/log_box_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>'
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.1
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.1.5
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: separate Rails log per Web transaction
|
110
|
+
test_files:
|
111
|
+
- spec/log_box_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
has_rdoc:
|