fluent-logger 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/AUTHORS +1 -0
- data/COPYING +14 -0
- data/ChangeLog +14 -0
- data/Gemfile +9 -0
- data/README.rdoc +16 -78
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/fluent-logger.gemspec +44 -0
- data/lib/fluent/logger.rb +8 -36
- data/lib/fluent/logger/{console.rb → console_logger.rb} +2 -1
- data/lib/fluent/logger/fluent_logger.rb +214 -0
- data/lib/fluent/logger/logger_base.rb +34 -0
- data/lib/fluent/logger/null_logger.rb +28 -0
- data/lib/fluent/logger/{test.rb → test_logger.rb} +4 -12
- data/lib/fluent/logger/text_logger.rb +40 -0
- data/lib/fluent/logger/version.rb +1 -1
- data/spec/console_logger_spec.rb +69 -0
- data/spec/fluent_logger_spec.rb +201 -0
- data/spec/logger_base_spec.rb +11 -0
- data/spec/logger_spec.rb +43 -0
- data/spec/null_logger_spec.rb +15 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/timecop.rb +8 -0
- data/spec/test_logger_spec.rb +31 -0
- metadata +121 -84
- data/lib/fluent/logger/base.rb +0 -89
- data/lib/fluent/logger/event.rb +0 -118
- data/lib/fluent/logger/fluent.rb +0 -121
- data/lib/fluent/logger/syslog.rb +0 -127
- data/test/event_test.rb +0 -183
- data/test/instance_test.rb +0 -34
- data/test/simple_test.rb +0 -78
- data/test/test_helper.rb +0 -14
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Fluent::Logger::NullLogger do
|
5
|
+
context "logger method" do
|
6
|
+
let(:logger) { Fluent::Logger::NullLogger.new }
|
7
|
+
|
8
|
+
context "post" do
|
9
|
+
it('false') {
|
10
|
+
logger.post('tag1', {:foo => :bar}).should == false
|
11
|
+
logger.post('tag2', {:foo => :baz}).should == false
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
if ENV['SIMPLE_COV']
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter 'spec/'
|
8
|
+
add_filter 'test/'
|
9
|
+
add_filter 'pkg/'
|
10
|
+
add_filter 'vendor/'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Requires supporting files with custom matchers and macros, etc,
|
15
|
+
# in ./support/ and its subdirectories.
|
16
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
17
|
+
|
18
|
+
require 'fluent-logger'
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.filter_run :focus => true
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
|
24
|
+
config.mock_with :rspec
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Fluent::Logger::TestLogger do
|
5
|
+
context "logger method" do
|
6
|
+
let(:logger) { Fluent::Logger::TestLogger.new }
|
7
|
+
subject { logger.queue }
|
8
|
+
|
9
|
+
context "post" do
|
10
|
+
before do
|
11
|
+
logger.post('tag1', {:foo => :bar})
|
12
|
+
logger.post('tag2', {:foo => :baz})
|
13
|
+
end
|
14
|
+
|
15
|
+
its(:first) { should == {:foo => :bar } }
|
16
|
+
its(:last) { should == {:foo => :baz } }
|
17
|
+
its("first.tag") { should == "tag1" }
|
18
|
+
its("last.tag") { should == "tag2" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "max" do
|
22
|
+
before do
|
23
|
+
logger.max = 2
|
24
|
+
10.times {|i| logger.post(i.to_s, {}) }
|
25
|
+
end
|
26
|
+
|
27
|
+
its(:size) { should == 2 }
|
28
|
+
its("last.tag") { should == "9" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,116 +1,153 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-logger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Sadayuki Furuhashi
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2011-11-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: &70346070861020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
version_requirements: *70346070861020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: msgpack
|
27
|
+
requirement: &70346070860420 !ruby/object:Gem::Requirement
|
25
28
|
none: false
|
26
|
-
requirements:
|
29
|
+
requirements:
|
27
30
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 7
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 4
|
33
|
-
- 4
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 0.4.4
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: json
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *70346070860420
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70346070859840 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.2
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70346070859840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &70346070859260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.7.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70346070859260
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &70346070858660 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.5.4
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70346070858660
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: &70346070858200 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.3.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70346070858200
|
80
|
+
description: fluent logger for ruby
|
54
81
|
email: frsyuki@gmail.com
|
55
82
|
executables: []
|
56
|
-
|
57
83
|
extensions: []
|
58
|
-
|
59
|
-
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .gitmodules
|
88
|
+
- .rspec
|
89
|
+
- .travis.yml
|
90
|
+
- AUTHORS
|
91
|
+
- COPYING
|
60
92
|
- ChangeLog
|
93
|
+
- Gemfile
|
61
94
|
- README.rdoc
|
62
|
-
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- fluent-logger.gemspec
|
63
98
|
- lib/fluent-logger.rb
|
64
99
|
- lib/fluent/logger.rb
|
65
|
-
- lib/fluent/logger/
|
66
|
-
- lib/fluent/logger/
|
67
|
-
- lib/fluent/logger/
|
68
|
-
- lib/fluent/logger/
|
69
|
-
- lib/fluent/logger/
|
70
|
-
- lib/fluent/logger/
|
100
|
+
- lib/fluent/logger/console_logger.rb
|
101
|
+
- lib/fluent/logger/fluent_logger.rb
|
102
|
+
- lib/fluent/logger/logger_base.rb
|
103
|
+
- lib/fluent/logger/null_logger.rb
|
104
|
+
- lib/fluent/logger/test_logger.rb
|
105
|
+
- lib/fluent/logger/text_logger.rb
|
71
106
|
- lib/fluent/logger/version.rb
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
|
79
|
-
|
107
|
+
- spec/console_logger_spec.rb
|
108
|
+
- spec/fluent_logger_spec.rb
|
109
|
+
- spec/logger_base_spec.rb
|
110
|
+
- spec/logger_spec.rb
|
111
|
+
- spec/null_logger_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/timecop.rb
|
114
|
+
- spec/test_logger_spec.rb
|
115
|
+
homepage: https://github.com/fluent/fluent-logger-ruby
|
80
116
|
licenses: []
|
81
|
-
|
82
117
|
post_install_message:
|
83
|
-
rdoc_options:
|
84
|
-
|
85
|
-
require_paths:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
86
120
|
- lib
|
87
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
122
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
segments:
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
94
128
|
- 0
|
95
|
-
|
96
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
hash: 675212802163774553
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
131
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
|
102
|
-
segments:
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
103
137
|
- 0
|
104
|
-
|
138
|
+
hash: 675212802163774553
|
105
139
|
requirements: []
|
106
|
-
|
107
140
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.8.10
|
109
142
|
signing_key:
|
110
143
|
specification_version: 3
|
111
|
-
summary:
|
112
|
-
test_files:
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
144
|
+
summary: fluent logger for ruby
|
145
|
+
test_files:
|
146
|
+
- spec/console_logger_spec.rb
|
147
|
+
- spec/fluent_logger_spec.rb
|
148
|
+
- spec/logger_base_spec.rb
|
149
|
+
- spec/logger_spec.rb
|
150
|
+
- spec/null_logger_spec.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/support/timecop.rb
|
153
|
+
- spec/test_logger_spec.rb
|
data/lib/fluent/logger/base.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Fluent
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011 FURUHASHI Sadayuki
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
module Fluent
|
19
|
-
module Logger
|
20
|
-
|
21
|
-
|
22
|
-
class LoggerBase
|
23
|
-
def self.open(*args, &block)
|
24
|
-
Fluent::Logger.open(self, *args, &block)
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_event(tag, *args)
|
28
|
-
map = {}
|
29
|
-
keys = []
|
30
|
-
args.each {|a|
|
31
|
-
case a
|
32
|
-
when Hash
|
33
|
-
a.each_pair {|k,v|
|
34
|
-
keys << k.to_sym
|
35
|
-
map[k.to_sym] = v
|
36
|
-
}
|
37
|
-
else
|
38
|
-
keys << a.to_sym
|
39
|
-
end
|
40
|
-
}
|
41
|
-
|
42
|
-
m = Module.new
|
43
|
-
m.module_eval do
|
44
|
-
keys.each {|key|
|
45
|
-
define_method(key) do |v|
|
46
|
-
with(key=>v)
|
47
|
-
end
|
48
|
-
define_method(:"#{key}!") do |v|
|
49
|
-
with!(key=>v)
|
50
|
-
end
|
51
|
-
}
|
52
|
-
define_method(:MODULE) { m }
|
53
|
-
end
|
54
|
-
|
55
|
-
e = TerminalEvent.new(self, tag, map)
|
56
|
-
e.extend(m)
|
57
|
-
e
|
58
|
-
end
|
59
|
-
|
60
|
-
#def post(tag, map)
|
61
|
-
#end
|
62
|
-
|
63
|
-
#def close(map)
|
64
|
-
#end
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
class TextLogger < LoggerBase
|
69
|
-
def initialize
|
70
|
-
require 'json'
|
71
|
-
@time_format = "%b %e %H:%M:%S"
|
72
|
-
end
|
73
|
-
|
74
|
-
def post(tag, map)
|
75
|
-
a = [Time.now.strftime(@time_format), " ", tag, ":"]
|
76
|
-
map.each_pair {|k,v|
|
77
|
-
a << " #{k}="
|
78
|
-
a << v.to_json
|
79
|
-
}
|
80
|
-
post_text a.join
|
81
|
-
end
|
82
|
-
|
83
|
-
#def post_text(text)
|
84
|
-
#end
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
data/lib/fluent/logger/event.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Fluent
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011 FURUHASHI Sadayuki
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
module Fluent
|
19
|
-
module Logger
|
20
|
-
|
21
|
-
|
22
|
-
class Event
|
23
|
-
def initialize(link, map)
|
24
|
-
@link = link
|
25
|
-
@map = map
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_hash(o={})
|
29
|
-
@link.to_hash(o)
|
30
|
-
o.merge!(@map)
|
31
|
-
o
|
32
|
-
end
|
33
|
-
|
34
|
-
def tag
|
35
|
-
@link.tag
|
36
|
-
end
|
37
|
-
|
38
|
-
def logger
|
39
|
-
@link.logger
|
40
|
-
end
|
41
|
-
|
42
|
-
def logger=(logger)
|
43
|
-
@link.logger = logger
|
44
|
-
end
|
45
|
-
|
46
|
-
def post!(with_tag=tag)
|
47
|
-
logger.post(with_tag, to_hash)
|
48
|
-
self
|
49
|
-
end
|
50
|
-
|
51
|
-
alias post post!
|
52
|
-
|
53
|
-
def with(a)
|
54
|
-
if a.is_a?(Event)
|
55
|
-
ma = MODULE()
|
56
|
-
mb = a.MODULE()
|
57
|
-
m = Module.new
|
58
|
-
m.module_eval do
|
59
|
-
include ma
|
60
|
-
include mb
|
61
|
-
define_method(:MODULE) { m }
|
62
|
-
end
|
63
|
-
map = a.to_hash(to_hash)
|
64
|
-
e = TerminalEvent.new(LOGGER(), tag, map)
|
65
|
-
e.extend(m)
|
66
|
-
else
|
67
|
-
map = a.to_hash
|
68
|
-
e = Event.new(self, map)
|
69
|
-
e.extend(MODULE())
|
70
|
-
end
|
71
|
-
e
|
72
|
-
end
|
73
|
-
|
74
|
-
alias + with
|
75
|
-
|
76
|
-
def with!(a)
|
77
|
-
if a.is_a?(Event)
|
78
|
-
self.extend a.MODULE()
|
79
|
-
a.to_hash(@map)
|
80
|
-
else
|
81
|
-
@map.merge!(a.to_hash)
|
82
|
-
end
|
83
|
-
self
|
84
|
-
end
|
85
|
-
|
86
|
-
def create_event(*args)
|
87
|
-
self.with(LOGGER().create_event(*args))
|
88
|
-
end
|
89
|
-
|
90
|
-
def LOGGER
|
91
|
-
@link.LOGGER()
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
class TerminalEvent < Event
|
97
|
-
def initialize(logger, tag, map)
|
98
|
-
@logger = logger
|
99
|
-
@tag = tag
|
100
|
-
@map = map
|
101
|
-
end
|
102
|
-
|
103
|
-
def to_hash(o={})
|
104
|
-
o.merge!(@map)
|
105
|
-
o
|
106
|
-
end
|
107
|
-
|
108
|
-
attr_accessor :tag
|
109
|
-
attr_accessor :logger
|
110
|
-
|
111
|
-
def LOGGER
|
112
|
-
@logger
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|