loga 2.3.0 → 2.3.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
  SHA256:
3
- metadata.gz: 99d4525427d3cfa44d95be9d47f82188246743e71aab9f8d40489214e02e4c02
4
- data.tar.gz: 33fc287f4ecabf93cdc6d789f81a040c64eb411d7a018459fa39c91ae03c46c8
3
+ metadata.gz: 9144c2b13cb8e6ed178d6ee24e99c9d00d4ce23bf3198d487e1803d221038874
4
+ data.tar.gz: 2528a6ce89a60dccc50e22f98abd1e4e74ae3f49319adeed42a89a98ad4412f8
5
5
  SHA512:
6
- metadata.gz: 6ce2b115d84a4b3c1c93bf8070b0f3d7ed148df4eb1169ab57d8de2357ad03ea23c21fab2f30f6c0b24236919cbaee21565eee7fed007949a7fa6601118ef510
7
- data.tar.gz: df05bfcd3ba233ef8a64e743fcb40c9948caeb1a82039340ae6cb24a839b2cab08044da8009f91196bf444b0b960cbcc29bd2fe9b08f8f3ac003f2757ad5d320
6
+ metadata.gz: 1d9b346f49a5661ab32f3cabe4a16edba7757aa5a5d10b830758d1ca12ff70ece723014701a5ba82da7d358736c320af4a91e7dee609ba657d200905b5afdb3f
7
+ data.tar.gz: e53c366b5efcb67136322cae79fa6f21fcfdbefd654cb982681067b02de0c86d02f678afe02b7e5c3db298024818ba06dd5ac4ad51f0c234ea799a906295782d
@@ -2,5 +2,3 @@ engines:
2
2
  rubocop:
3
3
  enabled: true
4
4
  channel: rubocop-0-57
5
- config:
6
- file: rubocop.yml
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [2.3.1] - 2019-05-14
8
+ ### Added
9
+ New configuration option `hide_pii` which defaults to `true` to hide email addresses in logs that get generate when an email is sent through action_mailer
10
+
7
11
  ## [2.3.0] - 2018-06-29
8
12
  ### Added
9
13
  Support for Sidekiq `~> 5.0`.
@@ -15,9 +15,10 @@ module Loga
15
15
  ].freeze
16
16
 
17
17
  attr_accessor :device, :filter_exceptions, :filter_parameters,
18
- :host, :level, :service_version, :sync, :tags
18
+ :host, :level, :service_version, :sync, :tags, :hide_pii
19
19
  attr_reader :logger, :format, :service_name
20
20
 
21
+ # rubocop:disable Metrics/MethodLength
21
22
  def initialize(user_options = {}, framework_options = {})
22
23
  options = default_options.merge(framework_options)
23
24
  .merge(environment_options)
@@ -33,11 +34,13 @@ module Loga
33
34
  self.service_version = options[:service_version] || ServiceVersionStrategies.call
34
35
  self.sync = options[:sync]
35
36
  self.tags = options[:tags]
37
+ self.hide_pii = options[:hide_pii]
36
38
 
37
39
  validate
38
40
 
39
41
  @logger = initialize_logger
40
42
  end
43
+ # rubocop:enable Metrics/MethodLength
41
44
 
42
45
  def format=(name)
43
46
  @format = name.to_s.to_sym
@@ -68,6 +71,7 @@ module Loga
68
71
  level: :info,
69
72
  sync: true,
70
73
  tags: [],
74
+ hide_pii: true,
71
75
  }
72
76
  end
73
77
 
@@ -9,7 +9,11 @@ module Loga
9
9
  recipients = event.payload[:to].join(',')
10
10
  unique_id = event.payload[:unique_id]
11
11
  duration = event.duration.round(1)
12
- message = "#{mailer}: Sent mail to #{recipients} in (#{duration}ms)"
12
+ message = ''.tap do |string|
13
+ string << "#{mailer}: Sent mail"
14
+ string << " to #{recipients}" unless hide_pii?
15
+ string << " in (#{duration}ms)"
16
+ end
13
17
 
