rf_logger 0.3.2 → 0.3.3

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: b595e7d05f3277b9c9835fa966c9c3a4a1e6fec9
4
- data.tar.gz: aecb196b1dbd862dffab3ec5dc341ab68ec1e31b
3
+ metadata.gz: c98893ac9f0eafd8301166b30dcf4457b36d5b1f
4
+ data.tar.gz: d502d55018ded1e967701994c50f76d51dda5e46
5
5
  SHA512:
6
- metadata.gz: 6b16adcfce60a563371920d59b2bfc05b701c5c74a0572bdaace67bf747914b95ae6128142f8f51eb4e3530c6d3768af99223d65877c7e563ad0fed2e7bd6d22
7
- data.tar.gz: 96c307c32bb8880a67b3a159713d6734f990bd63a3ac2e1ea6c76235177ecac1a2b8add190331cb8e90eb0d70710c5bf615de914edab98bd05f0f130e662bc39
6
+ metadata.gz: 5874f7a53ef1009b1ccb3fae87e9e6344857c35f16ada5e43c19f08a0d2a5f5e6a98593d9bd52f02dae5e3616f62f508d09679d4fd3aae6260e407793c77d562
7
+ data.tar.gz: a34a4b5e487697bdbb8898fb8aab7924b62060b3694c673f12b698b3172e56680c06ba9d7a89b308ab8013080d25883e92a0739175ca403627aff70b439665e9
@@ -20,11 +20,10 @@ module RfLogger
20
20
  :level => RfLogger::LEVELS.index(level.to_sym),
21
21
  :action => entry[:action],
22
22
  :actor => entry[:actor],
23
- :metadata => entry[:metadata] || {},
23
+ :metadata => merge_request_to_metadata(entry[:metadata] || {}),
24
24
  :target_type => entry[:target_type],
25
25
  :target_id => entry[:target_id],
26
26
  }
27
- attributes[:metadata].merge!(request_tags: rf_logger_request_tags) unless rf_logger_request_tags.nil?
28
27
  create(attributes)
29
28
  end
30
29
  end
@@ -53,6 +53,6 @@ require "rails/engine/railties"
53
53
 
54
54
  class KeyValueKeyLogging < ::Rails::Railtie
55
55
  initializer "rf_logging.add_log_tag_request_id" do |app|
56
- app.config.log_tags = { request_id: :uuid }
56
+ app.config.log_tags = { request_id: :uuid, remote_ip: :remote_ip }
57
57
  end
58
58
  end
@@ -21,7 +21,7 @@ module RfLogger
21
21
  attr_reader :rails_version
22
22
 
23
23
  def rails_not_support_message
24
- return unless ENV["RF_LOGGER_LOAD_DEBUG"] = "true"
24
+ return unless ENV["RF_LOGGER_LOAD_DEBUG"] == "true"
25
25
  puts "RfLogger: These patches change Rails private methods and are only known to work for Rails #{MIN} through #{MAX}. Current version #{rails_version}"
26
26
  end
27
27
 
@@ -5,5 +5,16 @@ module RfLogger
5
5
  def rf_logger_request_tags
6
6
  Thread.current.get_inheritable_attribute(:rf_logger_request_tags)
7
7
  end
8
+
9
+ def rf_logger_request_tags?
10
+ rf_logger_request_tags.present? && rf_logger_request_tags.reject { |_, v| v.nil? }.count > 0
11
+ end
12
+
13
+ def merge_request_to_metadata(metadata)
14
+ if metadata.is_a?(Hash) && rf_logger_request_tags?
15
+ metadata.merge!(request_tags: rf_logger_request_tags)
16
+ end
17
+ metadata
18
+ end
8
19
  end
9
20
  end
@@ -26,8 +26,7 @@ module RfLogger
26
26
  def add(level, entry)
27
27
  entry[:level] = RfLogger::LEVELS.index(level.to_sym)
