tag_logger 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89dc1838150d202e25c6c788f56c98f2b295d1978921681e7ebeba740263f6c7
4
- data.tar.gz: 3529f3aa838f689f9cf1c1960e790b919b40f6dc37ea5eff8036f137d0f15715
3
+ metadata.gz: 215dfe2e22d3d59cdcd85d9b30c666e32c0e10af3846050082a634645f2b6102
4
+ data.tar.gz: 34604939dd5fd617211ed6d5cc539a9e2e3df8bc3dedafcb2ab3d182a4ade84b
5
5
  SHA512:
6
- metadata.gz: 7f59e32e1c8fa629e1bd66f7dbf4577f51c13fa24a16cac081db9eb55631d81e68327c53f569610c94f48309b824c961cee1148f728228edefa7142992d125c8
7
- data.tar.gz: a1cb01532e4d6c2ff3c71f13b8f989a145f0fd8ee841e8af489965712ae595b7c2837f9f9041562cef07c18aebc72261781a6c18ddc160fc95cc5f838466b6d6
6
+ metadata.gz: fe407b802ddb976326afd1d338127ce39967b3368e9673188c02dd9e3fffdef13e036f56879223118f89ac1f2ee0c71bf725680c98513bba7a45767bdc5ee330
7
+ data.tar.gz: 4620345336eedaa3b1cd4d8aa60794d7a8b5117955c8112113ca3d74c3e6ce43de9c77be5a74bd7a2a66c7a4545fbee1e9e88a5cccc4af1bfdb503dda02b9da2
data/README.md CHANGED
@@ -11,7 +11,7 @@ gem 'tag_logger'
11
11
 
12
12
  Or install it yourself as:
13
13
  ```bash
14
- $ gem install sample_filter
14
+ $ gem install tag_logger
15
15
  ```
16
16
 
17
17
  ## Usage
@@ -19,6 +19,7 @@ First need to add configuration:
19
19
  ```ruby
20
20
  TagLogger.configure do |config|
21
21
  config.output_path = 'log/tag_logger.log'
22
+ config.filter_parameters = [:password]
22
23
  end
23
24
  ```
24
25
 
@@ -33,6 +34,11 @@ class MyClass
33
34
 
34
35
  # then log with levels: [:warn, :info, :debug, :fatal, :error]
35
36
  log :info, 'Log information'
37
+
38
+ # if data has sensitive information, it must be sanitized
39
+ # INFO -- : [tag_name] Log information {:email=>"test@email.com", :password=>"[FILTERED]"}
40
+ data = {email: 'test@email.com', password: '123456'}
41
+ log :info, "Log information #{sanitize_log(data)}"
36
42
  end
37
43
  end
38
44
  ```
@@ -2,6 +2,8 @@ require 'tag_logger/helper_logger'
2
2
  require 'tag_logger/configuration'
3
3
 
4
4
  module TagLogger
5
+ FILTERED_TEXT = '[FILTERED]'.freeze
6
+
5
7
  def tag_logger(*tags)
6
8
  @tag_logger ||= HelperLogger.new(tags)
7
9
  end
@@ -13,4 +15,16 @@ module TagLogger
13
15
  @tag_logger.write_log(type, text)
14
16
  end
15
17
  end
18
+
19
+ def sanitize_log(data)
20
+ data = data.to_hash.transform_keys(&:to_sym)
21
+
22
+ filter_parameters = TagLogger.configuration.filter_parameters
23
+ filter_parameters.each do |key|
24
+ next if data[key.to_sym].nil?
25
+ data[key.to_sym] = FILTERED_TEXT
26
+ end
27
+
28
+ data
29
+ end
16
30
  end
@@ -9,6 +9,10 @@ module TagLogger
9
9
  end
10
10
 
11
11
  class Configuration
12
- attr_accessor :output_path
12
+ attr_accessor :output_path, :filter_parameters
13
+
14
+ def initialize
15
+ @filter_parameters = Array.new
16
+ end
13
17
  end
14
18
  end
@@ -3,16 +3,19 @@ module TagLogger
3
3
  attr_reader :tags, :logger
4
4
 
5
5
  def initialize(tags)
6
+ raise 'TagLogger configuration is nil!' if TagLogger.configuration.nil?
7
+
6
8
  if tags.empty?
7
9
  raise 'Tags for `tag_logger` are empty!'
8
10
  else
9
11
  @tags = tags
10
12
  end
11
13
 
12
- if TagLogger.configuration&.output_path.blank?
14
+ output_path = TagLogger.configuration.output_path
15
+ if output_path.nil? || output_path.empty?
13
16
  raise 'TagLogger configuration `output_path` is blank!'
14
17
  else
15
- @logger ||= Logger.new(TagLogger.configuration.output_path)
18
+ @logger ||= Logger.new(output_path)
16
19
  end
17
20
  end
18
21
 
@@ -1,3 +1,3 @@
1
1
  module TagLogger
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - iliakg