14
18
  loga_event = Event.new(
15
19
  data: { mailer: mailer, unique_id: unique_id },
@@ -41,10 +45,15 @@ module Loga
41
45
  from = event.payload[:from]
42
46
  mailer = event.payload[:mailer]
43
47
  unique_id = event.payload[:unique_id]
48
+ message = ''.tap do |string|
49
+ string << 'Received mail'
50
+ string << " from #{from}" unless hide_pii?
51
+ string << " in (#{event.duration.round(1)}ms)"
52
+ end
44
53
 
45
54
  loga_event = Event.new(
46
55
  data: { mailer: mailer, unique_id: unique_id },
47
- message: "Received mail #{from} in (#{event.duration.round(1)}ms)",
56
+ message: message,
48
57
  type: 'action_mailer',
49
58
  )
50
59
 
@@ -54,6 +63,10 @@ module Loga
54
63
  def logger
55
64
  Loga.logger
56
65
  end
66
+
67
+ def hide_pii?
68
+ Loga.configuration.hide_pii
69
+ end
57
70
  end
58
71
  end
59
72
  end
@@ -1,3 +1,3 @@
1
1
  module Loga
2
- VERSION = '2.3.0'.freeze
2
+ VERSION = '2.3.1'.freeze
3
3
  end
@@ -44,7 +44,7 @@ RSpec.describe Loga::LogSubscribers::ActionMailer, if: Rails.env.production? do
44
44
  it 'has the proper payload for message delivery' do
45
45
  FakeMailer.send_email
46
46
 
47
- message_pattern = /^FakeMailer: Sent mail to user@example.com in \(*/
47
+ message_pattern = /^FakeMailer: Sent mail \(*/
48
48
  expect(last_log_entry['short_message']).to match(message_pattern)
49
49
  end
50
50
 
@@ -24,11 +24,34 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
24
24
  to: ['user@example.com'],
25
25
  }
26
26
  end
27
+ let(:config) { instance_double Loga::Configuration, hide_pii: hide_pii }
27
28
 
28
- it 'logs an info message' do
29
+ before do
29
30
  allow(Loga.logger).to receive(:info)
30
- mailer.deliver(event)
31
- expect(Loga.logger).to have_received(:info).with(kind_of(Loga::Event))
31
+ allow(Loga).to receive(:configuration).and_return(config)
32
+ end
33
+
34
+ context 'when configuration hide_pii is true' do
35
+ let(:hide_pii) { true }
36
+
37
+ it 'logs an info message' do
38
+ mailer.deliver(event)
39
+ expect(Loga.logger).to have_received(:info).with(Loga::Event) do |event|
40
+ expect(event.message).to include('FakeMailer: Sent mail')
41
+ expect(event.message).not_to include('user@example.com')
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when configuration option hide_pii is false' do
47
+ let(:hide_pii) { false }
48
+
49
+ it 'logs an info message' do
50
+ mailer.deliver(event)
51
+ expect(Loga.logger).to have_received(:info).with(Loga::Event) do |event|
52
+ expect(event.message).to include('FakeMailer: Sent mail to user@example.com')
53
+ end
54
+ end
32
55
  end
33
56
  end
34
57
  end
@@ -45,7 +68,12 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
45
68
  it 'logs an info message' do
46
69
  allow(Loga.logger).to receive(:debug)
47
70
  mailer.process(event)
48
- expect(Loga.logger).to have_received(:debug).with(kind_of(Loga::Event))
71
+ expect(Loga.logger).to have_received(:debug)
72
+ .with(kind_of(Loga::Event)) do |event|
73
+ expect(event.message).to include(
74
+ 'FakeMailer#hello_world: Processed outbound mail',
75
+ )
76
+ end
49
77
  end
50
78
  end
51
79
  end
@@ -59,11 +87,38 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
59
87
  subject: 'Lorem ipsum',
60
88
  }
61
89
  end
90
+ let(:config) { instance_double Loga::Configuration, hide_pii: hide_pii }
62
91
 
63
- it 'logs an info message' do
92
+ before do
64
93
  allow(Loga.logger).to receive(:info)
65
- mailer.receive(event)
66
- expect(Loga.logger).to have_received(:info).with(kind_of(Loga::Event))
94
+ allow(Loga).to receive(:configuration).and_return(config)
95
+ end
96
+
97
+ context 'when configuration hide_pii is true' do
98
+ let(:hide_pii) { true }
99
+
100
+ it 'logs an info message without email' do
101
+ mailer.receive(event)
102
+ expect(Loga.logger).to have_received(:info)
103
+ .with(kind_of(Loga::Event)) do |event|
104
+ expect(event.message).to include('Received mail')
105
+ expect(event.message).not_to include('loremipsum@example.com')
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'when configuration option hide_pii is false' do
111
+ let(:hide_pii) { false }
112
+
113
+ it 'logs an info message with email' do
114
+ mailer.receive(event)
115
+ expect(Loga.logger).to have_received(:info)
116
+ .with(kind_of(Loga::Event)) do |event|
117
+ expect(event.message).to include(
118
+ 'Received mail from loremipsum@example.com',
119
+ )
120
+ end
121
+ end
67
122
  end
68
123
  end
69
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loga
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Funding Circle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2019-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport