logstash-logger-p 0.26.1

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.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +1156 -0
  5. data/.travis.yml +26 -0
  6. data/Appraisals +23 -0
  7. data/CHANGELOG.md +199 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +880 -0
  11. data/Rakefile +23 -0
  12. data/gemfiles/rails_3.2.gemfile +9 -0
  13. data/gemfiles/rails_4.0.gemfile +9 -0
  14. data/gemfiles/rails_4.1.gemfile +9 -0
  15. data/gemfiles/rails_4.2.gemfile +9 -0
  16. data/gemfiles/rails_5.0.gemfile +9 -0
  17. data/gemfiles/rails_5.1.gemfile +9 -0
  18. data/lib/logstash-logger/buffer.rb +336 -0
  19. data/lib/logstash-logger/configuration.rb +29 -0
  20. data/lib/logstash-logger/device/aws_stream.rb +94 -0
  21. data/lib/logstash-logger/device/balancer.rb +40 -0
  22. data/lib/logstash-logger/device/base.rb +73 -0
  23. data/lib/logstash-logger/device/connectable.rb +131 -0
  24. data/lib/logstash-logger/device/file.rb +23 -0
  25. data/lib/logstash-logger/device/firehose.rb +42 -0
  26. data/lib/logstash-logger/device/io.rb +11 -0
  27. data/lib/logstash-logger/device/kafka.rb +57 -0
  28. data/lib/logstash-logger/device/kinesis.rb +44 -0
  29. data/lib/logstash-logger/device/multi_delegator.rb +36 -0
  30. data/lib/logstash-logger/device/redis.rb +76 -0
  31. data/lib/logstash-logger/device/socket.rb +21 -0
  32. data/lib/logstash-logger/device/stderr.rb +13 -0
  33. data/lib/logstash-logger/device/stdout.rb +14 -0
  34. data/lib/logstash-logger/device/tcp.rb +86 -0
  35. data/lib/logstash-logger/device/udp.rb +12 -0
  36. data/lib/logstash-logger/device/unix.rb +18 -0
  37. data/lib/logstash-logger/device.rb +67 -0
  38. data/lib/logstash-logger/formatter/base.rb +73 -0
  39. data/lib/logstash-logger/formatter/cee.rb +11 -0
  40. data/lib/logstash-logger/formatter/cee_syslog.rb +22 -0
  41. data/lib/logstash-logger/formatter/json.rb +11 -0
  42. data/lib/logstash-logger/formatter/json_lines.rb +11 -0
  43. data/lib/logstash-logger/formatter/logstash_event.rb +6 -0
  44. data/lib/logstash-logger/formatter.rb +51 -0
  45. data/lib/logstash-logger/logger.rb +106 -0
  46. data/lib/logstash-logger/multi_logger.rb +153 -0
  47. data/lib/logstash-logger/railtie.rb +51 -0
  48. data/lib/logstash-logger/silenced_logging.rb +83 -0
  49. data/lib/logstash-logger/tagged_logging.rb +40 -0
  50. data/lib/logstash-logger/version.rb +3 -0
  51. data/lib/logstash-logger.rb +11 -0
  52. data/logstash-logger.gemspec +39 -0
  53. data/samples/example.crt +16 -0
  54. data/samples/example.key +15 -0
  55. data/samples/file.conf +11 -0
  56. data/samples/redis.conf +12 -0
  57. data/samples/ssl.conf +15 -0
  58. data/samples/syslog.conf +10 -0
  59. data/samples/tcp.conf +11 -0
  60. data/samples/udp.conf +11 -0
  61. data/samples/unix.conf +11 -0
  62. data/spec/configuration_spec.rb +27 -0
  63. data/spec/constructor_spec.rb +30 -0
  64. data/spec/device/balancer_spec.rb +31 -0
  65. data/spec/device/connectable_spec.rb +74 -0
  66. data/spec/device/file_spec.rb +15 -0
  67. data/spec/device/firehose_spec.rb +41 -0
  68. data/spec/device/io_spec.rb +13 -0
  69. data/spec/device/kafka_spec.rb +32 -0
  70. data/spec/device/kinesis_spec.rb +41 -0
  71. data/spec/device/multi_delegator_spec.rb +31 -0
  72. data/spec/device/redis_spec.rb +52 -0
  73. data/spec/device/socket_spec.rb +15 -0
  74. data/spec/device/stderr_spec.rb +16 -0
  75. data/spec/device/stdout_spec.rb +31 -0
  76. data/spec/device/tcp_spec.rb +120 -0
  77. data/spec/device/udp_spec.rb +9 -0
  78. data/spec/device/unix_spec.rb +23 -0
  79. data/spec/device_spec.rb +97 -0
  80. data/spec/formatter/base_spec.rb +125 -0
  81. data/spec/formatter/cee_spec.rb +15 -0
  82. data/spec/formatter/cee_syslog_spec.rb +43 -0
  83. data/spec/formatter/json_lines_spec.rb +14 -0
  84. data/spec/formatter/json_spec.rb +10 -0
  85. data/spec/formatter/logstash_event_spec.rb +10 -0
  86. data/spec/formatter_spec.rb +79 -0
  87. data/spec/logger_spec.rb +128 -0
  88. data/spec/multi_logger_spec.rb +59 -0
  89. data/spec/rails_spec.rb +91 -0
  90. data/spec/silenced_logging_spec.rb +31 -0
  91. data/spec/spec_helper.rb +111 -0
  92. data/spec/syslog_spec.rb +32 -0
  93. data/spec/tagged_logging_spec.rb +32 -0
  94. metadata +335 -0
