md-logstasher 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4563d96cf88d8a5e5fa8c1a263ed5e79c2fa2acc
4
- data.tar.gz: edbcb27c41a3068d29fb1d896131a81035391c3d
3
+ metadata.gz: caa8c203cdf135bf92e27bfca4064949758143c3
4
+ data.tar.gz: 98ee851c3e42f83a2c4da5826affa3a1fc1c5ad2
5
5
  SHA512:
6
- metadata.gz: f2bcdf71a918cbed00947a631abbd3a444dee9918afd8eb3d1947e4f092fc8569327ee088bb5aa890d5900fc959879dc3e9da3fcac96d675d36a6ea2db66e08f
7
- data.tar.gz: 77f0394fb5e701c380176ae702412d07c8b24faa31d6f67ec60969ad3e5f42499c763bcd4e6d78efbb19ba1750750619d074e9e4e011e65d306b1d50a231c3cc
6
+ metadata.gz: fbcabec619855beaf57346e6ecd42b41ae8ba487ece014e7c34b047bc83c8b12efeb6d0a1e116ae427b407d6d0f59aef40067b1e0b0d3e5a38c47685b7a2ca12
7
+ data.tar.gz: 8830d3f59e199d1c31d8226755093b9dfcefb8401d38c9058d0bac828274785e21c81030a5f3a691362d8afd301fc24534b111efec901d71835fa031a135a4d3
@@ -59,7 +59,7 @@ module LogStasher
59
59
 
60
60
  def validate_options
61
61
  unless ['list', 'channel'].include?(options['data_type'])
62
- fail 'Expected data_type to be either "list" or "channel"'
62
+ fail RuntimeError, 'Expected data_type to be either "list" or "channel"'
63
63
  end
64
64
  end
65
65
  end
@@ -2,34 +2,27 @@
2
2
 
3
3
  require 'logstasher/device'
4
4
  require 'syslog'
5
- require 'thread'
6
5
 
7
6
  module LogStasher
8
7
  module Device
9
8
  class Syslog
10
9
  include ::LogStasher::Device
11
10
 
12
- SEMAPHORE = Mutex.new
13
-
14
11
  attr_reader :options
15
12
 
16
13
  def initialize(options = {})
17
14
  raw_options = default_options.merge(stringify_keys(options))
18
15
 
19
16
  @options = parse_options(raw_options)
20
- @closed = false
17
+ open_syslog
21
18
  end
22
19
 
23
20
  def close
24
- SEMAPHORE.synchronize do
25
- ::Syslog.close if ::Syslog.opened?
26
- end
27
-
28
- @closed = true
21
+ ::Syslog.close rescue nil
29
22
  end
30
23
 
31
24
  def closed?
32
- @closed
25
+ !::Syslog.opened?
33
26
  end
34
27
 
35
28
  def facility
@@ -49,11 +42,10 @@ module LogStasher
49
42
  end
50
43
 
51
44
  def write(log)
52
- fail ::RuntimeError, 'Cannot write. The device has been closed.' if closed?
45
+ fail ::RuntimeError, 'Syslog has been closed.' if closed?
46
+ fail ::RuntimeError, 'Syslog re-configured unexpectedly.' if syslog_config_changed?
53
47
 
54
- with_syslog_open do
55
- ::Syslog.log(priority, '%s', log)
56
- end
48
+ ::Syslog.log(priority, '%s', log)
57
49
  end
58
50
 
59
51
  private
@@ -63,10 +55,18 @@ module LogStasher
63
55
  'identity' => 'logstasher',
64
56
  'facility' => ::Syslog::LOG_LOCAL0,
65
57
  'priority' => ::Syslog::LOG_INFO,
66
- 'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
58
+ 'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS,
67
59
  }
68
60
  end
69
61
 
62
+ def open_syslog
63
+ if ::Syslog.opened?
64
+ ::Syslog.reopen(identity, flags, facility)
65
+ else
66
+ ::Syslog.open(identity, flags, facility)
67
+ end
68
+ end
69
+
70
70
  def parse_option(value)
71
71
  case value
72
72
  when ::String
@@ -85,20 +85,8 @@ module LogStasher
85
85
  options
86
86
  end
87
87
 
88
- def syslog_configured?
89
- ::Syslog.ident == identity && ::Syslog.options == flags && ::Syslog.facility == facility
90
- end
91
-
92
- def with_syslog_open
93
- SEMAPHORE.synchronize do
94
- if ::Syslog.opened?
95
- ::Syslog.reopen(identity, flags, facility) unless syslog_configured?
96
- else
97
- ::Syslog.open(identity, flags, facility)
98
- end
99
-
100
- yield
101
- end
88
+ def syslog_config_changed?
89
+ ::Syslog.ident != identity || ::Syslog.options != flags || ::Syslog.facility != facility
102
90
  end
103
91
  end
104
92
  end
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -40,7 +40,7 @@ describe LogStasher::Device::Redis do
40
40
  it 'does not allow unsupported data types' do
41
41
  expect {
42
42
  device = LogStasher::Device::Redis.new(data_type: 'blargh')
43
- }.to raise_error()
43
+ }.to raise_error(::RuntimeError)
44
44
  end
