logasm 0.2.0 → 0.2.1

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: dc85c64499598712bb88fae7042b01cb73c2f43f
4
- data.tar.gz: a31ac1cb0489c75c740d52316a72e968672d83b4
3
+ metadata.gz: b3101253198b60ee5b25bb1630c9e921adb38aeb
4
+ data.tar.gz: 6bd9c7299915e79a8e66e435203814055d02975e
5
5
  SHA512:
6
- metadata.gz: 99904786ff29d235df18e6a3752b55c450893ccb07a27d3add9045752fb4694c9ded0eb4f12c324a697daff0f805e1ff50b77c124158226ec5cacd3574350e0f
7
- data.tar.gz: 8fbfe86ee157deb8f2da0b4e1fd8ca352c9e6de499d3ca915a5b763ca2b8ba704bf2935aa68ee19a8dd39c2626fe314c72a7a133b33f8de0d99892d48c13ec15
6
+ metadata.gz: d79512c5dfae753ff1b23afa09d847b4eea76d2c659b496f4b45d1646113af73683c808cb7a756c472dd8eb3befbcf4e2532847180d42512adb9eb8b42db475d
7
+ data.tar.gz: 85187d7037e0df502f3c25e2c792d1769a4583f39d3876534069365eacea671b092dcb56f37f30216dc89c47a4d6a774223a55ec651f36124124b69efdffc177
data/Gemfile.lock CHANGED
@@ -1,26 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logasm (0.2.0)
4
+ logasm (0.2.1)
5
5
  inflecto
6
6
  logstash-event (~> 1.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- amq-protocol (2.0.0)
12
- atomic (1.1.99)
13
- bunny (1.6.3)
14
- amq-protocol (>= 1.9.2)
15
11
  coderay (1.1.0)
16
12
  diff-lcs (1.2.5)
17
- freddy (0.4.1)
18
- bunny (= 1.6.3)
19
- hamster (~> 1.0.1.pre.rc3)
20
- symbolizer
21
- thread (~> 0.2)
22
- hamster (1.0.1.pre.rc3)
23
- atomic (~> 1.1)
24
13
  inflecto (0.0.2)
25
14
  logstash-event (1.2.02)
26
15
  method_source (0.8.2)
@@ -43,15 +32,12 @@ GEM
43
32
  rspec-support (~> 3.3.0)
44
33
  rspec-support (3.3.0)
45
34
  slop (3.6.0)
46
- symbolizer (0.0.1)
47
- thread (0.2.2)
48
35
 
49
36
  PLATFORMS
50
37
  ruby
51
38
 
52
39
  DEPENDENCIES
53
40
  bundler (~> 1.3)
54
- freddy (~> 0.4.1)
55
41
  logasm!
56
42
  pry
57
43
  rake
@@ -12,7 +12,7 @@ require_relative 'rabbitmq_adapter/message_builder'
12
12
  class Logasm
13
13
  module Adapters
14
14
  class RabbitmqAdapter
15
- attr_reader :publisher
15
+ attr_reader :freddy
16
16
 
17
17
  CONFIGURATION_KEYS = [:host, :user, :pass, :port]
18
18
 
@@ -21,15 +21,14 @@ class Logasm
21
21
  logger = Logger.new(STDOUT)
22
22
  @queue = arguments.fetch(:queue, 'logstash-queue')
23
23
  @level = level
24
-
25
24
  @message_builder = MessageBuilder.new(service)
26
- @freddy = Freddy.build(logger, config)
25
+ @freddy = Freddy.build(logger, config.merge({recover_from_connection_close: true}))
27
26
  end
28
27
 
29
28
  def log(level, metadata = {})
30
29
  if meets_threshold?(level)
31
30
  message = @message_builder.build_message metadata, level
32
- @freddy.deliver @queue, metadata
31
+ deliver_message message
33
32
  end
34
33
  end
35
34
 
@@ -38,6 +37,11 @@ class Logasm
38
37
  def meets_threshold?(level)
39
38
  LOG_LEVELS.index(level.to_s) >= @level
40
39
  end
40
+
41
+ def deliver_message(message)
42
+ @freddy.deliver @queue, message
43
+ rescue Bunny::ConnectionClosedError
44
+ end
41
45
  end
42
46
  end
43
47
  end
data/logasm.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "logasm"
7
- gem.version = '0.2.0'
7
+ gem.version = '0.2.1'
8
8
  gem.authors = ["Salemove"]
9
9
  gem.email = ["support@salemove.com"]
10
10
  gem.description = %q{It's logasmic}
@@ -2,37 +2,31 @@ require 'spec_helper'
2
2
  require_relative '../../lib/logasm/adapters/rabbitmq_adapter'
3
3
 
4
4
  describe Logasm::Adapters::RabbitmqAdapter do
5
- let(:publisher) { adapter.publisher }
6
-
7
- before do
8
- Logasm::Adapters::RabbitmqAdapter::Publisher.any_instance.stub(:initialize).and_return(double)
9
- end
5
+ let(:adapter) { described_class.new(log_level, nil, { host: 'localhost',
6
+ user: 'guest',
7
+ pass: 'guest',
8
+ port: '5672' }
9
+ ) }
10
+ let(:freddy) { adapter.freddy }
10
11
 
11
12
  describe '#log' do
12
13
  context 'when logging a message' do
13
- let(:adapter) { described_class.new(0, nil, { host: 'localhost',
14
- user: 'guest',
15
- pass: 'guest',
16
- port: '5672' }
17
- ) }
14
+ let(:log_level) { 0 }
18
15
 
19
- it 'delegates to publisher' do
20
- expect(publisher).to receive(:publish)
16
+ it 'delegates to freddy' do
17
+ expect(freddy).to receive(:deliver)
21
18
 
22
19
  adapter.log :info, message: 'test'
23
20
  end
24
21
  end
25
22
 
26
23
  context 'when log level is lower than threshold' do
27
- let(:adapter) { described_class.new(3, nil, { host: 'localhost',
28
- user: 'guest',
29
- pass: 'guest',
30
- port: '5672' }
31
- ) }
24
+ let(:log_level) { 3 }
32
25
 
33
26
  it 'does not delegate to freddy' do
34
- expect(publisher).not_to receive(:publish)
35
- adapter.log :info, message: 'test'
27
+ expect(freddy).not_to receive(:deliver)
28
+
29
+ adapter.log :info, message: 'test', a: 'b'
36
30
  end
37
31
  end
38
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-event
@@ -101,7 +101,6 @@ files:
101
101
  - lib/logasm/adapters/logstash_adapter/formatter.rb
102
102
  - lib/logasm/adapters/rabbitmq_adapter.rb
103
103
  - lib/logasm/adapters/rabbitmq_adapter/message_builder.rb
104
- - lib/logasm/adapters/rabbitmq_adapter/publisher.rb
105
104
  - lib/logasm/adapters/stdout_adapter.rb
106
105
  - logasm.gemspec
107
106
  - spec/adapters/logstash_adapter/formatter_spec.rb
@@ -1,20 +0,0 @@
1
- require 'bunny'
2
-
3
- class Logasm
4
- module Adapters
5
- class RabbitmqAdapter
6
- class Publisher
7
- def initialize(queue, config)
8
- connection = Bunny.new("amqp://#{config[:user]}:#{config[:pass]}@#{config[:host]}:#{config[:port]}")
9
- connection.start
10
- @exchange = connection.create_channel.default_exchange
11
- @queue = queue
12
- end
13
-
14
- def publish(message)
15
- @exchange.publish(message.to_json, :routing_key => @queue)
16
- end
17
- end
18
- end
19
- end
20
- end