logasm 0.5.0 → 0.5.2

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: 687158e874206e3955b57df05548074eec12ce28
4
- data.tar.gz: 66ac91d1af8c3ecce4c2b8314b505d1578d6ec5f
3
+ metadata.gz: a9ade685a2af887a257340ed2dab29d09abceb8a
4
+ data.tar.gz: 1b5671acbe54ce055156a496a481ce524270a3b1
5
5
  SHA512:
6
- metadata.gz: 7534c016b81f0716725577489ba398b870dcb792049872268838600700ff817416b6a88ed0045575bff55f3f083d4c432a6849eb31f48e24a44a17d27d0c47bc
7
- data.tar.gz: b338dd4d8133b1f9cf18eaf4da39952b2346003c8299b9fc00c47978f497def27e4dddfcecdf69ecd7a1bb5c2bf0c628176f43b34d4621ab717a961aaf5f7382
6
+ metadata.gz: d5a206ab30b603af225468e52195c9ef3e87b42d2bf71cd7794ebe98b3eabe952fe9df666d1a1618915a379e7ac0559fba7e5543d6dbf5d1de1574157fb3ce83
7
+ data.tar.gz: b363d87991efde13a6ea82b82e673536aa83179ad1f103f1d8098fe00222bf2b9e321b5a9bc59cf3ce0b9fbf451ec53eeb11c5ebfd8b3f11c21265d9a363d88e
@@ -1,8 +1,8 @@
1
1
  begin
2
- require 'freddy'
2
+ require 'bunny'
3
3
  rescue LoadError => e
4
- raise unless e.message =~ /freddy/
5
- exception = e.exception('To use RabbitMQ adapter for logging, please install freddy!')
4
+ raise unless e.message =~ /bunny/
5
+ exception = e.exception('To use RabbitMQ adapter for logging, please install bunny!')
6
6
  exception.set_backtrace(e.backtrace)
7
7
  raise exception
8
8
  end
@@ -10,17 +10,16 @@ end
10
10
  class Logasm
11
11
  module Adapters
12
12
  class RabbitmqAdapter
13
- attr_reader :freddy
14
-
15
13
  CONFIGURATION_KEYS = [:host, :hosts, :user, :pass, :port]
16
14
 
15
+ attr_reader :bunny
16
+
17
17
  def initialize(level, service_name, arguments = {})
18
18
  config = arguments.select { |key, value| CONFIGURATION_KEYS.include?(key) }
19
- logger = NullLogger.new
20
- @queue = arguments.fetch(:queue, 'logstash-queue')
21
19
  @level = level
22
20
  @service_name = service_name
23
- @freddy = Freddy.build(logger, config.merge({recover_from_connection_close: true}))
21
+ @bunny = Bunny.new(config)
22
+ @queue_name = arguments.fetch(:queue, 'logstash-queue')
24
23
  end
25
24
 
26
25
  def log(level, metadata = {})
@@ -57,9 +56,20 @@ class Logasm
57
56
  end
58
57
 
59
58
  def deliver_message(message)
60
- @freddy.deliver @queue, message
59
+ exchange.publish(JSON.dump(message), {
60
+ content_type: 'application/json',
61
+ routing_key: @queue_name
62
+ })
61
63
  rescue Bunny::ConnectionClosedError
62
64
  end
65
+
66
+ def exchange
67
+ @exchange ||= begin
68
+ bunny.start
69
+ channel = bunny.create_channel
70
+ channel.default_exchange
71
+ end
72
+ end
63
73
  end
64
74
  end
65
75
  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.5.0'
7
+ gem.version = '0.5.2'
8
8
  gem.authors = ["Salemove"]
9
9
  gem.email = ["support@salemove.com"]
10
10
  gem.description = %q{It's logasmic}
@@ -20,5 +20,5 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_development_dependency "bundler", "~> 1.3"
22
22
  gem.add_development_dependency "rake"
23
- gem.add_development_dependency "freddy", "~> 0.4.1"
23
+ gem.add_development_dependency "bunny"
24
24
  end
@@ -7,10 +7,12 @@ describe Logasm::Adapters::RabbitmqAdapter do
7
7
  host: 'localhost', user: 'guest', pass: 'guest', port: '5672'
8
8
  })
9
9
  end
10
- let(:freddy) { adapter.freddy }
10
+ let(:bunny) { double(start: nil, create_channel: channel) }
11
+ let(:channel) { double(default_exchange: exchange) }
12
+ let(:exchange) { spy }
11
13
 
12
14
  before do
13
- allow(Freddy).to receive(:build) { FreddyMock.new }
15
+ allow(Bunny).to receive(:new) { bunny }
14
16
  end
15
17
 
16
18
  describe '#log' do
@@ -20,15 +22,10 @@ describe Logasm::Adapters::RabbitmqAdapter do
20
22
  it 'delegates to freddy' do
21
23
  adapter.log :info, message: 'test'
22
24
 
23
- expect(freddy.deliveries.size).to eq(1)
24
-
25
- queue, event = freddy.deliveries[0]
26
- expect(queue).to eq('logstash-queue')
27
- expect(event[:message]).to eq('test')
28
- expect(event[:application]).to eq('test_service')
29
- expect(event[:level]).to eq('info')
30
- expect(event[:host]).to be_a(String)
31
- expect(event[:@timestamp]).to match(/\d{4}-\d{2}-\d{2}T.*/)
25
+ expect(exchange).to have_received(:publish).with(
26
+ match(/{"@timestamp":"\d{4}-\d{2}-\d{2}T.*","host":"\w+","message":"test","application":"test_service","level":"info"}/),
27
+ { content_type: 'application/json', routing_key: 'logstash-queue' }
28
+ )
32
29
  end
33
30
  end
34
31
 
@@ -36,9 +33,9 @@ describe Logasm::Adapters::RabbitmqAdapter do
36
33
  let(:log_level) { 3 }
37
34
 
38
35
  it 'does not delegate to freddy' do
39
- expect(freddy).not_to receive(:deliver)
40
-
41
36
  adapter.log :info, message: 'test', a: 'b'
37
+
38
+ expect(exchange).to_not have_received(:publish)
42
39
  end
43
40
  end
44
41
  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.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: freddy
56
+ name: bunny
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.4.1
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.4.1
68
+ version: '0'
69
69
  description: It's logasmic
70
70
  email:
71
71
  - support@salemove.com
@@ -100,7 +100,6 @@ files:
100
100
  - spec/preprocessors/blacklist_spec.rb
101
101
  - spec/preprocessors/whitelist_spec.rb
102
102
  - spec/spec_helper.rb
103
- - spec/support/freddy_mock.rb
104
103
  - spec/support/implement_interface.rb
105
104
  - spec/utils_spec.rb
106
105
  homepage:
@@ -136,6 +135,5 @@ test_files:
136
135
  - spec/preprocessors/blacklist_spec.rb
137
136
  - spec/preprocessors/whitelist_spec.rb
138
137
  - spec/spec_helper.rb
139
- - spec/support/freddy_mock.rb
140
138
  - spec/support/implement_interface.rb
141
139
  - spec/utils_spec.rb
@@ -1,11 +0,0 @@
1
- class FreddyMock
2
- attr_reader :deliveries
3
-
4
- def initialize
5
- @deliveries = []
6
- end
7
-
8
- def deliver(queue, params)
9
- @deliveries << [queue, params]
10
- end
11
- end