logger_facade 0.1.0 → 0.2.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: 4d784e71c70884c488dd4ef8ae10ccff6a683be1
4
- data.tar.gz: 3bd33d57268557c45be71199770893c458a68a97
3
+ metadata.gz: 0180ea9d2371adfb7dc9745b2b5c550fada71357
4
+ data.tar.gz: 9969640e45a3c0f9f1be24f52834c9c5f1a37b83
5
5
  SHA512:
6
- metadata.gz: ce943da29d63815307c019927f4d6e1c67347398f9406c2a0fd816fa8d711f265bf637a7b557c9523659aea9d6b86d4fd6d894405fcc78523384daae614ce4da
7
- data.tar.gz: b1968c2095b653bb77b20938b0080f54176ab7da012b8b86dd745318470efafa36c43916cfba21de10c795426858a101b08ba75fcb829246bfdcd55ad84acbd4
6
+ metadata.gz: 20a421d2ff5f652551b050047652034c374974eca980c68787815f4910acefb7d79032d033353ab64e1dbadeb80612e044c259fdb4da0a3c879fae971df7f8cc
7
+ data.tar.gz: f15e7d566a1b471521260c54d4555a1a82ff6b48d9cbfce7c6aceee9112ed7e30ccae0e5921911a8963d32aa452365d6dbe6ef18ac31b0c6c04ba8afeaa5c51a
data/Gemfile.lock CHANGED
@@ -1,13 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logger_facade (0.1.0)
4
+ logger_facade (0.2.0)
5
+ airbrake (~> 4.0)
5
6
  hashie (~> 3.2)
7
+ sucker_punch (~> 1.1)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
12
+ airbrake (4.0.0)
13
+ builder
14
+ multi_json
15
+ builder (3.2.2)
10
16
  bump (0.5.0)
17
+ celluloid (0.15.2)
18
+ timers (~> 1.1.0)
11
19
  codeclimate-test-reporter (0.3.0)
12
20
  simplecov (>= 0.7.1, < 1.0.0)
13
21
  coderay (1.1.0)
@@ -39,6 +47,9 @@ GEM
39
47
  simplecov-html (~> 0.8.0)
40
48
  simplecov-html (0.8.0)
41
49
  slop (3.6.0)
50
+ sucker_punch (1.1)
51
+ celluloid (~> 0.15.2)
52
+ timers (1.1.0)
42
53
 
43
54
  PLATFORMS
44
55
  ruby
@@ -1 +1,2 @@
1
1
  require_relative 'plugins/console'
2
+ require_relative 'plugins/airbrake'
@@ -0,0 +1,86 @@
1
+ require 'airbrake'
2
+
3
+ module LoggerFacade::Plugins
4
+
5
+ class Airbrake
6
+
7
+ attr_reader :name, :environment
8
+
9
+ def initialize(environment = nil)
10
+ @name = "LoggerFacade::Plugins::Airbrake"
11
+ @environment = environment.to_s
12
+
13
+ ::Airbrake.configure do |config|
14
+ config.host = nil
15
+ config.port = 80
16
+ config.secure = config.port == 443
17
+ config.async = true
18
+ config.development_environments = %w(development test)
19
+ end
20
+ end
21
+
22
+ def configure(&block)
23
+ ::Airbrake.configure do |config|
24
+ yield config
25
+ end
26
+ end
27
+
28
+ def is_debug
29
+ false
30
+ end
31
+
32
+ def trace(logger, message)
33
+ # do nothing
34
+ end
35
+
36
+ def debug(logger, message)
37
+ # do nothing
38
+ end
39
+
40
+ def info(logger, message)
41
+ # do nothing
42
+ end
43
+
44
+ def warn(logger, message)
45
+ # do nothing
46
+ end
47
+
48
+ def error(logger, message)
49
+ return unless valid_config
50
+
51
+ if message.is_a? Exception
52
+ notify_exception(message, logger)
53
+ else
54
+ notify_error_log(message, logger)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def valid_config
61
+ config = ::Airbrake.configuration
62
+ config.api_key && config.host
63
+ end
64
+
65
+ def notify_error_log(message, logger)
66
+ ::Airbrake.notify_or_ignore(
67
+ :error_class => "#{logger}::LogError",
68
+ :error_message => "#{logger}::LogError: #{message}",
69
+ :backtrace => $@,
70
+ :cgi_data => ENV.to_hash,
71
+ :environment_name => environment
72
+ )
73
+ end
74
+
75
+ def notify_exception(e, logger)
76
+ ::Airbrake.notify_or_ignore(
77
+ e,
78
+ :backtrace => $@,
79
+ :cgi_data => ENV.to_hash,
80
+ :environment_name => environment
81
+ )
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -1,3 +1,3 @@
1
1
  module LoggerFacade
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -31,4 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'bump', '~> 0.5'
32
32
 