45
45
 
46
46
  it 'quits the redis connection on #close' do
@@ -14,9 +14,9 @@ describe LogStasher::Device::Syslog do
14
14
  before { allow(::Syslog).to receive(:log) }
15
15
 
16
16
  around do |example|
17
- ::Syslog.close if ::Syslog.opened?
17
+ ::Syslog.close rescue nil
18
18
  example.run
19
- ::Syslog.close if ::Syslog.opened?
19
+ ::Syslog.close rescue nil
20
20
  end
21
21
 
22
22
  it 'has default options' do
@@ -64,25 +64,37 @@ describe LogStasher::Device::Syslog do
64
64
  expect(device.flags).to eq(::Syslog::LOG_NOWAIT | ::Syslog::LOG_ODELAY)
65
65
  end
66
66
 
67
- describe '#write' do
68
- subject { LogStasher::Device::Syslog.new }
67
+ it 'opens syslog when it is closed' do
68
+ expect(::Syslog).to receive(:open).with(
69
+ default_options['identity'],
70
+ default_options['flags'],
71
+ default_options['facility'],
72
+ )
69
73
 
70
- it 'opens syslog when syslog is closed' do
71
- expect(::Syslog).to receive(:open).with(subject.identity, subject.flags, subject.facility)
72
- subject.write('a log')
73
- end
74
+ LogStasher::Device::Syslog.new
75
+ end
74
76
 
75
- it 'does not re-open syslog when its config is in sync' do
76
- ::Syslog.open(subject.identity, subject.flags, subject.facility)
77
- expect(::Syslog).not_to receive(:open)
78
- expect(::Syslog).not_to receive(:reopen)
79
- subject.write('a log')
80
- end
77
+ it 're-opens syslog when it is already opened' do
78
+ ::Syslog.open('temp', ::Syslog::LOG_NDELAY, ::Syslog::LOG_AUTH)
81
79
 
82
- it 're-opens syslog when its config is out of sync' do
83
- ::Syslog.open('temp', ::Syslog::LOG_NDELAY, ::Syslog::LOG_AUTH)
84
- expect(::Syslog).to receive(:reopen).with(subject.identity, subject.flags, subject.facility)
85
- subject.write('a log')
80
+ expect(::Syslog).to receive(:reopen).with(
81
+ default_options['identity'],
82
+ default_options['flags'],
83
+ default_options['facility'],
84
+ )
85
+
86
+ LogStasher::Device::Syslog.new
87
+ end
88
+
89
+ describe '#write' do
90
+ subject { LogStasher::Device::Syslog.new }
91
+
92
+ it 'fails when the syslog config is out of sync' do
93
+ subject
94
+ ::Syslog.reopen('temp', ::Syslog::LOG_NDELAY, ::Syslog::LOG_AUTH)
95
+ expect {
96
+ subject.write('a log')
97
+ }.to raise_error(::RuntimeError, 'Syslog re-configured unexpectedly.')
86
98
  end
87
99
 
88
100
  it 'writes the log to syslog' do
@@ -94,7 +106,7 @@ describe LogStasher::Device::Syslog do
94
106
  subject.close
95
107
  expect {
96
108
  subject.write('a log')
97
- }.to raise_error(::RuntimeError, 'Cannot write. The device has been closed.')
109
+ }.to raise_error(::RuntimeError, 'Syslog has been closed.')
98
110
  end
99
111
  end
100
112
 
@@ -106,15 +118,9 @@ describe LogStasher::Device::Syslog do
106
118
  expect(subject).to be_closed
107
119
  end
108
120
 
109
- it 'closes syslog when syslog is open' do
110
- ::Syslog.open(subject.identity, subject.flags, subject.facility)
121
+ it 'closes syslog' do
111
122
  expect(::Syslog).to receive(:close)
112
123
  subject.close
113
124
  end
114
-
115
- it 'does not close syslog if it is already closed' do
116
- expect(::Syslog).not_to receive(:close)
117
- subject.close
118
- end
119
125
  end
120
126
  end
@@ -19,12 +19,6 @@ describe ::LogStasher::Railtie do
19
19
  let(:config) { described_class.config.logstasher }
20
20
 
21
21
  describe 'logstasher.configure' do
22
- subject do
23
- described_class.instance.initializers.find do |initializer|
24
- initializer.name == 'logstasher.configure'
25
- end
26
- end
27
-
28
22
  it 'should configure LogStasher' do
29
23
  config.logger = ::Logger.new('/dev/null')
30
24
  config.log_level = "log_level"
@@ -40,7 +34,7 @@ describe ::LogStasher::Railtie do
40
34
  expect(::LogStasher).to receive(:logger=).with(config.logger).and_call_original
41
35
  expect(config.logger).to receive(:level=).with("log_level")
42
36
 
43
- subject.run
37
+ ActiveSupport.run_load_hooks(:before_initialize)
44
38
  end
45
39
  end
46
40
 
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.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Christensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.2.2
124
+ rubygems_version: 2.5.1
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Awesome rails logs