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 +4 -4
- data/README.md +2 -1
- data/lib/tag_logger.rb +3 -5
- data/lib/tag_logger/configuration.rb +1 -1
- data/lib/tag_logger/helper_logger.rb +27 -12
- data/lib/tag_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b6ffe603dda9c2a7833e47df69ffb15940a00d6bcb7721951316d7be5ad74d
|
4
|
+
data.tar.gz: e51ecdcf5d7ff594a3658862864a4da8f058693f107c30ab596838d44d27e876
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
14
|
-
|
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)
|
@@ -1,22 +1,27 @@
|
|
1
1
|
module TagLogger
|
2
2
|
class HelperLogger
|
3
|
-
attr_reader :tags, :
|
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
|
-
|
9
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@
|
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
|
-
|
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)
|
data/lib/tag_logger/version.rb
CHANGED
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
|
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.
|
44
|
+
rubygems_version: 3.1.4
|
45
45
|
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: Simple gem for tag logging
|