@@ -0,0 +1,16 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICdTCCAd4CCQDLMpdv+B+sYDANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJV
3
+ UzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8GA1UEBxMIUGFzYWRlbmExDzANBgNV
4
+ BAoTBkJ1dGxlcjEVMBMGA1UEAxMMRGF2aWQgQnV0bGVyMSAwHgYJKoZIhvcNAQkB
5
+ FhFkd2J1dGxlckB1Y2xhLmVkdTAeFw0xNDA2MDkwNjIyMTZaFw0xNTA2MDkwNjIy
6
+ MTZaMH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMREwDwYDVQQH
7
+ EwhQYXNhZGVuYTEPMA0GA1UEChMGQnV0bGVyMRUwEwYDVQQDEwxEYXZpZCBCdXRs
8
+ ZXIxIDAeBgkqhkiG9w0BCQEWEWR3YnV0bGVyQHVjbGEuZWR1MIGfMA0GCSqGSIb3
9
+ DQEBAQUAA4GNADCBiQKBgQDbBJ1t2m8RA72GZZ8XOUCsLI1EhRqZqWx0zYHpZbc4
10
+ kVbfMeb5uyfpx1gd5QngZrsD0cvTf46F9z9Ng805Ns9jE5QBJxefl1b6iJ6f/Y9s
11
+ W+WYQJgtNOcJahWWLeiBXqApPUllFI2ME/52+/umuSYVtSVAW7QmPx3YSLPpVjkQ
12
+ 3wIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAKiZm6yNzRXKJ9LBLL+Nep87WPlkdFmx
13
+ YUoEtTF8XpgMNfOdzF8DlD4FmoNz/SD7uVOk+tARUoEQFVK+iqpd3/dLDVa/pslX
14
+ a5v6AcmgfSFUHgLvKQZNvgY50jhLdqruf8PCgVnq+4L0ItguJx/viYMxF0p0fJTG
15
+ oGX8W4ul0W5F
16
+ -----END CERTIFICATE-----
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICWwIBAAKBgQDbBJ1t2m8RA72GZZ8XOUCsLI1EhRqZqWx0zYHpZbc4kVbfMeb5
3
+ uyfpx1gd5QngZrsD0cvTf46F9z9Ng805Ns9jE5QBJxefl1b6iJ6f/Y9sW+WYQJgt
4
+ NOcJahWWLeiBXqApPUllFI2ME/52+/umuSYVtSVAW7QmPx3YSLPpVjkQ3wIDAQAB
5
+ AoGAYaFXBAchB3ahX22hU1rkJ1vcxTSIPQM3I4IQbRg4anDvRqMaESyKiD2iXAEj
6
+ O/LPXs6Ai5EK2VDz2Pvt2ZlDLFX3GKMEChtIa2mpiQqIdoJS+42ibqfHrv3nlnTK
7
+ OTeTcw+SbAAFTKFPJO94lGcBXhsYYW/LAFH08bVqp+Jhi1ECQQDzkz4O0eYH05Wb
8
+ 1bAwjNcjj+X6JKIRGgWYb1kkk3VyAFuD6qCEKBfS2t4nZs1yy83Ch4Bk9YmDHx1Q
9
+ gdYCjPsLAkEA5jCwo51KqboxAz6m0pZwdiKlCav94TMdHMKTFcUE5fDoWrwzrIyH
10
+ 8rr7q7cl3culX7pUcPdKMl78Nw6/4JFF/QJARwNfrWxut0ttq+BSHOWC98BFWXeC
11
+ tJ+0j+uuvqYrMJCAHeay47TYtUXQTQaA0X4vwA5HVafsbokMv+MKpPW7XwJAF713
12
+ yjgDpkOMoIAKpndbe+OQz9GMKniiDQBIORuLqMdSv2Dfl3Ea6D6+i/QklJ5XHOtT
13
+ oB7w6QcAzhDYWynAZQJAX0UF9alkX8CQq1rvsAG6zzh3bD+Udy7cU0Yonx/byZoz
14
+ K6G/seM5YFTMVrnbY9V23aIhjJSxGWOB5fDNPG5p4w==
15
+ -----END RSA PRIVATE KEY-----
data/samples/file.conf ADDED
@@ -0,0 +1,11 @@
1
+ input {
2
+ file {
3
+ path => "/usr/local/var/logstash.log"
4
+ format => json
5
+ }
6
+ }
7
+ output {
8
+ stdout {
9
+ codec => json_lines
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ input {
2
+ redis {
3
+ data_type => "list"
4
+ codec => json
5
+ key => "logstash"
6
+ }
7
+ }
8
+ output {
9
+ stdout {
10
+ codec => json_lines
11
+ }
12
+ }
data/samples/ssl.conf ADDED
@@ -0,0 +1,15 @@
1
+ input {
2
+ tcp {
3
+ port => 8443
4
+ ssl_enable => true
5
+ ssl_cert => "samples/example.crt"
6
+ ssl_key => "samples/example.key"
7
+ codec => json_lines
8
+ }
9
+ }
10
+ output {
11
+ stdout {
12
+ codec => json_lines
13
+ }
14
+ }
15
+
@@ -0,0 +1,10 @@
1
+ input {
2
+ syslog {
3
+ codec => json_lines
4
+ }
5
+ }
6
+ output {
7
+ stdout {
8
+ codec => json_lines
9
+ }
10
+ }
data/samples/tcp.conf ADDED
@@ -0,0 +1,11 @@
1
+ input {
2
+ tcp {
3
+ port => 5228
4
+ codec => json_lines
5
+ }
6
+ }
7
+ output {
8
+ stdout {
9
+ codec => json_lines
10
+ }
11
+ }
data/samples/udp.conf ADDED
@@ -0,0 +1,11 @@
1
+ input {
2
+ udp {
3
+ port => 5228
4
+ codec => json_lines
5
+ }
6
+ }
7
+ output {
8
+ stdout {
9
+ codec => json_lines
10
+ }
11
+ }
data/samples/unix.conf ADDED
@@ -0,0 +1,11 @@
1
+ input {
2
+ unix {
3
+ path => "/tmp/logstash"
4
+ codec => json_lines
5
+ }
6
+ }
7
+ output {
8
+ stdout {
9
+ codec => json_lines
10
+ }
11
+ }
@@ -0,0 +1,27 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger do
4
+ describe "#configure" do
5
+ it 'auto initializes' do
6
+ config = LogStashLogger.configure
7
+ expect(config).to be_a LogStashLogger::Configuration
8
+ expect(LogStashLogger.configuration).to eq(config)
9
+ end
10
+
11
+ describe LogStashLogger::Configuration do
12
+ describe "#customize_event" do
13
+ it 'allows each LogStash::Event to be customized' do
14
+ config = LogStashLogger.configure do |config|
15
+ config.customize_event do |event|
16
+ event["test1"] = "response1"
17
+ end
18
+ end
19
+
20
+ event = LogStash::Event.new({})
21
+ config.customize_event_block.call(event)
22
+ expect(event["test1"]).to eq("response1")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger do
4
+ describe '.new' do
5
+ it 'returns a Logger instance' do
6
+ expect(LogStashLogger.new(type: :stdout)).to be_a ::Logger
7
+ end
8
+
9
+ context 'type: :multi_logger' do
10
+ it "returns an instance of LogStashLogger::MultiLogger" do
11
+ expect(LogStashLogger.new(type: :multi_logger)).to be_a LogStashLogger::MultiLogger
12
+ end
13
+
14
+ it 'merges top level configuration into each logger' do
15
+ logger = LogStashLogger.new(type: :multi_logger, port: 1234, outputs: [ { type: :tcp }, { type: :udp } ])
16
+ logger.loggers.each do |logger|
17
+ expect(logger.device.port).to eq(1234)
18
+ end
19
+ end
20
+ end
21
+
22
+ context 'logger_class: CustomLogger' do
23
+ class CustomLogger < Logger; end
24
+
25
+ it 'should create a logger of the specified class' do
26
+ expect(LogStashLogger.new(type: :stdout, :logger_class => CustomLogger)).to be_a CustomLogger
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
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
+ subject { balancer_device }
8
+
9
+ describe '#write' do
10
+ before do
11
+ allow(subject.devices).to receive(:sample) { io }
12
+ end
13
+
14
+ it "writes to one device" do
15
+ expect(io).to receive(:write).once
16
+ expect($stdout).to_not receive(:write)
17
+ subject.write("log message")
18
+ end
19
+ end
20
+
21
+ describe '#flush, #close' do
22
+ [:flush, :close].each do |method_name|
23
+ it "call on all devices" do
24
+ subject.devices.each do |device|
25
+ expect(device).to receive(method_name).once
26
+ end
27
+ subject.send(method_name)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,74 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Connectable do
4
+ include_context 'device'
5
+
6
+ let(:io) { double("IO") }
7
+
8
+ subject { udp_device }
9
+
10
+ describe "#reconnect" do
11
+ context "with active IO connection" do
12
+ before do
13
+ subject.instance_variable_set(:@io, io)
14
+ end
15
+
16
+ it "closes the connection" do
17
+ expect(io).to receive(:close).once
18
+ subject.reconnect
19
+ end
20
+ end
21
+
22
+ context "with no active IO connection" do
23
+ before do
24
+ subject.instance_variable_set(:@io, nil)
25
+ end
26
+
27
+ it "does nothing" do
28
+ expect(io).to_not receive(:close)
29
+ subject.reconnect
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#with_connection" do
35
+ context "on exception" do
36
+ before do
37
+ allow(subject).to receive(:connected?) { raise(StandardError) }
38
+ allow(subject).to receive(:warn)
39
+ end
40
+
41
+ context "with active IO connection" do
42
+ before do
43
+ subject.instance_variable_set(:@io, io)
44
+ end
45
+
46
+ it "closes the connection" do
47
+ expect(io).to receive(:close).once
48
+
49
+ expect {
50
+ subject.with_connection do |connection|
51
+ connection
52
+ end
53
+ }.to raise_error(StandardError)
54
+ end
55
+ end
56
+
57
+ context "with no active IO connection" do
58
+ before do
59
+ subject.instance_variable_set(:@io, nil)
60
+ end
61
+
62
+ it "does nothing" do
63
+ expect(io).to_not receive(:close)
64
+
65
+ expect {
66
+ subject.with_connection do |connection|
67
+ connection
68
+ end
69
+ }.to raise_error(StandardError)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::File do
4
+ include_context 'device'
5
+
6
+ it "writes to a file" do
7
+ expect(file_device.to_io).to be_a ::File
8
+ end
9
+
10
+ context "when path is not specified" do
11
+ it "raises an exception" do
12
+ expect { described_class.new }.to raise_error(ArgumentError)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Firehose do
4
+ include_context 'device'
5
+
6
+ let(:client) { double("Aws::Firehose::Client") }
7
+
8
+ before(:each) do
9
+ allow(Aws::Firehose::Client).to receive(:new) { client }
10
+ end
11
+
12
+ it "writes to a Firehose stream" do
13
+ response = ::Aws::Firehose::Types::PutRecordBatchOutput.new
14
+ response.failed_put_count = 0
15
+ response.request_responses = []
16
+ expect(client).to receive(:put_record_batch) { response }
17
+ firehose_device.write "foo"
18
+
19
+ expect(firehose_device).to be_connected
20
+ firehose_device.close!
21
+ expect(firehose_device).not_to be_connected
22
+ end
23
+
24
+ it "it puts records with recoverable errors back in the buffer" do
25
+ failed_record = ::Aws::Firehose::Types::PutRecordBatchResponseEntry.new
26
+ failed_record.error_code = "InternalFailure"
27
+ failed_record.error_message = "InternalFailure"
28
+ response = ::Aws::Firehose::Types::PutRecordBatchOutput.new
29
+ response.failed_put_count = 1
30
+ response.request_responses = [failed_record]
31
+
32
+ expect(client).to receive(:put_record_batch) { response }
33
+ expect(firehose_device).to receive(:write).with("foo")
34
+
35
+ firehose_device.write_one "foo"
36
+ end
37
+
38
+ it "defaults the Firehose stream to logstash" do
39
+ expect(firehose_device.stream).to eq('logstash')
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::IO do
4
+ include_context 'device'
5
+
6
+ subject { io_device }
7
+
8
+ it "writes to the IO object" do
9
+ expect(subject.to_io).to eq(io)
10
+ expect(io).to receive(:write).once
11
+ subject.write("test")
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Kafka do
4
+ include_context 'device'
5
+
6
+ let(:producer) { double("Poseidon::Producer") }
7
+
8
+ before(:each) do
9
+ allow(Poseidon::Producer).to receive(:new) { producer }
10
+ end
11
+
12
+ it "writes to a Kafka topic" do
13
+ expect(producer).to receive(:send_messages)
14
+ kafka_device.write "foo"
15
+ end
16
+
17
+ it "defaults the Kafka hosts to ['localhost:9092']" do
18
+ expect(kafka_device.hosts).to eq(['localhost:9092'])
19
+ end
20
+
21
+ it "defaults the Kafka topic to 'logstash'" do
22
+ expect(kafka_device.topic).to eq('logstash')
23
+ end
24
+
25
+ it "defaults the Kafka producer to 'logstash-logger'" do
26
+ expect(kafka_device.producer).to eq('logstash-logger')
27
+ end
28
+
29
+ it "defaults the Kafka backoff to 1" do
30
+ expect(kafka_device.backoff).to eq(1)
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Kinesis do
4
+ include_context 'device'
5
+
6
+ let(:client) { double("Aws::Kinesis::Client") }
7
+
8
+ before(:each) do
9
+ allow(Aws::Kinesis::Client).to receive(:new) { client }
10
+ end
11
+
12
+ it "writes to a Kinesis stream" do
13
+ response = ::Aws::Kinesis::Types::PutRecordsOutput.new
14
+ response.failed_record_count = 0
15
+ response.records = []
16
+ expect(client).to receive(:put_records) { response }
17
+ kinesis_device.write "foo"
18
+
19
+ expect(kinesis_device).to be_connected
20
+ kinesis_device.close!
21
+ expect(kinesis_device).not_to be_connected
22
+ end
23
+
24
+ it "it puts records with recoverable errors back in the buffer" do
25
+ failed_record = ::Aws::Kinesis::Types::PutRecordsResultEntry.new
26
+ failed_record.error_code = "ProvisionedThroughputExceededException"
27
+ failed_record.error_message = "ProvisionedThroughputExceededException"
28
+ response = ::Aws::Kinesis::Types::PutRecordsOutput.new
29
+ response.failed_record_count = 1
30
+ response.records = [failed_record]
31
+
32
+ expect(client).to receive(:put_records) { response }
33
+ expect(kinesis_device).to receive(:write).with("foo")
34
+
35
+ kinesis_device.write_one "foo"
36
+ end
37
+
38
+ it "defaults the kinesis stream to logstash" do
39
+ expect(kinesis_device.stream).to eq('logstash')
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::MultiDelegator do
4
+ include_context 'device'
5
+
6
+ # Create a MultiDelegator writing to both STDOUT and a StringIO
7
+ subject { multi_delegator_device }
8
+
9
+ it "writes to all outputs" do
10
+ expect($stdout).to receive(:write).once
11
+ expect(io).to receive(:write).once
12
+
13
+ subject.write("test")
14
+ end
15
+
16
+ describe ".new" do
17
+ it "merges top level configuration to each output" do
18
+ logger = described_class.new(
19
+ port: 1234,
20
+ outputs: [
21
+ { type: :udp },
22
+ { type: :tcp }
23
+ ]
24
+ )
25
+
26
+ logger.devices.each do |device|
27
+ expect(device.port).to eq(1234)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,52 @@
1
+ require 'logstash-logger'
2
+ require 'redis'
3
+
4
+ describe LogStashLogger::Device::Redis do
5
+ include_context 'device'
6
+
7
+ let(:redis) { double("Redis") }
8
+
9
+ before(:each) do
10
+ allow(Redis).to receive(:new) { redis }
11
+ allow(redis).to receive(:connect)
12
+ end
13
+
14
+ it "writes to a Redis list" do
15
+ expect(redis).to receive(:rpush)
16
+ redis_device.write "foo"
17
+ end
18
+
19
+ it "defaults the Redis list to 'logstash'" do
20
+ expect(redis_device.list).to eq('logstash')
21
+ end
22
+
23
+ describe "initializer" do
24
+ let(:redis_options) { { host: HOST, port: 6379 } }
25
+ subject { LogStashLogger::Device::Redis.new(redis_options).connect }
26
+
27
+ context "path is not blank" do
28
+ before do
29
+ redis_options[:path] = "/0"
30
+ end
31
+
32
+ it "sets the db" do
33
+ expect(Redis).to receive(:new).with(hash_including(db: 0))
34
+ subject
35
+ end
36
+
37
+ end
38
+
39
+ context "path is blank" do
40
+ before do
41
+ redis_options[:path] = ""
42
+ end
43
+
44
+ it "does not set the db" do
45
+ expect(Redis).to receive(:new).with(hash_excluding(:db))
46
+ subject
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,15 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Socket do
4
+ include_context 'device'
5
+
6
+ it "defaults host to 0.0.0.0" do
7
+ expect(device_with_port.host).to eq("0.0.0.0")
8
+ end
9
+
10
+ context "when port is not specified" do
11
+ it "raises an exception" do
12
+ expect { described_class.new }.to raise_error(ArgumentError)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Stderr do
4
+ let(:stderr) { $stderr }
5
+
6
+ it 'writes to stderr' do
7
+ expect(subject.to_io).to eq stderr
8
+ expect(stderr).to receive(:write).once
9
+ subject.write("test")
10
+ end
11
+
12
+ it 'ignores #close' do
13
+ expect(stderr).not_to receive(:close)
14
+ subject.close
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ require 'logstash-logger'
2
+
3
+ describe LogStashLogger::Device::Stdout do
4
+ let(:stdout) { $stdout }
5
+
6
+ it "writes to $stdout" do
7
+ expect(subject.to_io).to eq(stdout)
8
+ expect(stdout).to receive(:write).once
9
+ subject.write("test")
10
+ end
11
+
12
+ it "ignores #close" do
13
+ expect(stdout).not_to receive(:close)
14
+ subject.close
15
+ end
16
+
17
+ context "when the default $stdout has been overridden" do
18
+ before { $stdout = StringIO.new }
19
+ after { $stdout = STDOUT }
20
+
21
+ let(:injected_stdout) { STDOUT }
22
+
23
+ subject { described_class.new(io: injected_stdout) }
24
+
25
+ it "accepts an injectable reference to stdout" do
26
+ expect(subject.to_io).to eq(injected_stdout)
27
+ expect(injected_stdout).to receive(:write).once
28
+ subject.write("test")
29
+ end
30
+ end
31
+ end