tag_logger 1.0.2 → 1.0.3

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: ca7876f8a33dfbe7a209c3981c80c92013bb064151e0e5bd8c922551d0bc61b4
4
- data.tar.gz: f6d858cc3d50e54971ae194985264313886a6ea71b0fd8e0a5627a08b7849db9
3
+ metadata.gz: 9a7649a198354c1d095fcef0635f1a9b622ca6918a1ae081e7dd2e01349cd0ce
4
+ data.tar.gz: ae8d092d882bc27d42063ee76828986196aa9fa0c5111850988a8dc215e3f361
5
5
  SHA512:
6
- metadata.gz: 200a2c7c1f70bc92d8ab308c988365901bd7e410f7cc60db28353570cbea56c0ceb31abf60e647e81c4d286a713e4cd79da08b8f4320d9637daaa955aef0ea2a
7
- data.tar.gz: f60823c056fb2aac28fd3bb8cb8bb9266de5c293059ee70e9e980b7e3934679ddd1b7dd7607baf015b83b4f5eb6becd5ff6cd737076092cb59cb3e6f24dae5da
6
+ metadata.gz: 0fbe43f76a3f87c48857e76f994bd8b5f41c29ca9a2ee851bd3b82ce66f21ba52e23d2f760ae95e233f6dc50584edf24c6e9ba127276de111d4d7fb65c286416
7
+ data.tar.gz: 89283740080c5eaba1a1cdaf6956b60e3c887468d264804e9d64a8eb12da14d98b0a365c8d8b16de5ba787896f03aed501f4f0d50cbdaa713fb98f1a820e5f8b
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
+ raise '`sanitize_log` only for Hash' unless data.is_a?(Hash)
21
+
22
+ filter_parameters = TagLogger.configuration.filter_parameters
23
+ filter_parameters.each do |key|
24
+ next if data[key].nil?
25
+ data[key] = 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,13 +3,15 @@ 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
- output_path = TagLogger.configuration&.output_path
14
+ output_path = TagLogger.configuration.output_path
13
15
  if output_path.nil? || output_path.empty?
14
16
  raise 'TagLogger configuration `output_path` is blank!'
15
17
  else
@@ -1,3 +1,3 @@
1
1
  module TagLogger
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - iliakg