logstasher 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjdkMjE3MDE0ZWEzMDQ3Y2VkOTdjNjllODg4Y2UzNzZkOTg1Yjc5MA==
4
+ YjQ0MTI1YmFiNDhhZWU4ODczZmQ2MzUwOTJlYzJlY2Q5NmE0MDFjMQ==
5
5
  data.tar.gz: !binary |-
6
- YTcyYTI4MDY1NTY0YjJhMzg3MjlkMTM4NjQ0N2VmNTRmNTJlZGNmNA==
6
+ MGU5ZGIwYWRhYTgwZDUxMDcxNTg1OGNlM2EzMDRkNjA4Yzk4ZDVhNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTEzNmI5ZmU0MTJhZWYzN2IwMzhlMTJhYjc1NGU0OTA3MGQzNWI4Mjc4ODNl
10
- NTU0NGJiMTc3NmNlM2E4ZDliOTMzYmMyYmQ0ZWUxY2E1NWE0ZWJlZWZlNTZl
11
- NTFjZjQxOWIwNzQ0NzhkNzE0NDYyYzg1YWEwYzdmNjBhYWM1MTU=
9
+ YzY2ZGU0NWQxNjk3YjExNjY2YWZlMjQ0MDJhNjBiMjg4YWE3NDUwOTIxZDc2
10
+ OTkzNzk1ZTU0ZDM5MTM1YTE0ZDgyY2MxODZhNTFiNjJlZjIxYjQ3ZTFkYjUy
11
+ ZmFmYTBhNTc3MDIxZjkwYTk5NDMxZjIwNzdiNTZhOGQyOTE4NzY=
12
12
  data.tar.gz: !binary |-
13
- YTllN2NlMzFkNDI4MTNjN2QxNjRhNjI1ZTk5NTAxZjc2ZTYwNDdiODgwZTAz
14
- NDU1MDUwYjM4NTBkZDc1MzlkMzc0MmU1NzQ4MGY3ZDNlMzNjZDliYmM3MWM3
15
- YjgzMmU1MzdkNzM0MTkxNmRiNGNmMjdjZmU5Zjk0MGRhYjU3MmE=
13
+ YWNkNzc5OGEwMDVlN2Y0ZmYwMTUyM2U2NTY0NDZhY2ZmNzA3ZjI4M2NhZDIy
14
+ OWVlM2ZjZDVkMjAzYWU1ZjQ1ODI0ZTczYTBjNWRlNThhY2ViNzNiYTBjOGIx
15
+ ODNiZTdlYTg2MDVlMjEyN2JiOTM2N2Y3ZGI3YzUwOGU3OTJjNmI=
data/Gemfile CHANGED
@@ -4,11 +4,12 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'rb-fsevent', '~> 0.9'
7
+ gem 'growl'
8
8
  gem 'guard'
9
9
  gem 'guard-rspec'
10
- gem 'growl'
11
- gem 'simplecov', :platforms => :mri_19, :require => false
12
- gem 'rcov', :platforms => :mri_18
13
10
  gem 'rails', "~> #{ENV["RAILS_VERSION"] || "3.2.0"}"
11
+ gem 'rb-fsevent', '~> 0.9'
12
+ gem 'rcov', :platforms => :mri_18
13
+ gem 'redis', :require => false
14
+ gem 'simplecov', :platforms => :mri_19, :require => false
14
15
  end
