logstash-logger 0.10.3 → 0.11.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +4 -0
- data/lib/logstash-logger/device.rb +2 -0
- data/lib/logstash-logger/device/balancer.rb +40 -0
- data/lib/logstash-logger/version.rb +1 -1
- data/spec/device/balancer_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00421e5706d99d473e29844c80e2c50f471f2ca1
|
4
|
+
data.tar.gz: a1ae4bd4936c8acecbc560391bda1e70f624ecb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 194c6aec69634dfd22112a120fa6c9dc5e459f82eae2e97f78b1e512907bb20d7f475edb7d60f66ffec6637a72cafd5ba9c1079ae6bf6bf83696aa2276570f00
|
7
|
+
data.tar.gz: 495dfc7623df42e62418e20b274185bb2c1e40fa588a166fd09af97dc5878d4cf721aaaa463df7c6a93706a1aed8da49057ce00074fdf9b6cfb3b4a1a24fd67c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -52,6 +52,9 @@ io_logger = LogStashLogger.new(type: :io, io: io)
|
|
52
52
|
# Multiple Outputs
|
53
53
|
multi_logger = LogStashLogger.new([{type: :file, path: 'log/development.log'}, {type: :udp, host: 'localhost', port: 5228}])
|
54
54
|
|
55
|
+
# Balancing messages between several outputs
|
56
|
+
balancer_logger = LogStashLogger.new(type: :balancer, outputs: [{type: :udp, host: 'host1', port: 5228}, {type: :udp, host: 'host2', port: 5228}])
|
57
|
+
|
55
58
|
# The following messages are written to UDP port 5228:
|
56
59
|
|
57
60
|
logger.info 'test'
|
@@ -447,6 +450,7 @@ logger = LogStashLogger.new('localhost', 5228, :tcp)
|
|
447
450
|
* [Felix Bechstein](https://github.com/felixb)
|
448
451
|
* [Vadim Kazakov](https://github.com/yads)
|
449
452
|
* [Anil Rhemtulla](https://github.com/AnilRh)
|
453
|
+
* [Nikita Vorobei](https://github.com/Nikita-V)
|
450
454
|
|
451
455
|
## Contributing
|
452
456
|
|
@@ -16,6 +16,7 @@ module LogStashLogger
|
|
16
16
|
autoload :IO, 'logstash-logger/device/io'
|
17
17
|
autoload :Stdout, 'logstash-logger/device/stdout'
|
18
18
|
autoload :Stderr, 'logstash-logger/device/stderr'
|
19
|
+
autoload :Balancer, 'logstash-logger/device/balancer'
|
19
20
|
autoload :MultiDelegator, 'logstash-logger/device/multi_delegator'
|
20
21
|
|
21
22
|
def self.new(opts)
|
@@ -62,6 +63,7 @@ module LogStashLogger
|
|
62
63
|
when :io then IO
|
63
64
|
when :stdout then Stdout
|
64
65
|
when :stderr then Stderr
|
66
|
+
when :balancer then Balancer
|
65
67
|
else fail ArgumentError, 'Invalid type'
|
66
68
|
end
|
67
69
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module LogStashLogger
|
2
|
+
module Device
|
3
|
+
class Balancer < Base
|
4
|
+
attr_reader :devices
|
5
|
+
|
6
|
+
def initialize(opts)
|
7
|
+
@io = self
|
8
|
+
@devices = create_devices(opts[:outputs])
|
9
|
+
self.class.delegate_to_all(:close, :flush)
|
10
|
+
self.class.delegate_to_one(:write)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_devices(opts)
|
16
|
+
opts.map { |o| Device.new(o) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.delegate_to_all(*methods)
|
20
|
+
methods.each do |m|
|
21
|
+
define_method(m) do |*args|
|
22
|
+
devices.each { |device| device.send(m, *args) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.delegate_to_one(*methods)
|
28
|
+
methods.each do |m|
|
29
|
+
define_method(m) do |*args|
|
30
|
+
select_device.send(m, *args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def select_device
|
36
|
+
devices.sample
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'logstash-logger'
|
2
|
+
|
3
|
+
describe LogStashLogger::Device::Balancer do
|
4
|
+
include_context 'device'
|
5
|
+
|
6
|
+
# Create a Balancer writing to both STDOUT and a StringIO
|
7
|
+
let(:subject) { balancer_device }
|
8
|
+
|
9
|
+
let(:stdout) { $stdout }
|
10
|
+
let(:io) { StringIO.new }
|
11
|
+
|
12
|
+
describe '#write' do
|
13
|
+
before do
|
14
|
+
allow(subject.devices).to receive(:sample) { io }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "writes to one device" do
|
18
|
+
expect(io).to receive(:write).once
|
19
|
+
expect(stdout).to_not receive(:write)
|
20
|
+
subject.write("log message")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#flush, #close' do
|
25
|
+
[:flush, :close].each do |method_name|
|
26
|
+
it "call on all devices" do
|
27
|
+
subject.devices.each do |device|
|
28
|
+
expect(device).to receive(method_name).once
|
29
|
+
end
|
30
|
+
subject.send(method_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -54,6 +54,7 @@ RSpec.shared_context 'device' do
|
|
54
54
|
let(:redis_device) { LogStashLogger::Device.new(type: :redis, sync: true) }
|
55
55
|
let(:kafka_device) { LogStashLogger::Device.new(type: :kafka, sync: true) }
|
56
56
|
let(:multi_delegator_device) { LogStashLogger::Device.new([{type: :stdout}, {type: :io, io: io}]) }
|
57
|
+
let(:balancer_device) { LogStashLogger::Device.new(type: :balancer, outputs: [{type: :stdout}, {type: :io, io: io}]) }
|
57
58
|
|
58
59
|
let(:udp_uri) { "udp://localhost:5228" }
|
59
60
|
let(:tcp_uri) { "tcp://localhost:5229" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-event
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/logstash-logger.rb
|
174
174
|
- lib/logstash-logger/configuration.rb
|
175
175
|
- lib/logstash-logger/device.rb
|
176
|
+
- lib/logstash-logger/device/balancer.rb
|
176
177
|
- lib/logstash-logger/device/base.rb
|
177
178
|
- lib/logstash-logger/device/connectable.rb
|
178
179
|
- lib/logstash-logger/device/file.rb
|
@@ -201,6 +202,7 @@ files:
|
|
201
202
|
- samples/udp.conf
|
202
203
|
- samples/unix.conf
|
203
204
|
- spec/configuration_spec.rb
|
205
|
+
- spec/device/balancer_spec.rb
|
204
206
|
- spec/device/file_spec.rb
|
205
207
|
- spec/device/io_spec.rb
|
206
208
|
- spec/device/kafka_spec.rb
|
@@ -243,6 +245,7 @@ specification_version: 4
|
|
243
245
|
summary: LogStash Logger for ruby
|
244
246
|
test_files:
|
245
247
|
- spec/configuration_spec.rb
|
248
|
+
- spec/device/balancer_spec.rb
|
246
249
|
- spec/device/file_spec.rb
|
247
250
|
- spec/device/io_spec.rb
|
248
251
|
- spec/device/kafka_spec.rb
|