loga 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +157 -0
- data/.codeclimate.yml +4 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +13 -8
- data/Appraisals +16 -6
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -1
- data/Guardfile +8 -6
- data/README.md +1 -0
- data/Rakefile +1 -1
- data/gemfiles/rails32.gemfile +1 -2
- data/gemfiles/rails40.gemfile +1 -2
- data/gemfiles/rails42.gemfile +11 -0
- data/gemfiles/rails50.gemfile +1 -2
- data/gemfiles/rails52.gemfile +11 -0
- data/gemfiles/sinatra14.gemfile +1 -2
- data/gemfiles/unit.gemfile +1 -2
- data/lib/loga.rb +4 -2
- data/lib/loga/configuration.rb +5 -5
- data/lib/loga/ext/rails/rack/debug_exceptions.rb +1 -2
- data/lib/loga/formatters/simple_formatter.rb +1 -1
- data/lib/loga/log_subscribers/action_mailer.rb +59 -0
- data/lib/loga/rack/logger.rb +1 -1
- data/lib/loga/rack/request_id.rb +2 -2
- data/lib/loga/railtie.rb +22 -9
- data/lib/loga/version.rb +1 -1
- data/loga.gemspec +9 -8
- data/spec/fixtures/README.md +23 -3
- data/spec/fixtures/rails32.rb +79 -0
- data/spec/fixtures/rails40.rb +80 -0
- data/spec/fixtures/rails42.rb +80 -0
- data/spec/fixtures/rails50.rb +80 -0
- data/spec/fixtures/rails52.rb +80 -0
- data/spec/integration/rails/action_mailer_spec.rb +63 -0
- data/spec/integration/rails/railtie_spec.rb +15 -0
- data/spec/integration/sinatra_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -8
- data/spec/support/gethostname_shared.rb +7 -0
- data/spec/support/helpers.rb +0 -4
- data/spec/unit/loga/configuration_spec.rb +4 -4
- data/spec/unit/loga/formatters/gelf_formatter_spec.rb +1 -1
- data/spec/unit/loga/formatters/simple_formatter_spec.rb +2 -2
- data/spec/unit/loga/log_subscribers/action_mailer_spec.rb +69 -0
- data/spec/unit/loga/rack/logger_spec.rb +1 -1
- data/spec/unit/loga_spec.rb +1 -1
- metadata +71 -225
- data/circle.yml +0 -23
- data/spec/fixtures/rails32/Rakefile +0 -7
- data/spec/fixtures/rails32/app/controllers/application_controller.rb +0 -28
- data/spec/fixtures/rails32/app/helpers/application_helper.rb +0 -2
- data/spec/fixtures/rails32/app/views/layouts/application.html.erb +0 -14
- data/spec/fixtures/rails32/app/views/user.html.erb +0 -1
- data/spec/fixtures/rails32/config.ru +0 -4
- data/spec/fixtures/rails32/config/application.rb +0 -71
- data/spec/fixtures/rails32/config/boot.rb +0 -6
- data/spec/fixtures/rails32/config/environment.rb +0 -5
- data/spec/fixtures/rails32/config/environments/development.rb +0 -26
- data/spec/fixtures/rails32/config/environments/production.rb +0 -50
- data/spec/fixtures/rails32/config/environments/test.rb +0 -35
- data/spec/fixtures/rails32/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/fixtures/rails32/config/initializers/inflections.rb +0 -15
- data/spec/fixtures/rails32/config/initializers/mime_types.rb +0 -5
- data/spec/fixtures/rails32/config/initializers/secret_token.rb +0 -7
- data/spec/fixtures/rails32/config/initializers/session_store.rb +0 -8
- data/spec/fixtures/rails32/config/initializers/wrap_parameters.rb +0 -10
- data/spec/fixtures/rails32/config/locales/en.yml +0 -5
- data/spec/fixtures/rails32/config/routes.rb +0 -64
- data/spec/fixtures/rails32/public/404.html +0 -26
- data/spec/fixtures/rails32/public/422.html +0 -26
- data/spec/fixtures/rails32/public/500.html +0 -25
- data/spec/fixtures/rails32/public/favicon.ico +0 -0
- data/spec/fixtures/rails32/public/index.html +0 -241
- data/spec/fixtures/rails32/public/robots.txt +0 -5
- data/spec/fixtures/rails32/script/rails +0 -6
- data/spec/fixtures/rails40/Rakefile +0 -6
- data/spec/fixtures/rails40/app/controllers/application_controller.rb +0 -30
- data/spec/fixtures/rails40/app/helpers/application_helper.rb +0 -2
- data/spec/fixtures/rails40/app/views/layouts/application.html.erb +0 -14
- data/spec/fixtures/rails40/app/views/user.html.erb +0 -1
- data/spec/fixtures/rails40/bin/bundle +0 -3
- data/spec/fixtures/rails40/bin/rails +0 -4
- data/spec/fixtures/rails40/bin/rake +0 -4
- data/spec/fixtures/rails40/config.ru +0 -4
- data/spec/fixtures/rails40/config/application.rb +0 -37
- data/spec/fixtures/rails40/config/boot.rb +0 -4
- data/spec/fixtures/rails40/config/environment.rb +0 -5
- data/spec/fixtures/rails40/config/environments/development.rb +0 -24
- data/spec/fixtures/rails40/config/environments/production.rb +0 -65
- data/spec/fixtures/rails40/config/environments/test.rb +0 -39
- data/spec/fixtures/rails40/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/fixtures/rails40/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/fixtures/rails40/config/initializers/inflections.rb +0 -16
- data/spec/fixtures/rails40/config/initializers/mime_types.rb +0 -5
- data/spec/fixtures/rails40/config/initializers/secret_token.rb +0 -12
- data/spec/fixtures/rails40/config/initializers/session_store.rb +0 -3
- data/spec/fixtures/rails40/config/initializers/wrap_parameters.rb +0 -9
- data/spec/fixtures/rails40/config/locales/en.yml +0 -23
- data/spec/fixtures/rails40/config/routes.rb +0 -62
- data/spec/fixtures/rails40/public/404.html +0 -58
- data/spec/fixtures/rails40/public/422.html +0 -58
- data/spec/fixtures/rails40/public/500.html +0 -57
- data/spec/fixtures/rails40/public/favicon.ico +0 -0
- data/spec/fixtures/rails40/public/robots.txt +0 -5
- data/spec/fixtures/rails50/Rakefile +0 -6
- data/spec/fixtures/rails50/app/controllers/application_controller.rb +0 -28
- data/spec/fixtures/rails50/app/helpers/application_helper.rb +0 -2
- data/spec/fixtures/rails50/app/views/layouts/application.html.erb +0 -13
- data/spec/fixtures/rails50/app/views/user.html.erb +0 -1
- data/spec/fixtures/rails50/bin/bundle +0 -3
- data/spec/fixtures/rails50/bin/rails +0 -4
- data/spec/fixtures/rails50/bin/rake +0 -4
- data/spec/fixtures/rails50/bin/setup +0 -34
- data/spec/fixtures/rails50/bin/update +0 -29
- data/spec/fixtures/rails50/config.ru +0 -5
- data/spec/fixtures/rails50/config/application.rb +0 -34
- data/spec/fixtures/rails50/config/boot.rb +0 -3
- data/spec/fixtures/rails50/config/cable.yml +0 -9
- data/spec/fixtures/rails50/config/environment.rb +0 -5
- data/spec/fixtures/rails50/config/environments/development.rb +0 -44
- data/spec/fixtures/rails50/config/environments/production.rb +0 -75
- data/spec/fixtures/rails50/config/environments/test.rb +0 -42
- data/spec/fixtures/rails50/config/initializers/application_controller_renderer.rb +0 -6
- data/spec/fixtures/rails50/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/fixtures/rails50/config/initializers/cookies_serializer.rb +0 -5
- data/spec/fixtures/rails50/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/fixtures/rails50/config/initializers/inflections.rb +0 -16
- data/spec/fixtures/rails50/config/initializers/mime_types.rb +0 -4
- data/spec/fixtures/rails50/config/initializers/new_framework_defaults.rb +0 -21
- data/spec/fixtures/rails50/config/initializers/session_store.rb +0 -3
- data/spec/fixtures/rails50/config/initializers/wrap_parameters.rb +0 -9
- data/spec/fixtures/rails50/config/locales/en.yml +0 -23
- data/spec/fixtures/rails50/config/puma.rb +0 -47
- data/spec/fixtures/rails50/config/routes.rb +0 -9
- data/spec/fixtures/rails50/config/secrets.yml +0 -23
- data/spec/fixtures/rails50/public/404.html +0 -67
- data/spec/fixtures/rails50/public/422.html +0 -67
- data/spec/fixtures/rails50/public/500.html +0 -66
- data/spec/fixtures/rails50/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/fixtures/rails50/public/apple-touch-icon.png +0 -0
- data/spec/fixtures/rails50/public/favicon.ico +0 -0
- data/spec/fixtures/rails50/public/robots.txt +0 -5
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'action_controller/railtie'
|
2
|
+
require 'action_mailer/railtie'
|
3
|
+
|
4
|
+
Bundler.require(*Rails.groups)
|
5
|
+
|
6
|
+
STREAM = StringIO.new unless defined?(STREAM)
|
7
|
+
|
8
|
+
class Dummy < Rails::Application
|
9
|
+
config.eager_load = true
|
10
|
+
config.filter_parameters += [:password]
|
11
|
+
config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24'
|
12
|
+
config.session_store :cookie_store, key: '_rails50_session'
|
13
|
+
|
14
|
+
config.log_tags = [:uuid, 'TEST_TAG']
|
15
|
+
config.loga = {
|
16
|
+
device: STREAM,
|
17
|
+
host: 'bird.example.com',
|
18
|
+
service_name: 'hello_world_app',
|
19
|
+
service_version: '1.0',
|
20
|
+
}
|
21
|
+
config.action_mailer.delivery_method = :test
|
22
|
+
end
|
23
|
+
|
24
|
+
class ApplicationController < ActionController::Base
|
25
|
+
include Rails.application.routes.url_helpers
|
26
|
+
protect_from_forgery with: :null_session
|
27
|
+
|
28
|
+
def ok
|
29
|
+
render plain: 'Hello Rails'
|
30
|
+
end
|
31
|
+
|
32
|
+
def error
|
33
|
+
nil.name
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
render json: params
|
38
|
+
end
|
39
|
+
|
40
|
+
def create
|
41
|
+
render json: params
|
42
|
+
end
|
43
|
+
|
44
|
+
def new
|
45
|
+
redirect_to :ok
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
@id = params[:id]
|
50
|
+
render '/user'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class FakeMailer < ActionMailer::Base
|
55
|
+
default from: 'notifications@example.com'
|
56
|
+
|
57
|
+
def self.send_email
|
58
|
+
basic_mail.deliver_now
|
59
|
+
end
|
60
|
+
|
61
|
+
def basic_mail
|
62
|
+
mail(
|
63
|
+
to: 'user@example.com',
|
64
|
+
subject: 'Welcome to My Awesome Site',
|
65
|
+
body: 'Banana muffin',
|
66
|
+
content_type: 'text/html',
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Dummy.routes.append do
|
72
|
+
get 'ok' => 'application#ok'
|
73
|
+
get 'error' => 'application#error'
|
74
|
+
get 'show' => 'application#show'
|
75
|
+
post 'users' => 'application#create'
|
76
|
+
get 'new' => 'application#new'
|
77
|
+
put 'users/:id' => 'application#update'
|
78
|
+
end
|
79
|
+
|
80
|
+
Dummy.initialize!
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'action_controller/railtie'
|
2
|
+
require 'action_mailer/railtie'
|
3
|
+
|
4
|
+
Bundler.require(*Rails.groups)
|
5
|
+
|
6
|
+
STREAM = StringIO.new unless defined?(STREAM)
|
7
|
+
|
8
|
+
class Dummy < Rails::Application
|
9
|
+
config.eager_load = true
|
10
|
+
config.filter_parameters += [:password]
|
11
|
+
config.secret_key_base = '2624599ca9ab3cf3823626240138a128118a87683bf03ab8f155844c33b3cd8cbbfa3ef5e29db6f5bd182f8bd4776209d9577cfb46ac51bfd232b00ab0136b24'
|
12
|
+
config.session_store :cookie_store, key: '_rails52_session'
|
13
|
+
|
14
|
+
config.log_tags = [:uuid, 'TEST_TAG']
|
15
|
+
config.loga = {
|
16
|
+
device: STREAM,
|
17
|
+
host: 'bird.example.com',
|
18
|
+
service_name: 'hello_world_app',
|
19
|
+
service_version: '1.0',
|
20
|
+
}
|
21
|
+
config.action_mailer.delivery_method = :test
|
22
|
+
end
|
23
|
+
|
24
|
+
class ApplicationController < ActionController::Base
|
25
|
+
include Rails.application.routes.url_helpers
|
26
|
+
protect_from_forgery with: :null_session
|
27
|
+
|
28
|
+
def ok
|
29
|
+
render plain: 'Hello Rails'
|
30
|
+
end
|
31
|
+
|
32
|
+
def error
|
33
|
+
nil.name
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
render json: params
|
38
|
+
end
|
39
|
+
|
40
|
+
def create
|
41
|
+
render json: params
|
42
|
+
end
|
43
|
+
|
44
|
+
def new
|
45
|
+
redirect_to :ok
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
@id = params[:id]
|
50
|
+
render '/user'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class FakeMailer < ActionMailer::Base
|
55
|
+
default from: 'notifications@example.com'
|
56
|
+
|
57
|
+
def self.send_email
|
58
|
+
basic_mail.deliver_now
|
59
|
+
end
|
60
|
+
|
61
|
+
def basic_mail
|
62
|
+
mail(
|
63
|
+
to: 'user@example.com',
|
64
|
+
subject: 'Welcome to My Awesome Site',
|
65
|
+
body: 'Banana muffin',
|
66
|
+
content_type: 'text/html',
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Dummy.routes.append do
|
72
|
+
get 'ok' => 'application#ok'
|
73
|
+
get 'error' => 'application#error'
|
74
|
+
get 'show' => 'application#show'
|
75
|
+
post 'users' => 'application#create'
|
76
|
+
get 'new' => 'application#new'
|
77
|
+
put 'users/:id' => 'application#update'
|
78
|
+
end
|
79
|
+
|
80
|
+
Dummy.initialize!
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Loga::LogSubscribers::ActionMailer, if: Rails.env.production? do
|
4
|
+
let(:log_entries) do
|
5
|
+
entries = []
|
6
|
+
STREAM.tap do |s|
|
7
|
+
s.rewind
|
8
|
+
entries = s.read.split("\n").map { |line| JSON.parse(line) }
|
9
|
+
s.close
|
10
|
+
s.reopen
|
11
|
+
end
|
12
|
+
entries
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:last_log_entry) { log_entries.last }
|
16
|
+
|
17
|
+
context 'when an email is being sent' do
|
18
|
+
it 'delivers an email' do
|
19
|
+
send_mail = -> { FakeMailer.send_email }
|
20
|
+
|
21
|
+
expect(&send_mail).to change { FakeMailer.deliveries.size }.by(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0')
|
25
|
+
it 'has the proper payload for message processing' do
|
26
|
+
configuration = Loga::Configuration.new(
|
27
|
+
format: :gelf,
|
28
|
+
service_name: 'loga_test',
|
29
|
+
device: STREAM,
|
30
|
+
level: :debug,
|
31
|
+
)
|
32
|
+
|
33
|
+
allow(Loga).to receive(:logger).and_return(configuration.logger)
|
34
|
+
|
35
|
+
FakeMailer.send_email
|
36
|
+
|
37
|
+
message_pattern = /^FakeMailer#basic_mail: Processed outbound mail in\(*/
|
38
|
+
short_message = log_entries.last(2).first['short_message']
|
39
|
+
|
40
|
+
expect(short_message).to match message_pattern
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has the proper payload for message delivery' do
|
45
|
+
FakeMailer.send_email
|
46
|
+
|
47
|
+
message_pattern = /^FakeMailer: Sent mail to user@example.com in \(*/
|
48
|
+
expect(last_log_entry['short_message']).to match(message_pattern)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'has the additional key "_mailer"' do
|
52
|
+
FakeMailer.send_email
|
53
|
+
|
54
|
+
expect(last_log_entry).to have_key('_mailer')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'has the additional key "_unique_id"' do
|
58
|
+
FakeMailer.send_email
|
59
|
+
|
60
|
+
expect(last_log_entry).to have_key('_unique_id')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -52,6 +52,7 @@ RSpec.describe Loga::Railtie do
|
|
52
52
|
let(:listeners) do
|
53
53
|
ActiveSupport::Notifications.notifier.listeners_for(notification)
|
54
54
|
end
|
55
|
+
|
55
56
|
let(:subscribers) do
|
56
57
|
listeners.map { |l| l.instance_variable_get(:@delegate).class }
|
57
58
|
end
|
@@ -94,6 +95,20 @@ RSpec.describe Loga::Railtie do
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
98
|
+
|
99
|
+
context 'ActionMailer' do
|
100
|
+
[
|
101
|
+
'receive.action_mailer',
|
102
|
+
'deliver.action_mailer',
|
103
|
+
'process.action_mailer',
|
104
|
+
].each do |notification|
|
105
|
+
let(:notification) { notification }
|
106
|
+
|
107
|
+
it 'removes ActionMailer::LogSubscriber' do
|
108
|
+
expect(subscribers).to_not include(ActionMailer::LogSubscriber)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
97
112
|
end
|
98
113
|
end
|
99
114
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class MySinatraApp < Sinatra::Base
|
4
|
-
set :logging,
|
4
|
+
set :logging, false
|
5
5
|
|
6
6
|
get '/ok' do
|
7
7
|
'Hello Sinatra'
|
@@ -21,7 +21,7 @@ class MySinatraApp < Sinatra::Base
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
RSpec.describe 'Structured logging with Sinatra',
|
24
|
+
RSpec.describe 'Structured logging with Sinatra', :with_hostname, :timecop do
|
25
25
|
let(:io) { StringIO.new }
|
26
26
|
let(:format) {}
|
27
27
|
before do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
+
require 'byebug'
|
1
2
|
require 'pry'
|
3
|
+
require 'support/gethostname_shared'
|
2
4
|
require 'support/helpers'
|
3
|
-
require 'support/timecop_shared'
|
4
5
|
require 'support/request_spec'
|
6
|
+
require 'support/timecop_shared'
|
5
7
|
require 'rack/test'
|
6
8
|
require 'simplecov'
|
7
9
|
|
8
|
-
SimpleCov.start
|
9
|
-
|
10
|
-
class Socket
|
11
|
-
def self.gethostname
|
12
|
-
'bird.example.com'
|
13
|
-
end
|
10
|
+
SimpleCov.start do
|
11
|
+
command_name "ruby-#{RUBY_VERSION}-#{File.basename(ENV['BUNDLE_GEMFILE'], '.gemfile')}"
|
14
12
|
end
|
15
13
|
|
16
14
|
case ENV['BUNDLE_GEMFILE']
|
@@ -18,7 +16,8 @@ when /rails/
|
|
18
16
|
rspec_pattern = 'integration/rails/**/*_spec.rb'
|
19
17
|
/(?<appraisal>rails\d{2})\.gemfile/ =~ ENV['BUNDLE_GEMFILE']
|
20
18
|
require 'rails'
|
21
|
-
require
|
19
|
+
require 'action_mailer'
|
20
|
+
require File.expand_path("../fixtures/#{appraisal}.rb", __FILE__)
|
22
21
|
when /sinatra/
|
23
22
|
rspec_pattern = 'integration/sinatra_spec.rb'
|
24
23
|
require 'json'
|
data/spec/support/helpers.rb
CHANGED
@@ -9,23 +9,23 @@ describe Loga::Configuration do
|
|
9
9
|
|
10
10
|
describe 'initialize' do
|
11
11
|
let(:framework_exceptions) do
|
12
|
-
%w
|
12
|
+
%w[
|
13
13
|
ActionController::RoutingError
|
14
14
|
ActiveRecord::RecordNotFound
|
15
15
|
Sinatra::NotFound
|
16
|
-
|
16
|
+
]
|
17
17
|
end
|
18
18
|
|
19
19
|
before do
|
20
20
|
allow(Loga::ServiceVersionStrategies).to receive(:call).and_return('unknown.sha')
|
21
21
|
end
|
22
22
|
|
23
|
-
context 'defaults' do
|
23
|
+
context 'defaults', with_hostname: true do
|
24
24
|
specify { expect(subject.device).to eq(STDOUT) }
|
25
25
|
specify { expect(subject.filter_exceptions).to eq(framework_exceptions) }
|
26
26
|
specify { expect(subject.filter_parameters).to eq([]) }
|
27
27
|
specify { expect(subject.format).to eq(:simple) }
|
28
|
-
specify { expect(subject.host).to eq(
|
28
|
+
specify { expect(subject.host).to eq(hostname) }
|
29
29
|
specify { expect(subject.level).to eq(:info) }
|
30
30
|
specify { expect(subject.service_name).to eq('hello_world_app') }
|
31
31
|
specify { expect(subject.service_version).to eq('unknown.sha') }
|
@@ -109,7 +109,7 @@ describe Loga::Formatters::GELFFormatter do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
context 'when the Event has an exception' do
|
112
|
-
let(:backtrace) { %w
|
112
|
+
let(:backtrace) { %w[a b] }
|
113
113
|
let(:exception) do
|
114
114
|
StandardError.new('Foo Error').tap { |e| e.set_backtrace backtrace }
|
115
115
|
end
|
@@ -54,7 +54,7 @@ describe Loga::Formatters::SimpleFormatter do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'when the Event has an exception' do
|
57
|
-
let(:backtrace) { %w
|
57
|
+
let(:backtrace) { %w[a b] }
|
58
58
|
let(:exception) do
|
59
59
|
StandardError.new('Foo Error').tap { |e| e.set_backtrace backtrace }
|
60
60
|
end
|
@@ -97,7 +97,7 @@ describe Loga::Formatters::SimpleFormatter do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
context 'when tags are available' do
|
100
|
-
let(:tags) { %w
|
100
|
+
let(:tags) { %w[USER_54321 EmailWorker] }
|
101
101
|
|
102
102
|
before do
|
103
103
|
allow_any_instance_of(described_class).to receive(:current_tags).and_return(tags)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support'
|
3
|
+
require 'loga/log_subscribers/action_mailer'
|
4
|
+
|
5
|
+
RSpec.describe Loga::LogSubscribers::ActionMailer do
|
6
|
+
subject(:mailer) { described_class.new }
|
7
|
+
|
8
|
+
let(:event) do
|
9
|
+
double('event', payload: payload, duration: 0.0001, time: Time.now)
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
Loga.reset
|
14
|
+
|
15
|
+
Loga.configure(service_name: 'hello_world_app')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#deliver' do
|
19
|
+
context 'when an email is sent' do
|
20
|
+
let(:payload) do
|
21
|
+
{
|
22
|
+
mailer: 'FakeMailer',
|
23
|
+
to: ['user@example.com'],
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'logs an info message' do
|
28
|
+
expect(Loga.logger).to receive(:info).with(kind_of(Loga::Event))
|
29
|
+
|
30
|
+
mailer.deliver(event)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#process' do
|
36
|
+
context 'when an email is sent' do
|
37
|
+
let(:payload) do
|
38
|
+
{
|
39
|
+
mailer: 'FakeMailer',
|
40
|
+
action: 'hello_world',
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'logs an info message' do
|
45
|
+
expect(Loga.logger).to receive(:debug).with(kind_of(Loga::Event))
|
46
|
+
|
47
|
+
mailer.process(event)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#receive' do
|
53
|
+
context 'when an email is sent' do
|
54
|
+
let(:payload) do
|
55
|
+
{
|
56
|
+
mailer: 'FakeMailer',
|
57
|
+
from: 'loremipsum@example.com',
|
58
|
+
subject: 'Lorem ipsum',
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'logs an info message' do
|
63
|
+
expect(Loga.logger).to receive(:info).with(kind_of(Loga::Event))
|
64
|
+
|
65
|
+
mailer.receive(event)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|