md-logstasher 1.0.0.rc3 → 1.0.0.rc4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de357b73d80ace9f66dec3772501f39485116454
4
- data.tar.gz: abdf933ca237337395477d5374631b2bceb11571
3
+ metadata.gz: 1da4bf654fde44e013c54012909145df5a0bcf59
4
+ data.tar.gz: 21a9cddde75b6ceedad8dcc02f27c269a1d52562
5
5
  SHA512:
6
- metadata.gz: 633cb72fb229d8a8423ef2a7dc7b89e96d6420d406a94992e6d303fd73f068b66cbf8554c30fe6970921183c0b8a26719344bcf24f6d93b7a69b77c5766f86dd
7
- data.tar.gz: 80bde9a5868c345cf24487cf15e2323f34884daa30391ec23a9809aea3f8c4f35f819894b9278819607a2ea315d35b6b0758c276599022a3c92054d912385982
6
+ metadata.gz: da02d119cab4da5ebcf20030a60a6754881c435217c1018797a0e2158d8ce9a492b76c3d51d1f9b4a02eb633c0f1bd8e1805c04839599a4a5d0ddb8e0a057881
7
+ data.tar.gz: 85ef7becae5957c2da39587d141b652ed5d874c0e36a5fcdf31fe7831de650d3c51fc88b52838705fbbf9fa5ebe143c9abda4895d89d1974887e6562a41d27fc
@@ -1,23 +1,26 @@
1
+ require 'logstasher/device'
1
2
  require 'redis'
2
3
 
3
4
  module LogStasher
4
5
  module Device
5
6
  class Redis
7
+ include ::LogStasher::Device
6
8
 
7
9
  attr_reader :options, :redis
8
10
 
9
11
  def initialize(options = {})
10
- @options = default_options.merge(options)
12
+ @options = default_options.merge(stringify_keys(options))
13
+
11
14
  validate_options
12
15
  configure_redis
13
16
  end
14
17
 
15
18
  def data_type
16
- options[:data_type]
19
+ options['data_type']
17
20
  end
18
21
 
19
22
  def key
20
- options[:key]
23
+ options['key']
21
24
  end
22
25
 
23
26
  def redis_options
@@ -51,12 +54,12 @@ module LogStasher
51
54
  end
52
55
 
53
56
  def default_options
54
- { key: 'logstash', data_type: 'list' }
57
+ { 'key' => 'logstash', 'data_type' => 'list' }
55
58
  end
56
59
 
57
60
  def validate_options
58
- unless ['list', 'channel'].include?(options[:data_type])
59
- fail 'Expected :data_type to be either "list" or "channel"'
61
+ unless ['list', 'channel'].include?(options['data_type'])
62
+ fail 'Expected data_type to be either "list" or "channel"'
60
63
  end
61
64
  end
62
65
  end
@@ -1,18 +1,22 @@
1
1
  # inspired by [lumberjack](https://github.com/bdurand/lumberjack_syslog_device)
2
2
 
3
+ require 'logstasher/device'
3
4
  require 'syslog'
4
5
  require 'thread'
5
6
 
6
7
  module LogStasher
7
8
  module Device
8
9
  class Syslog
10
+ include ::LogStasher::Device
9
11
 
10
12
  SEMAPHORE = Mutex.new
11
13
 
12
14
  attr_reader :options
13
15
 
14
16
  def initialize(options = {})
15
- @options = parse_options(default_options.merge(options))
17
+ raw_options = default_options.merge(stringify_keys(options))
18
+
19
+ @options = parse_options(raw_options)
16
20
  @closed = false
17
21
  end
18
22
 
@@ -29,19 +33,19 @@ module LogStasher
29
33
  end
30
34
 
31
35
  def facility
32
- options[:facility]
36
+ options['facility']
33
37
  end
34
38
 
35
39
  def flags
36
- options[:flags]
40
+ options['flags']
37
41
  end
38
42
 
39
43
  def identity
40
- options[:identity]
44
+ options['identity']
41
45
  end
42
46
 
43
47
  def priority
44
- options[:priority]
48
+ options['priority']
45
49
  end
46
50
 
47
51
  def write(log)
@@ -56,10 +60,10 @@ module LogStasher
56
60
 
57
61
  def default_options
58
62
  {
59
- :identity => 'logstasher',
60
- :facility => ::Syslog::LOG_LOCAL0,
61
- :priority => ::Syslog::LOG_INFO,
62
- :flags => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
63
+ 'identity' => 'logstasher',
64
+ 'facility' => ::Syslog::LOG_LOCAL0,
65
+ 'priority' => ::Syslog::LOG_INFO,
66
+ 'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
63
67
  }
64
68
  end
65
69
 
