logger_facade 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/logger_facade/middleware/rack.rb +13 -1
- data/lib/logger_facade/plugins/airbrake.rb +19 -28
- data/lib/logger_facade/version.rb +1 -1
- data/spec/unit/middleware/rack_spec.rb +27 -1
- data/spec/unit/plugins/airbrake_spec.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23cc1584b5cfa42c103b970633ce4ae8b0a53690
|
4
|
+
data.tar.gz: 2886973542c5e009e047e29c7c4d150e6a77d9b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c9fd2d2e1e416cc28da978ba219c6ff3c4202c8f99a8acb6aa41df8a15d1b1c3e64d007eb78ed18ec2e2846baa3bd037e9ca60c71a8b5bd0d0f7281a54fe616
|
7
|
+
data.tar.gz: a18d4667ceb7cd90e2d9b323ab0c17c4f96299a1018a9f58b1c5ff883f52e9fe47f11fbf70cda146f9626830c54362eb78e445136e68decc53d57454c69f4020
|
data/Gemfile.lock
CHANGED
@@ -19,7 +19,8 @@ module LoggerFacade::Middleware
|
|
19
19
|
metadata["bytes"],
|
20
20
|
metadata["request_time"] ]
|
21
21
|
|
22
|
-
|
22
|
+
severity = get_severity(metadata["response"])
|
23
|
+
@logger.send(severity, msg, metadata)
|
23
24
|
end
|
24
25
|
|
25
26
|
def get_metadata(env, status, header, began_at)
|
@@ -39,5 +40,16 @@ module LoggerFacade::Middleware
|
|
39
40
|
}
|
40
41
|
end
|
41
42
|
|
43
|
+
def get_severity(status)
|
44
|
+
status = status.to_i
|
45
|
+
if status >= 400 and status < 500
|
46
|
+
:warn
|
47
|
+
elsif status >= 500
|
48
|
+
:error
|
49
|
+
else
|
50
|
+
:info
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
42
54
|
end
|
43
55
|
end
|
@@ -2,21 +2,14 @@ require 'airbrake'
|
|
2
2
|
|
3
3
|
module LoggerFacade::Plugins
|
4
4
|
|
5
|
-
class Airbrake
|
5
|
+
class Airbrake < Base
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :environment
|
8
8
|
|
9
9
|
def initialize(environment = nil)
|
10
|
-
|
10
|
+
super("LoggerFacade::Plugins::Airbrake", { level: :error })
|
11
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
|
12
|
+
set_default_airbrake_config
|
20
13
|
end
|
21
14
|
|
22
15
|
def configure(&block)
|
@@ -25,27 +18,17 @@ module LoggerFacade::Plugins
|
|
25
18
|
end
|
26
19
|
end
|
27
20
|
|
28
|
-
|
29
|
-
false
|
30
|
-
end
|
31
|
-
|
32
|
-
def trace(logger, message)
|
33
|
-
# do nothing
|
34
|
-
end
|
21
|
+
protected
|
35
22
|
|
36
|
-
def
|
37
|
-
|
38
|
-
end
|
23
|
+
def log(log_level, message, logger, metadata)
|
24
|
+
return unless is_level_active(log_level)
|
39
25
|
|
40
|
-
|
41
|
-
# do nothing
|
26
|
+
notify(logger, message, metadata)
|
42
27
|
end
|
43
28
|
|
44
|
-
|
45
|
-
# do nothing
|
46
|
-
end
|
29
|
+
private
|
47
30
|
|
48
|
-
def
|
31
|
+
def notify(logger, message, metadata)
|
49
32
|
return unless valid_config
|
50
33
|
|
51
34
|
if message.is_a? Exception
|
@@ -55,7 +38,15 @@ module LoggerFacade::Plugins
|
|
55
38
|
end
|
56
39
|
end
|
57
40
|
|
58
|
-
|
41
|
+
def set_default_airbrake_config
|
42
|
+
::Airbrake.configure do |config|
|
43
|
+
config.host = nil
|
44
|
+
config.port = 80
|
45
|
+
config.secure = config.port == 443
|
46
|
+
config.async = true
|
47
|
+
config.development_environments = %w(development test)
|
48
|
+
end
|
49
|
+
end
|
59
50
|
|
60
51
|
def valid_config
|
61
52
|
config = ::Airbrake.configuration
|
@@ -45,7 +45,33 @@ describe LoggerFacade::Middleware::Rack do
|
|
45
45
|
Rack::MockRequest.new(described_class.new(app)).get("/path?q=true")
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
|
+
context 'severity' do
|
50
|
+
|
51
|
+
it "log 200 status to info" do
|
52
|
+
expect(logger).to receive(:info)
|
53
|
+
Rack::MockRequest.new(described_class.new(app)).get("/path")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "log 300 status to info" do
|
57
|
+
expect(logger).to receive(:info)
|
58
|
+
Rack::MockRequest.new(described_class.new(app)).get("/path")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "log 400 status to warn" do
|
62
|
+
expect(logger).to receive(:warn)
|
63
|
+
app = -> (env) { [400, env, "app"] }
|
64
|
+
Rack::MockRequest.new(described_class.new(app)).get("/path")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "log 500 status to error" do
|
68
|
+
expect(logger).to receive(:error)
|
69
|
+
app = -> (env) { [500, env, "app"] }
|
70
|
+
Rack::MockRequest.new(described_class.new(app)).get("/path")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
49
75
|
context 'with proper metadata' do
|
50
76
|
|
51
77
|
after do
|
@@ -4,6 +4,8 @@ describe LoggerFacade::Plugins::Airbrake do
|
|
4
4
|
|
5
5
|
subject { described_class.new(:test) }
|
6
6
|
|
7
|
+
let(:message) { "call with message" }
|
8
|
+
|
7
9
|
before :each do
|
8
10
|
|
9
11
|
subject.configure do |c|
|
@@ -39,13 +41,27 @@ describe LoggerFacade::Plugins::Airbrake do
|
|
39
41
|
context("logging in #{level} level") do
|
40
42
|
|
41
43
|
it("doesn't notify") do
|
42
|
-
message = "call with message"
|
43
44
|
expect(::Airbrake).not_to receive(:notify_or_ignore)
|
44
45
|
subject.send(level.to_sym, "name", message)
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
48
49
|
|
50
|
+
context("accepts metadata") do
|
51
|
+
|
52
|
+
it("logging in #{level} level with metadata") do
|
53
|
+
expect(::Airbrake).not_to receive(:notify_or_ignore)
|
54
|
+
subject.send(level.to_sym, "name", message, metadata: { context: "info" })
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
%w(trace debug info warn error).each do |level|
|
62
|
+
|
63
|
+
|
64
|
+
|
49
65
|
end
|
50
66
|
|
51
67
|
context("logging in error level") do
|
@@ -53,7 +69,6 @@ describe LoggerFacade::Plugins::Airbrake do
|
|
53
69
|
context('with message') do
|
54
70
|
|
55
71
|
it("notify") do
|
56
|
-
message = "call with message"
|
57
72
|
expect(::Airbrake).to receive(:notify_or_ignore)
|
58
73
|
.with(hash_including(
|
59
74
|
:error_class => "NAME::LogError",
|
@@ -81,6 +96,11 @@ describe LoggerFacade::Plugins::Airbrake do
|
|
81
96
|
|
82
97
|
end
|
83
98
|
|
99
|
+
it("accepts metadata") do
|
100
|
+
expect(::Airbrake).to receive(:notify_or_ignore)
|
101
|
+
subject.error("name", message, metadata: { context: "information" })
|
102
|
+
end
|
103
|
+
|
84
104
|
end
|
85
105
|
|
86
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logger_facade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Januário
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|