md-logstasher 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/logstasher/device/udp.rb +40 -0
- data/lib/logstasher/device.rb +3 -0
- data/lib/logstasher/version.rb +1 -1
- data/spec/lib/logstasher/device/udp_spec.rb +37 -0
- data/spec/lib/logstasher/device_spec.rb +11 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91f47cc71b8a9c6f01e3f12661c11922040c2c0acf6be1882eee182fffca6aba
|
4
|
+
data.tar.gz: dd9494bd0f46ef6b01a9c5df6166794db82a0fdc563e06df0555efb2acba7472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e486d0d8eef5bd325d700fcf1685bf1d26f8a1764dc32c8e054f35cca64d5a9a2a8aed18bc75441ceeb536902cae59ffd7ea76013aea959dd89e0453d8907f66
|
7
|
+
data.tar.gz: 1d836f746425a75131f82db774c25a6ec5a9fb0ad34680884b88bb4946c4b7413be9a76b231cbc2810f1477e484e655ad596af871dcb9fb2689d66ce20a75e59
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# simple UDP logger
|
2
|
+
|
3
|
+
require 'logstasher/device'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
|
7
|
+
module LogStasher
|
8
|
+
module Device
|
9
|
+
class UDP
|
10
|
+
include ::LogStasher::Device
|
11
|
+
|
12
|
+
attr_reader :options, :socket
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@options = default_options.merge(stringify_keys(options))
|
16
|
+
@socket = UDPSocket.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
@socket.close
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(log)
|
24
|
+
@socket.send(log, 0, options['hostname'], options['port'])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_options
|
30
|
+
{
|
31
|
+
'hostname' => '127.0.0.1',
|
32
|
+
'port' => 31459,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
data/lib/logstasher/device.rb
CHANGED
@@ -11,6 +11,9 @@ module LogStasher
|
|
11
11
|
when "syslog", :syslog then
|
12
12
|
require 'logstasher/device/syslog'
|
13
13
|
::LogStasher::Device::Syslog.new(config)
|
14
|
+
when "udp", :udp then
|
15
|
+
require 'logstasher/device/udp'
|
16
|
+
::LogStasher::Device::UDP.new(config)
|
14
17
|
else
|
15
18
|
fail ArgumentError, "Unknown type: #{type}"
|
16
19
|
end
|
data/lib/logstasher/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'logstasher/device/udp'
|
4
|
+
|
5
|
+
describe LogStasher::Device::UDP do
|
6
|
+
|
7
|
+
let(:default_options) {{
|
8
|
+
'hostname' => '127.0.0.1',
|
9
|
+
'port' => 31459
|
10
|
+
}}
|
11
|
+
|
12
|
+
it 'has default options' do
|
13
|
+
device = LogStasher::Device::UDP.new
|
14
|
+
expect(device.options).to eq(default_options)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'closes the udp socket on #close' do
|
18
|
+
device = LogStasher::Device::UDP.new
|
19
|
+
expect(device.socket).to receive(:close)
|
20
|
+
device.close
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'works as a logger device' do
|
24
|
+
device = LogStasher::Device::UDP.new
|
25
|
+
expect(device).to receive(:write).with('foo')
|
26
|
+
logger = Logger.new(device)
|
27
|
+
logger << 'foo'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#write' do
|
31
|
+
subject { LogStasher::Device::UDP.new }
|
32
|
+
it 'writes the log to the the socket' do
|
33
|
+
expect(subject.socket).to receive(:send).with('a log', 0, default_options['hostname'], default_options['port'])
|
34
|
+
subject.write('a log')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
require "logstasher/device"
|
4
4
|
require "logstasher/device/redis"
|
5
5
|
require "logstasher/device/syslog"
|
6
|
+
require "logstasher/device/udp"
|
6
7
|
|
7
8
|
describe LogStasher::Device do
|
8
9
|
describe ".factory" do
|
@@ -47,7 +48,17 @@ describe LogStasher::Device do
|
|
47
48
|
device = ::LogStasher::Device.factory(:type => "syslog")
|
48
49
|
expect(device).to be_a_kind_of(::LogStasher::Device::Syslog)
|
49
50
|
end
|
51
|
+
|
52
|
+
it "can create udp devices" do
|
53
|
+
expect(
|
54
|
+
::LogStasher::Device
|
55
|
+
).to receive(:require).with("logstasher/device/udp")
|
56
|
+
|
57
|
+
device = ::LogStasher::Device.factory(:type => "udp")
|
58
|
+
expect(device).to be_a_kind_of(::LogStasher::Device::UDP)
|
59
|
+
end
|
50
60
|
|
61
|
+
|
51
62
|
it "fails to create unknown devices" do
|
52
63
|
expect {
|
53
64
|
::LogStasher::Device.factory(:type => "unknown")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md-logstasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Christensen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-event
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/logstasher/device.rb
|
86
86
|
- lib/logstasher/device/redis.rb
|
87
87
|
- lib/logstasher/device/syslog.rb
|
88
|
+
- lib/logstasher/device/udp.rb
|
88
89
|
- lib/logstasher/log_subscriber.rb
|
89
90
|
- lib/logstasher/railtie.rb
|
90
91
|
- lib/logstasher/silent_logger.rb
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- logstasher.gemspec
|
97
98
|
- spec/lib/logstasher/device/redis_spec.rb
|
98
99
|
- spec/lib/logstasher/device/syslog_spec.rb
|
100
|
+
- spec/lib/logstasher/device/udp_spec.rb
|
99
101
|
- spec/lib/logstasher/device_spec.rb
|
100
102
|
- spec/lib/logstasher/log_subscriber_spec.rb
|
101
103
|
- spec/lib/logstasher/railtie_spec.rb
|
@@ -105,7 +107,7 @@ homepage: https://github.com/moneydesktop/logstasher
|
|
105
107
|
licenses:
|
106
108
|
- MIT
|
107
109
|
metadata: {}
|
108
|
-
post_install_message:
|
110
|
+
post_install_message:
|
109
111
|
rdoc_options: []
|
110
112
|
require_paths:
|
111
113
|
- lib
|
@@ -120,14 +122,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
- !ruby/object:Gem::Version
|
121
123
|
version: '0'
|
122
124
|
requirements: []
|
123
|
-
|
124
|
-
|
125
|
-
signing_key:
|
125
|
+
rubygems_version: 3.2.28
|
126
|
+
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Awesome rails logs
|
128
129
|
test_files:
|
129
130
|
- spec/lib/logstasher/device/redis_spec.rb
|
130
131
|
- spec/lib/logstasher/device/syslog_spec.rb
|
132
|
+
- spec/lib/logstasher/device/udp_spec.rb
|
131
133
|
- spec/lib/logstasher/device_spec.rb
|
132
134
|
- spec/lib/logstasher/log_subscriber_spec.rb
|
133
135
|
- spec/lib/logstasher/railtie_spec.rb
|