33
33
  spec.add_dependency 'hashie', '~> 3.2'
34
+ spec.add_dependency 'airbrake', '~> 4.0'
35
+ # sucker punch is used to use airbrake async
36
+ spec.add_dependency 'sucker_punch', '~> 1.1'
34
37
  end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe LoggerFacade::Plugins::Airbrake do
4
+
5
+ subject { described_class.new(:test) }
6
+
7
+ before :each do
8
+
9
+ subject.configure do |c|
10
+ c.host = "host.test"
11
+ c.api_key = "key.test"
12
+ end
13
+
14
+ end
15
+
16
+ describe('#is_debug') do
17
+
18
+ it('returns false') do
19
+ expect(subject.is_debug).to be false
20
+ end
21
+
22
+ end
23
+
24
+ describe('#configure') do
25
+
26
+ it('overrides Airbrake configurations') do
27
+
28
+ subject.configure do |config|
29
+ config.api_key = "key"
30
+ end
31
+
32
+ expect(::Airbrake.configuration.api_key).to eq("key")
33
+ end
34
+
35
+ end
36
+
37
+ %w(trace debug info warn).each do |level|
38
+
39
+ context("logging in #{level} level") do
40
+
41
+ it("doesn't notify") do
42
+ message = "call with message"
43
+ expect(::Airbrake).not_to receive(:notify_or_ignore)
44
+ subject.send(level.to_sym, "name", message)
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ context("logging in error level") do
52
+
53
+ context('with message') do
54
+
55
+ it("notify") do
56
+ message = "call with message"
57
+ expect(::Airbrake).to receive(:notify_or_ignore)
58
+ .with(hash_including(
59
+ :error_class => "NAME::LogError",
60
+ :error_message => "NAME::LogError: #{message}",
61
+ :backtrace => anything,
62
+ :cgi_data => anything,
63
+ :environment_name=> "test"
64
+ )) { nil }
65
+ subject.error("NAME", message)
66
+ end
67
+ end
68
+
69
+ context('with exception') do
70
+
71
+ it("notify") do
72
+ e = Exception.new 'test notify'
73
+ expect(::Airbrake).to receive(:notify_or_ignore)
74
+ .with(e, hash_including(
75
+ :backtrace => anything,
76
+ :cgi_data => anything,
77
+ :environment_name=> "test"
78
+ )) { nil }
79
+ subject.error("NAME", e)
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger_facade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Januário
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: airbrake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sucker_punch
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.1'
125
153
  description: |-
126
154
  Simple class library to work as logger facade.
127
155
  This simple logger facade allows you to hook plugins to execute logging.
@@ -145,6 +173,7 @@ files:
145
173
  - lib/logger_facade/loggable.rb
146
174
  - lib/logger_facade/manager.rb
147
175
  - lib/logger_facade/plugins.rb
176
+ - lib/logger_facade/plugins/airbrake.rb
148
177
  - lib/logger_facade/plugins/console.rb
149
178
  - lib/logger_facade/version.rb
150
179
  - logger_facade.gemspec
@@ -152,6 +181,7 @@ files:
152
181
  - spec/unit/log_spec.rb
153
182
  - spec/unit/loggable_spec.rb
154
183
  - spec/unit/manager_spec.rb
184
+ - spec/unit/plugins/airbrake_spec.rb
155
185
  - spec/unit/plugins/console_spec.rb
156
186
  homepage: https://github.com/pjanuario/logger-facade-ruby
157
187
  licenses:
@@ -184,4 +214,5 @@ test_files:
184
214
  - spec/unit/log_spec.rb
185
215
  - spec/unit/loggable_spec.rb
186
216
  - spec/unit/manager_spec.rb
217
+ - spec/unit/plugins/airbrake_spec.rb
187
218
  - spec/unit/plugins/console_spec.rb