28
28
  entry[:actor] = entry[:actor] || ''
29
- entry[:metadata] = entry[:metadata] || {}
30
- entry[:metadata].merge!(request_tags: rf_logger_request_tags) unless rf_logger_request_tags.nil?
29
+ entry[:metadata] = merge_request_to_metadata(entry[:metadata] || {})
31
30
  entry[:created_at] = Time.now
32
31
  create(entry)
33
32
  end
@@ -39,6 +38,7 @@ module RfLogger
39
38
  end
40
39
 
41
40
  def metadata=(metadata_hash)
41
+ metadata_hash = self.class.merge_request_to_metadata(metadata_hash)
42
42
  metadata_as_json = metadata_hash.nil? ? nil : metadata_hash.to_json
43
43
  self[:metadata] = metadata_as_json
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module RfLogger
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -44,6 +44,20 @@ describe RfLogger::ActiveRecord::Logger do
44
44
  )
45
45
  end
46
46
  end
47
+
48
+ context "when metadata is not a hash" do
49
+ it "creates new Log object with level = #{level}" do
50
+ described_class.send(level.to_sym, action: 'log me', metadata: "not a hash")
51
+ expect(described_class).to have_received(:create).with(
52
+ :level => RfLogger::LEVELS.index(level.to_sym),
53
+ :action => 'log me',
54
+ :actor => nil,
55
+ :metadata => "not a hash",
56
+ :target_type => nil,
57
+ :target_id => nil,
58
+ )
59
+ end
60
+ end
47
61
  end
48
62
  end
49
63
  end
@@ -82,6 +82,20 @@ describe RfLogger::Sequel::Logger do
82
82
  end
83
83
  end
84
84
 
85
+ context "when rf_logger_request_tags has keys but nil values" do
86
+ it "return a metadata with no request_tags key" do
87
+ allow(described_class).to receive(:rf_logger_request_tags).and_return({ key_with_no_value: nil })
88
+
89
+ expect(described_class).to receive(:create).with(
90
+ ({ :level => 1,
91
+ :actor => "",
92
+ :metadata => { },
93
+ :created_at => "NOW" })
94
+ )
95
+ described_class.add(:info, {})
96
+ end
97
+ end
98
+
85
99
  it 'sets actor to blank string if not provided' do
86
100
  expect(described_class).to receive(:create).with(
87
101
  :actor => '',
@@ -104,12 +118,30 @@ describe RfLogger::Sequel::Logger do
104
118
 
105
119
  described_class.add(:info, { :action => 'palpitate' })
106
120
  end
121
+
122
+ it 'return passed in value when metadata is not a hash' do
123
+ expect(described_class).to receive(:create).with(
124
+ :actor => '',
125
+ :action => 'palpitate',
126
+ :metadata => "not a hash",
127
+ :created_at => 'NOW',
128
+ :level => RfLogger::LEVELS.index(:info)
129
+ )
130
+
131
+ described_class.add(:info, { :action => 'palpitate', :metadata => "not a hash" })
132
+ end
107
133
  end
108
134
 
109
135
  describe "#metadata" do
110
136
  it 'returns a hash for metadata even though it is stored as JSON' do
111
- subject.metadata = {'foo' => 'bar'}
112
- expect(subject.metadata).to eq({'foo' => 'bar'})
137
+ subject.metadata = { 'foo' => 'bar' }
138
+ expect(subject.metadata).to eq({ 'foo' => 'bar', "request_tags" => { "request_id" => "909090" } })
139
+ end
140
+
141
+ it 'return a hash without request_tags when values are nil' do
142
+ allow(described_class).to receive(:rf_logger_request_tags).and_return({ key_with_no_value: nil })
143
+ subject.metadata = { 'foo' => 'bar' }
144
+ expect(subject.metadata).to eq({ 'foo' => 'bar' })
113
145
  end
114
146
 
115
147
  it 'returns nil if column is null' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rf_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler