evt-log 0.4.3.5 → 0.5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/log/controls/log.rb +47 -45
- data/lib/log/controls/subject.rb +20 -18
- data/lib/log/controls/time.rb +4 -2
- data/lib/log/defaults.rb +50 -48
- data/lib/log/filter.rb +42 -40
- data/lib/log/format.rb +23 -21
- data/lib/log/format/color.rb +17 -3
- data/lib/log/level.rb +86 -84
- data/lib/log/levels.rb +21 -19
- data/lib/log/registry.rb +17 -15
- data/lib/log/subject_name.rb +13 -11
- data/lib/log/substitute.rb +26 -20
- data/lib/log/tags.rb +39 -37
- data/lib/log/telemetry.rb +16 -14
- data/lib/log/write.rb +11 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aea91ca5533a3ac1adeaeb1fb8a896058ce379c54878b630fd635a17e2757705
|
4
|
+
data.tar.gz: 4866f0db99d5035dff9f305efb61c1a50760f998ea351ad460158aca6abdbbef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf2765c97c9831c79137a03aa8c9567ac9dec3720c3ccb831f78c4dce98f8262c6443815b28ac57d47c7d45008e4de8f339c198b3c1484f12127c2b1a8fbd5a
|
7
|
+
data.tar.gz: 96110e9ff8e5f4153c254a3d2510ed65a2e8b1d08411dd033fa6724aaccb9f6703c93dc353c8a4f9e3e1815485c35fcb38b73eeca8b5acdc771ce039aecb2bcb
|
data/lib/log/controls/log.rb
CHANGED
@@ -1,65 +1,67 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
sink = ::Log.register_telemetry_sink(example)
|
7
|
-
example.telemetry_sink = sink
|
1
|
+
class Log
|
2
|
+
module Controls
|
3
|
+
module Log
|
4
|
+
def self.example
|
5
|
+
example = ::Log::Substitute::Log.new(::Log::Substitute.subject)
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
sink = ::Log.register_telemetry_sink(example)
|
8
|
+
example.telemetry_sink = sink
|
11
9
|
|
12
|
-
|
13
|
-
def self.example
|
14
|
-
logger = Log.example
|
15
|
-
logger.add_level(higher)
|
16
|
-
logger.add_level(middle)
|
17
|
-
logger.add_level(lower)
|
18
|
-
logger
|
10
|
+
example
|
19
11
|
end
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
module Levels
|
14
|
+
def self.example
|
15
|
+
logger = Log.example
|
16
|
+
logger.add_level(higher)
|
17
|
+
logger.add_level(middle)
|
18
|
+
logger.add_level(lower)
|
19
|
+
logger
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def self.higher
|
23
|
+
:higher
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
def self.middle
|
27
|
+
:middle
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def self.lower
|
31
|
+
:lower
|
32
|
+
end
|
37
33
|
end
|
38
34
|
|
39
|
-
|
40
|
-
|
35
|
+
module Operational
|
36
|
+
def self.example
|
37
|
+
::Log.build(subject)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.subject
|
41
|
+
'some subject'
|
42
|
+
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
module Specialized
|
46
|
+
def self.example
|
47
|
+
example = Example.build('Specialized Logger')
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
sink = ::Log.register_telemetry_sink(example)
|
50
|
+
example.telemetry_sink = sink
|
50
51
|
|
51
|
-
|
52
|
+
example.device = ::Log::Substitute::Log::NullDevice
|
52
53
|
|
53
|
-
|
54
|
+
example.tags = :some_additional_tag
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
example
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
class Example < ::Log
|
60
|
+
attr_accessor :telemetry_sink
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
def tag!(tags)
|
63
|
+
tags << :some_additional_tag
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
data/lib/log/controls/subject.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Log
|
2
|
+
module Controls
|
3
|
+
module Subject
|
4
|
+
def self.example
|
5
|
+
Example.new
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def self.new
|
9
|
+
example
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
module Operational
|
13
|
+
def self.example
|
14
|
+
Subject::Example.build
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
class Example
|
19
|
+
dependency :logger, ::Log
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def self.build
|
22
|
+
instance = new
|
23
|
+
::Log.configure(instance)
|
24
|
+
instance
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/log/controls/time.rb
CHANGED
data/lib/log/defaults.rb
CHANGED
@@ -1,67 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Log
|
2
|
+
module Defaults
|
3
|
+
def self.level
|
4
|
+
env_level = ENV['LOG_LEVEL']
|
5
|
+
return env_level.to_sym if !env_level.nil?
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
:info
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def self.tags
|
11
|
+
env_tags = ENV['LOG_TAGS']
|
11
12
|
|
12
|
-
|
13
|
+
return [] if env_tags.nil?
|
13
14
|
|
14
|
-
|
15
|
+
tags = env_tags.split(',')
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
tags.map { |tag| tag.to_sym }
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
def self.device
|
21
|
+
env_device = ENV['CONSOLE_DEVICE']
|
21
22
|
|
22
|
-
|
23
|
+
device = nil
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
if !env_device.nil?
|
26
|
+
if !['stderr', 'stdout'].include?(env_device)
|
27
|
+
raise "The CONSOLE_DEVICE should be either 'stderr' (default) or 'stdout'"
|
28
|
+
else
|
29
|
+
device = (env_device == 'stderr' ? STDERR : STDOUT)
|
30
|
+
end
|
27
31
|
else
|
28
|
-
device =
|
32
|
+
device = STDERR
|
29
33
|
end
|
30
|
-
|
31
|
-
device
|
34
|
+
|
35
|
+
device
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
def self.formatters
|
39
|
+
env_formatters = ENV['LOG_FORMATTERS']
|
36
40
|
|
37
|
-
|
38
|
-
|
41
|
+
if env_formatters.nil?
|
42
|
+
env_formatters = :on
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
env_formatters = :on
|
45
|
+
env_formatters.to_sym
|
42
46
|
end
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
:trace
|
55
|
-
]
|
56
|
-
end
|
48
|
+
def self.levels
|
49
|
+
[
|
50
|
+
:fatal,
|
51
|
+
:error,
|
52
|
+
:warn,
|
53
|
+
:info,
|
54
|
+
:debug,
|
55
|
+
:trace
|
56
|
+
]
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
def self.level_formatters
|
60
|
+
{
|
61
|
+
error: proc { |message, device| Format::Color.message(message, device, bg: :red, bold: true) },
|
62
|
+
fatal: proc { |message, device| Format::Color.message(message, device, fg: :red, bg: :black) },
|
63
|
+
warn: proc { |message, device| Format::Color.message(message, device, fg: :yellow, bg: :black) },
|
64
|
+
debug: proc { |message, device| Format::Color.message(message, device, fg: :green) },
|
65
|
+
trace: proc { |message, device| Format::Color.message(message, device, fg: :cyan) }
|
66
|
+
}
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
data/lib/log/filter.rb
CHANGED
@@ -1,58 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Log
|
2
|
+
module Filter
|
3
|
+
def write_level?(message_level)
|
4
|
+
if message_level.nil? && !logger_level?
|
5
|
+
return true
|
6
|
+
end
|
7
|
+
|
8
|
+
if message_level.nil? || !logger_level?
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
|
12
|
+
precedent?(message_level)
|
5
13
|
end
|
6
14
|
|
7
|
-
|
8
|
-
|
15
|
+
def precedent?(message_level)
|
16
|
+
ordinal(message_level) <= logger_ordinal
|
9
17
|
end
|
10
18
|
|
11
|
-
|
12
|
-
|
19
|
+
def write_tag?(message_tags)
|
20
|
+
message_tags ||= []
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
if message_tags.empty? && !logger_tags?
|
23
|
+
return true
|
24
|
+
end
|
17
25
|
|
18
|
-
|
19
|
-
|
26
|
+
if log_all_tags?
|
27
|
+
return true
|
28
|
+
end
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
if message_tags.empty? && log_untagged?
|
31
|
+
return true
|
32
|
+
end
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
|
34
|
+
if !message_tags.empty? && logger_tags?
|
35
|
+
if logger_tags_intersect?(message_tags)
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
end
|
28
39
|
|
29
|
-
|
30
|
-
return true
|
40
|
+
false
|
31
41
|
end
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
return true
|
36
|
-
end
|
43
|
+
def log_all_tags?
|
44
|
+
logger_tag?(:_all)
|
37
45
|
end
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def log_all_tags?
|
43
|
-
logger_tag?(:_all)
|
44
|
-
end
|
47
|
+
def log_untagged?
|
48
|
+
logger_tag?(:_untagged)
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
51
|
+
def tags_intersect?(message_tags)
|
52
|
+
if !(message_tags & logger_excluded_tags).empty?
|
53
|
+
return false
|
54
|
+
end
|
49
55
|
|
50
|
-
|
51
|
-
if !(message_tags & logger_excluded_tags).empty?
|
52
|
-
return false
|
56
|
+
!(logger_included_tags & message_tags).empty?
|
53
57
|
end
|
54
|
-
|
55
|
-
!(logger_included_tags & message_tags).empty?
|
58
|
+
alias :logger_tags_intersect? :tags_intersect?
|
56
59
|
end
|
57
|
-
alias :logger_tags_intersect? :tags_intersect?
|
58
60
|
end
|
data/lib/log/format.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Log
|
2
|
+
module Format
|
3
|
+
def self.line(message, time, subject, level, device, &message_formatter)
|
4
|
+
"#{header(time, subject, level, device)} #{message(message, device, &message_formatter)}"
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def self.message(message, device, &message_formatter)
|
8
|
+
return message unless block_given?
|
9
|
+
if Log::Defaults.formatters == :on
|
10
|
+
return message_formatter.(message, device)
|
11
|
+
else
|
12
|
+
return message
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def self.header(time, subject, level, device)
|
17
|
+
header = "[#{time}] #{subject}"
|
18
|
+
unless level.nil?
|
19
|
+
header << " #{level.to_s.upcase}"
|
20
|
+
end
|
21
|
+
header << ':'
|
22
|
+
Color.header(header, device)
|
19
23
|
end
|
20
|
-
header << ':'
|
21
|
-
Color.header(header)
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
module Defaults
|
26
|
+
def self.message_formatter
|
27
|
+
proc {|message| message }
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/log/format/color.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class Log
|
2
|
+
module Format
|
3
|
+
module Color
|
4
|
+
def self.color?(device)
|
5
|
+
device.tty?
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.header(text, device)
|
9
|
+
return text unless color?(device)
|
10
|
+
TerminalColors::Apply.(text, fg: :white)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.message(text, device, **options)
|
14
|
+
return text unless color?(device)
|
15
|
+
TerminalColors::Apply.(text, options)
|
16
|
+
end
|
17
|
+
end
|
4
18
|
end
|
5
19
|
end
|
data/lib/log/level.rb
CHANGED
@@ -1,116 +1,118 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class Log
|
2
|
+
module Level
|
3
|
+
LevelInfo = Struct.new(:name, :ordinal, :message_formatter)
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
alias :logger_level :level
|
8
|
-
|
9
|
-
def level=(level)
|
10
|
-
if [:_min, :_max].include?(level)
|
11
|
-
if level == :_min
|
12
|
-
level = min_level
|
13
|
-
else
|
14
|
-
level = max_level
|
15
|
-
end
|
5
|
+
def level
|
6
|
+
@level
|
16
7
|
end
|
8
|
+
alias :logger_level :level
|
9
|
+
|
10
|
+
def level=(level)
|
11
|
+
if [:_min, :_max].include?(level)
|
12
|
+
if level == :_min
|
13
|
+
level = min_level
|
14
|
+
else
|
15
|
+
level = max_level
|
16
|
+
end
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
alias :logger_level= :level=
|
22
|
-
|
23
|
-
def level?(level=nil)
|
24
|
-
if level.nil?
|
25
|
-
!logger_level.nil?
|
26
|
-
else
|
27
|
-
levels.has_key?(level)
|
19
|
+
assure_level(level)
|
20
|
+
@level = level
|
28
21
|
end
|
29
|
-
|
30
|
-
alias :logger_level? :level?
|
22
|
+
alias :logger_level= :level=
|
31
23
|
|
32
|
-
|
33
|
-
|
24
|
+
def level?(level=nil)
|
25
|
+
if level.nil?
|
26
|
+
!logger_level.nil?
|
27
|
+
else
|
28
|
+
levels.has_key?(level)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias :logger_level? :level?
|
34
32
|
|
35
|
-
|
33
|
+
def add_level(level, &message_formatter)
|
34
|
+
return nil if logger_level?(level)
|
36
35
|
|
37
|
-
|
36
|
+
Method.define(self, level)
|
38
37
|
|
39
|
-
|
40
|
-
end
|
38
|
+
message_formatter = Log::Format::Defaults.message_formatter unless block_given?
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
Method.remove(self, level)
|
45
|
-
levels.delete(level)
|
46
|
-
end
|
40
|
+
levels[level] = LevelInfo.new(level, levels.length, message_formatter)
|
41
|
+
end
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
def remove_level(level)
|
44
|
+
return nil unless logger_level?(level)
|
45
|
+
Method.remove(self, level)
|
46
|
+
levels.delete(level)
|
51
47
|
end
|
52
48
|
|
53
|
-
|
54
|
-
if
|
55
|
-
|
49
|
+
def assure_level(level)
|
50
|
+
if level.nil?
|
51
|
+
return
|
56
52
|
end
|
57
53
|
|
58
|
-
|
59
|
-
|
54
|
+
unless level == :_none
|
55
|
+
if !levels?
|
56
|
+
raise Log::Error, "Level #{level.inspect} cannot be set. The logger has no levels."
|
57
|
+
end
|
58
|
+
|
59
|
+
if !level?(level)
|
60
|
+
raise Log::Error, "Level #{level.inspect} must be one of: #{levels.keys.join(', ')}"
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
62
|
-
end
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
def ordinal(level=nil)
|
66
|
+
level ||= logger_level
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
if level == :_none
|
69
|
+
return -1
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
level = levels[level]
|
73
|
+
return no_ordinal if level.nil?
|
74
|
+
level.ordinal
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
def logger_ordinal
|
78
|
+
ordinal
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
def no_ordinal
|
82
|
+
-1
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def max_level
|
86
|
+
logger_levels.keys.last
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
def min_level
|
90
|
+
logger_levels.keys.first
|
91
|
+
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
def max_level!
|
94
|
+
self.logger_level = max_level
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
def min_level!
|
98
|
+
self.logger_level = min_level
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
def no_level!
|
102
|
+
self.logger_level = nil
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
module Method
|
106
|
+
def self.define(logger, level_name)
|
107
|
+
level = level_name
|
108
|
+
logger.define_singleton_method(level) do |message=nil, tag: nil, tags: nil, &blk|
|
109
|
+
self.(message, level, tag: tag, tags: tags, &blk)
|
110
|
+
end
|
109
111
|
end
|
110
|
-
end
|
111
112
|
|
112
|
-
|
113
|
-
|
113
|
+
def self.remove(logger, level_name)
|
114
|
+
logger.instance_eval "undef #{level_name}"
|
115
|
+
end
|
114
116
|
end
|
115
117
|
end
|
116
118
|
end
|
data/lib/log/levels.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
cls
|
4
|
-
|
1
|
+
class Log
|
2
|
+
module Levels
|
3
|
+
def self.included(cls)
|
4
|
+
cls.extend AddLevels
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def levels
|
8
|
+
@levels ||= {}
|
9
|
+
end
|
10
|
+
alias :logger_levels :levels
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def levels?
|
13
|
+
!levels.empty?
|
14
|
+
end
|
15
|
+
alias :logger_levels? :levels?
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def level_names
|
18
|
+
levels.keys.dup
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
module AddLevels
|
22
|
+
def add_levels(logger)
|
23
|
+
Log::Defaults.levels.each do |level|
|
24
|
+
logger.add_level(level, &Log::Defaults.level_formatters[level])
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/log/registry.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Log
|
2
|
+
module Registry
|
3
|
+
def get(subject)
|
4
|
+
register(subject)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def register(subject)
|
8
|
+
subject_name = subject_name(subject)
|
8
9
|
|
9
|
-
|
10
|
+
instance = registry[subject_name]
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if instance.nil?
|
13
|
+
instance = build(subject)
|
14
|
+
registry[subject_name] = instance
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
instance
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
def registry
|
21
|
+
@registry ||= {}
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/log/subject_name.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
class Log
|
2
|
+
module SubjectName
|
3
|
+
def subject_name(subject)
|
4
|
+
if subject.is_a?(Class) || subject.is_a?(Module)
|
5
|
+
name = subject.name
|
6
|
+
elsif subject.is_a? String
|
7
|
+
name = subject
|
8
|
+
elsif subject.is_a? Symbol
|
9
|
+
name = subject.to_s
|
10
|
+
else
|
11
|
+
name = subject.class.name
|
12
|
+
end
|
13
|
+
name
|
11
14
|
end
|
12
|
-
name
|
13
15
|
end
|
14
16
|
end
|
data/lib/log/substitute.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
class Log
|
2
|
+
module Substitute
|
3
|
+
def self.build
|
4
|
+
instance = Log.build(subject)
|
5
|
+
sink = Log.register_telemetry_sink(instance)
|
6
|
+
instance.telemetry_sink = sink
|
7
|
+
instance
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.subject
|
11
|
+
'(substitute logger)'
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
class Log < ::Log
|
15
|
+
attr_accessor :telemetry_sink
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def clock
|
18
|
+
@clock ||= Clock::UTC::Substitute.build
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def device
|
22
|
+
@device ||= NullDevice
|
23
|
+
end
|
24
|
+
|
25
|
+
class NullDevice
|
26
|
+
def self.write(*)
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
def self.tty?
|
30
|
+
true
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/log/tags.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def included_tags
|
8
|
-
@included_tags ||= []
|
9
|
-
end
|
10
|
-
alias :logger_included_tags :included_tags
|
1
|
+
class Log
|
2
|
+
module Tags
|
3
|
+
def tags
|
4
|
+
@tags ||= []
|
5
|
+
end
|
6
|
+
alias :logger_tags :tags
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
def included_tags
|
9
|
+
@included_tags ||= []
|
10
|
+
end
|
11
|
+
alias :logger_included_tags :included_tags
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
@tags = nil
|
20
|
-
return
|
13
|
+
def excluded_tags
|
14
|
+
@excluded_tags ||= []
|
21
15
|
end
|
16
|
+
alias :logger_excluded_tags :excluded_tags
|
17
|
+
|
18
|
+
def tags=(tags)
|
19
|
+
if tags.nil?
|
20
|
+
@tags = nil
|
21
|
+
return
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
+
tags = Array(tags)
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
tags.each do |tag|
|
27
|
+
unless tag.to_s.start_with?('-')
|
28
|
+
included_tags << tag
|
29
|
+
else
|
30
|
+
excluded_tags << tag[1..-1].to_sym
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
@tags = tags
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def tag=(tag)
|
38
|
+
self.tags = tag
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def tags?
|
42
|
+
!tags.empty?
|
43
|
+
end
|
44
|
+
alias :logger_tags? :tags?
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
def tag?(tag)
|
47
|
+
tags.include?(tag)
|
48
|
+
end
|
49
|
+
alias :logger_tag? :tag?
|
47
50
|
end
|
48
|
-
alias :logger_tag? :tag?
|
49
51
|
end
|
data/lib/log/telemetry.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class Log
|
2
|
+
module Telemetry
|
3
|
+
class Sink
|
4
|
+
include ::Telemetry::Sink
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
record :logged
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
+
Data = Struct.new :subject_name, :message, :level, :tags, :line
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def self.sink
|
12
|
+
Sink.new
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
module Register
|
16
|
+
def register_telemetry_sink(logger)
|
17
|
+
sink = Log::Telemetry.sink
|
18
|
+
logger.telemetry.register sink
|
19
|
+
sink
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/lib/log/write.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
message
|
1
|
+
class Log
|
2
|
+
module Write
|
3
|
+
def write(message, level, tags)
|
4
|
+
message = message.to_s
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
if message.length == 0
|
7
|
+
message = '(empty log message)'
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
+
line = Log::Format.line(message, clock.iso8601(precision: 5), subject, level, device, &levels[level] &.message_formatter)
|
10
11
|
|
11
|
-
|
12
|
+
device.write "#{line}#{$INPUT_RECORD_SEPARATOR}"
|
12
13
|
|
13
|
-
|
14
|
+
telemetry.record :logged, Log::Telemetry::Data.new(subject, message, level, tags, line)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-initializer
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.7.3
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Logging to STD IO with levels, tagging, and coloring
|