@@ -0,0 +1,64 @@
1
+ require 'redis'
2
+
3
+ module LogStasher
4
+ module Device
5
+ class Redis
6
+
7
+ attr_reader :options, :redis
8
+
9
+ def initialize(options = {})
10
+ @options = default_options.merge(options)
11
+ validate_options
12
+ configure_redis
13
+ end
14
+
15
+ def data_type
16
+ options[:data_type]
17
+ end
18
+
19
+ def key
20
+ options[:key]
21
+ end
22
+
23
+ def redis_options
24
+ unless @redis_options
25
+ default_keys = default_options.keys
26
+ @redis_options = options.select { |k, v| !default_keys.include?(k) }
27
+ end
28
+
29
+ @redis_options
30
+ end
31
+
32
+ def write(log)
33
+ case data_type
34
+ when 'list'
35
+ redis.rpush(key, log)
36
+ when 'channel'
37
+ redis.publish(key, log)
38
+ else
39
+ fail "Unknown data type #{data_type}"
40
+ end
41
+ end
42
+
43
+ def close
44
+ redis.quit
45
+ end
46
+
47
+ private
48
+
49
+ def configure_redis
50
+ @redis = ::Redis.new(redis_options)
51
+ end
52
+
53
+ def default_options
54
+ { key: 'logstash', data_type: 'list' }
55
+ end
56
+
57
+ def validate_options
58
+ unless ['list', 'channel'].include?(options[:data_type])
59
+ fail 'Expected :data_type to be either "list" or "channel"'
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module LogStasher
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ require 'logstasher/device/redis'
4
+
5
+ describe LogStasher::Device::Redis do
6
+
7
+ let(:redis_mock) { double('Redis') }
8
+
9
+ let(:default_options) {{
10
+ key: 'logstash',
11
+ data_type: 'list'
12
+ }}
13
+
14
+ it 'has default options' do
15
+ device = LogStasher::Device::Redis.new
16
+ device.options.should eq(default_options)
17
+ end
18
+
19
+ it 'creates a redis instance' do
20
+ ::Redis.should_receive(:new).with({})
21
+ LogStasher::Device::Redis.new()
22
+ end
23
+
24
+ it 'assumes unknown options are for redis' do
25
+ ::Redis.should_receive(:new).with(hash_including(db: '0'))
26
+ device = LogStasher::Device::Redis.new(db: '0')
27
+ device.redis_options.should eq(db: '0')
28
+ end
29
+
30
+ it 'has a key' do
31
+ device = LogStasher::Device::Redis.new(key: 'the_key')
32
+ device.key.should eq 'the_key'
33
+ end
34
+
35
+ it 'has a data_type' do
36
+ device = LogStasher::Device::Redis.new(data_type: 'channel')
37
+ device.data_type.should eq 'channel'
38
+ end
39
+
40
+ it 'does not allow unsupported data types' do
41
+ expect {
42
+ device = LogStasher::Device::Redis.new(data_type: 'blargh')
43
+ }.to raise_error()
44
+ end
45
+
46
+ it 'quits the redis connection on #close' do
47
+ device = LogStasher::Device::Redis.new
48
+ device.redis.should_receive(:quit)
49
+ device.close
50
+ end
51
+
52
+ it 'works as a logger device' do
53
+ device = LogStasher::Device::Redis.new
54
+ device.should_receive(:write).with('blargh')
55
+ logger = Logger.new(device)
56
+ logger << 'blargh'
57
+ end
58
+
59
+ describe '#write' do
60
+ it "rpushes logs onto a list" do
61
+ device = LogStasher::Device::Redis.new(data_type: 'list')
62
+ device.redis.should_receive(:rpush).with('logstash', 'the log')
63
+ device.write('the log')
64
+ end
65
+
66
+ it "rpushes logs onto a custom key" do
67
+ device = LogStasher::Device::Redis.new(data_type: 'list', key: 'custom')
68
+ device.redis.should_receive(:rpush).with('custom', 'the log')
69
+ device.write('the log')
70
+ end
71
+
72
+ it "publishes logs onto a channel" do
73
+ device = LogStasher::Device::Redis.new(data_type: 'channel', key: 'custom')
74
+ device.redis.should_receive(:publish).with('custom', 'the log')
75
+ device.write('the log')
76
+ end
77
+ end
78
+
79
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstasher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shadab Ahmed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -81,12 +81,14 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/logstasher.rb
84
+ - lib/logstasher/device/redis.rb
84
85
  - lib/logstasher/log_subscriber.rb
85
86
  - lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb
86
87
  - lib/logstasher/rails_ext/rack/logger.rb
87
88
  - lib/logstasher/railtie.rb
88
89
  - lib/logstasher/version.rb
89
90
  - logstasher.gemspec
91
+ - spec/lib/logstasher/device/redis_spec.rb
90
92
  - spec/lib/logstasher/log_subscriber_spec.rb
91
93
  - spec/lib/logstasher_spec.rb
92
94
  - spec/spec_helper.rb
@@ -114,6 +116,7 @@ signing_key:
114
116
  specification_version: 4
115
117
  summary: Awesome rails logs
116
118
  test_files:
119
+ - spec/lib/logstasher/device/redis_spec.rb
117
120
  - spec/lib/logstasher/log_subscriber_spec.rb
118
121
  - spec/lib/logstasher_spec.rb
119
122
  - spec/spec_helper.rb