tag_logger 1.0.6 → 1.1.0

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: 215dfe2e22d3d59cdcd85d9b30c666e32c0e10af3846050082a634645f2b6102
4
- data.tar.gz: 34604939dd5fd617211ed6d5cc539a9e2e3df8bc3dedafcb2ab3d182a4ade84b
3
+ metadata.gz: 06b6ffe603dda9c2a7833e47df69ffb15940a00d6bcb7721951316d7be5ad74d
4
+ data.tar.gz: e51ecdcf5d7ff594a3658862864a4da8f058693f107c30ab596838d44d27e876
5
5
  SHA512:
6
- metadata.gz: fe407b802ddb976326afd1d338127ce39967b3368e9673188c02dd9e3fffdef13e036f56879223118f89ac1f2ee0c71bf725680c98513bba7a45767bdc5ee330
7
- data.tar.gz: 4620345336eedaa3b1cd4d8aa60794d7a8b5117955c8112113ca3d74c3e6ce43de9c77be5a74bd7a2a66c7a4545fbee1e9e88a5cccc4af1bfdb503dda02b9da2
6
+ metadata.gz: ee664cba8fce8430fea45838e72e28bc3d72afaebcd78ee144a977d092feb1f8cdf61af8c349b2d9f48c79e02339316170861104f519d26769a5c27fb938a470
7
+ data.tar.gz: 5f5750e470787a3d334e05103ad43893122640431aa202162011f3c308037343a2402858bd23b28a7d20072310353e962509a4cdf836672915e753b4e7fa2c3e
data/README.md CHANGED
@@ -20,6 +20,7 @@ First need to add configuration:
20
20
  TagLogger.configure do |config|
21
21
  config.output_path = 'log/tag_logger.log'
22
22
  config.filter_parameters = [:password]
23
+ config.use_stdout = true # STDOUT log isn't shown by default
23
24
  end
24
25
  ```
25
26
 
@@ -30,7 +31,7 @@ class MyClass
30
31
 
31
32
  def my_method
32
33
  # start logging with tags
33
- tag_logger 'tag_name'
34
+ tag_logger 'tag_name', 'another_name'
34
35
 
35
36
  # then log with levels: [:warn, :info, :debug, :fatal, :error]
36
37
  log :info, 'Log information'
data/lib/tag_logger.rb CHANGED
@@ -9,11 +9,9 @@ module TagLogger
9
9
  end
10
10
 
11
11
  def log(type, text)
12
- if @tag_logger.nil?
13
- raise 'Initialize `tag_logger` method with tags name'
14
- else
15
- @tag_logger.write_log(type, text)
16
- end
12
+ tag_logger if @tag_logger.nil?
13
+
14
+ @tag_logger.write_log(type, text)
17
15
  end
18
16
 
19
17
  def sanitize_log(data)
@@ -9,7 +9,7 @@ module TagLogger
9
9
  end
10
10
 
11
11
  class Configuration
12
- attr_accessor :output_path, :filter_parameters
12
+ attr_accessor :output_path, :use_stdout, :filter_parameters
13
13
 
14
14
  def initialize
15
15
  @filter_parameters = Array.new
@@ -1,22 +1,27 @@
1
1
  module TagLogger
2
2
  class HelperLogger
3
- attr_reader :tags, :logger
3
+ attr_reader :tag_id, :tags, :path_logger, :stdout_logger
4
4
 
5
- def initialize(tags)
5
+ def initialize(tags = [])
6
6
  raise 'TagLogger configuration is nil!' if TagLogger.configuration.nil?
7
7
 
8
- if tags.empty?
9
- raise 'Tags for `tag_logger` are empty!'
10
- else
11
- @tags = tags
12
- end
8
+ @tag_id = rand(36**8).to_s(36)
9
+ @tags = tags
13
10
 
14
11
  output_path = TagLogger.configuration.output_path
15
- if output_path.nil? || output_path.empty?
16
- raise 'TagLogger configuration `output_path` is blank!'
17
- else
18
- @logger ||= Logger.new(output_path)
12
+ use_stdout = TagLogger.configuration.use_stdout
13
+
14
+ unless output_path.nil? || output_path.empty?
15
+ @path_logger ||= Logger.new(output_path)
16
+ path_logger.formatter = log_format
19
17
  end
18
+
19
+ if TagLogger.configuration.use_stdout == true
20
+ @stdout_logger ||= Logger.new(STDOUT)
21
+ stdout_logger.formatter = log_format
22
+ end
23
+
24
+ raise 'TagLogger output is blank!' if path_logger.nil? && stdout_logger.nil?
20
25
  end
21
26
 
22
27
  def write_log(type, text)
@@ -30,12 +35,16 @@ module TagLogger
30
35
 
31
36
  log_text = prepared_text(text)
32
37
  logger_class = types.fetch(type)
33
- logger_class.log(logger, log_text)
38
+
39
+ logger_class.log(path_logger, log_text) if path_logger
40
+ logger_class.log(stdout_logger, log_text) if stdout_logger
34
41
  end
35
42
 
36
43
  private
37
44
 
38
45
  def prepared_text(text)
46
+ return text if tags.empty?
47
+
39
48
  ''.tap do |s|
40
49
  tags.each do |t|
41
50
  s << ("[#{t}]" + ' ')
@@ -44,6 +53,12 @@ module TagLogger
44
53
  end
45
54
  end
46
55
 
56
+ def log_format
57
+ proc do |severity, time, _program_name, message|
58
+ "#{time.utc.iso8601(3)} ##{Process.pid} TID-#{Thread.current.object_id.to_s(36)} TAG-#{tag_id} #{severity}: #{message}\n"
59
+ end
60
+ end
61
+
47
62
  class ErrorLogger
48
63
  def self.log(logger, text)
49
64
  logger.error(text)
@@ -1,3 +1,3 @@
1
1
  module TagLogger
2
- VERSION = '1.0.6'
2
+ VERSION = '1.1.0'
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.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iliakg
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
- rubygems_version: 3.0.6
44
+ rubygems_version: 3.1.4
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: Simple gem for tag logging