@@ -75,9 +79,9 @@ module LogStasher
75
79
  end
76
80
 
77
81
  def parse_options(options)
78
- options[:facility] = parse_option(options[:facility])
79
- options[:priority] = parse_option(options[:priority])
80
- options[:flags] = parse_option(options[:flags])
82
+ options['facility'] = parse_option(options['facility'])
83
+ options['priority'] = parse_option(options['priority'])
84
+ options['flags'] = parse_option(options['flags'])
81
85
  options
82
86
  end
83
87
 
@@ -1,21 +1,27 @@
1
1
  module LogStasher
2
2
  module Device
3
3
  def self.factory(config)
4
- config = config.dup
5
- type = config.delete(:type) or fail ArgumentError, "No :type given"
4
+ config = stringify_keys(config)
5
+ type = config.delete('type') or fail ArgumentError, 'No "type" given'
6
6
 
7
7
  case type
8
- when "redis", :redis then
9
- require "logstasher/device/redis"
10
-
8
+ when 'redis', :redis then
9
+ require 'logstasher/device/redis'
11
10
  ::LogStasher::Device::Redis.new(config)
12
11
  when "syslog", :syslog then
13
- require "logstasher/device/syslog"
14
-
12
+ require 'logstasher/device/syslog'
15
13
  ::LogStasher::Device::Syslog.new(config)
16
14
  else
17
15
  fail ArgumentError, "Unknown type: #{type}"
18
16
  end
19
17
  end
18
+
19
+ def stringify_keys(hash)
20
+ hash.inject({}) do |stringified_hash, (key, value)|
21
+ stringified_hash[key.to_s] = value
22
+ stringified_hash
23
+ end
24
+ end
25
+ module_function :stringify_keys
20
26
  end
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "1.0.0.rc3"
2
+ VERSION = "1.0.0.rc4"
3
3
  end
@@ -7,8 +7,8 @@ describe LogStasher::Device::Redis do
7
7
  let(:redis_mock) { double('Redis') }
8
8
 
9
9
  let(:default_options) {{
10
- key: 'logstash',
11
- data_type: 'list'
10
+ 'key' => 'logstash',
11
+ 'data_type' => 'list'
12
12
  }}
13
13
 
14
14
  it 'has default options' do
@@ -22,9 +22,9 @@ describe LogStasher::Device::Redis do
22
22
  end
23
23
 
24
24
  it 'assumes unknown options are for redis' do
25
- ::Redis.should_receive(:new).with(hash_including(db: '0'))
25
+ ::Redis.should_receive(:new).with(hash_including('db' => '0'))
26
26
  device = LogStasher::Device::Redis.new(db: '0')
27
- device.redis_options.should eq(db: '0')
27
+ device.redis_options.should eq('db' => '0')
28
28
  end
29
29
 
30
30
  it 'has a key' do
@@ -5,10 +5,10 @@ require 'logstasher/device/syslog'
5
5
  describe LogStasher::Device::Syslog do
6
6
 
7
7
  let(:default_options) {{
8
- :identity => 'logstasher',
9
- :facility => ::Syslog::LOG_LOCAL0,
10
- :priority => ::Syslog::LOG_INFO,
11
- :flags => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
8
+ 'identity' => 'logstasher',
9
+ 'facility' => ::Syslog::LOG_LOCAL0,
10
+ 'priority' => ::Syslog::LOG_INFO,
11
+ 'flags' => ::Syslog::LOG_PID | ::Syslog::LOG_CONS
12
12
  }}
13
13
 
14
14
  before { ::Syslog.stub(:log) }
@@ -9,15 +9,24 @@ describe LogStasher::Device do
9
9
  it "expects a type" do
10
10
  expect {
11
11
  ::LogStasher::Device.factory(:no => "type given")
12
- }.to raise_error(ArgumentError, "No :type given")
12
+ }.to raise_error(ArgumentError, 'No "type" given')
13
13
  end
14
14
 
15
15
  it "forwards configuration options to the device" do
16
16
  ::LogStasher::Device::Redis.should_receive(:new).with(
17
- :options => "other", :than => "type"
17
+ 'options' => "other", 'than' => "type"
18
18
  )
19
19
  ::LogStasher::Device.factory(
20
- :type => 'redis', :options => 'other', :than => "type"
20
+ 'type' => 'redis', 'options' => 'other', :than => "type"
21
+ )
22
+ end
23
+
24
+ it "accepts symbolized configuration keys" do
25
+ ::LogStasher::Device::Redis.should_receive(:new).with(
26
+ 'options' => "other", 'than' => "type"
27
+ )
28
+ ::LogStasher::Device.factory(
29
+ :type => "redis", :options => "other", :than => "type"
21
30
  )
22
31
  end
23
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md-logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Christensen