tag_logger 1.0.0 → 1.0.5

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: 1383db345a0b72da2a66bb213a7b66c3222d513b25b2c45077e3a1b28f3a8427
4
- data.tar.gz: 18f14e9667504e9862abffb897d356e76b5ed0384e2629c2a135743c309e6b1f
3
+ metadata.gz: 01f47f454ecf52b39c5cf37c481e1c183802685c144ffd1c1a756a2cdce8eb4a
4
+ data.tar.gz: 1d94cc8ec85cd64685b7e690659a11182d0808feaf7e6403458e1dc213838514
5
5
  SHA512:
6
- metadata.gz: a4a0d4410c1086f3a24e6b1bc948b8f214915823fb92f17504cc23e5f025093e4f6067df6db237fd1e7d9544d835a795fe592e59b4d476ecbc1ef8bec103def3
7
- data.tar.gz: 41a821b4c21315e5c4266ef73899b6ad4cddf3633a8e75771b3a815b0603d634d0bedec046efbcd8e8cd608d393de0ba6b85dc455bb74b5c21d2423928c0313f
6
+ metadata.gz: 8ebba40d43445388a7540c9446734f564522e9583f4fb1a4cad8ac59574e30b2dc0d7787c94108ff6f2704737e91812e80c32138470f247c4f9c068a122a51e0
7
+ data.tar.gz: 63faae4fd1200ff11d382ff911236bfcecd9ea74203ff6b8c21827f5c8129368dd5dc8af79a98896a16a02c64bd3bbebb99d76844e0dfadec8863ef56d28f256
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ilia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -11,14 +11,15 @@ 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
18
18
  First need to add configuration:
19
19
  ```ruby
20
20
  TagLogger.configure do |config|
21
- config.output_path = "log/tag_logger.log"
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
- if tags.blank?
6
+ raise 'TagLogger configuration is nil!' if TagLogger.configuration.nil?
7
+
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.0'
3
- end
2
+ VERSION = '1.0.5'
3
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tag_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - ilia_kg
7
+ - iliakg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -16,6 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - LICENSE
19
20
  - README.md
20
21
  - lib/tag_logger.rb
21
22
  - lib/tag_logger/configuration.rb