evt-telemetry-logger 0.5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/telemetry/logger/ad_hoc.rb +18 -0
- data/lib/telemetry/logger/color.rb +75 -0
- data/lib/telemetry/logger/console_logger.rb +115 -0
- data/lib/telemetry/logger/dependency.rb +15 -0
- data/lib/telemetry/logger/levels.rb +141 -0
- data/lib/telemetry/logger/logger.rb +47 -0
- data/lib/telemetry/logger/null_object.rb +18 -0
- data/lib/telemetry/logger.rb +15 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fa78e17af434e16e3d6cb9cec295a3f6c613a45
|
4
|
+
data.tar.gz: 2e07f132799a4a90311c9847b6f2a20fac4b7f6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3827dc61365389e75c9079e5073e346f757d15532293970ddf69fbf0dfe95a609049ebdbd34355a427197027b0aae773c3fc2c0a864026023ddef07cd93e547
|
7
|
+
data.tar.gz: 81b83031ec93965b4c7d136ca74a6d5951ae50ac02672fbac7b8f0a304a40c1dfb46ed29c2e114cacf0fc536895d83f363f27b3ac9130cbada4349e61e5124b2
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Telemetry
|
2
|
+
module Logger
|
3
|
+
module AdHoc
|
4
|
+
def self.activate(target_class=nil)
|
5
|
+
target_class ||= Object
|
6
|
+
|
7
|
+
return if target_class.is_a? self
|
8
|
+
|
9
|
+
target_class.send :include, self
|
10
|
+
end
|
11
|
+
|
12
|
+
def __logger(subject=nil)
|
13
|
+
subject ||= caller[0].split('/').last
|
14
|
+
Telemetry::Logger.build subject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class Telemetry
|
2
|
+
module Logger
|
3
|
+
module Color
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def apply(level, message)
|
7
|
+
if respond_to? level
|
8
|
+
send level, message
|
9
|
+
else
|
10
|
+
message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def metadata(text)
|
15
|
+
Rainbow(text).yellow
|
16
|
+
end
|
17
|
+
|
18
|
+
def todo(message)
|
19
|
+
Rainbow(message).bright.white.bg(:white)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fubar(message)
|
23
|
+
Rainbow(message).red.bg(:yellow)
|
24
|
+
end
|
25
|
+
|
26
|
+
def obsolete(message)
|
27
|
+
Rainbow(message).bright.white
|
28
|
+
end
|
29
|
+
|
30
|
+
def opt_data(message)
|
31
|
+
data(message)
|
32
|
+
end
|
33
|
+
|
34
|
+
def data(message)
|
35
|
+
Rainbow(message).cyan
|
36
|
+
end
|
37
|
+
|
38
|
+
def opt_trace(message)
|
39
|
+
trace(message)
|
40
|
+
end
|
41
|
+
|
42
|
+
def trace(message)
|
43
|
+
Rainbow(message).white
|
44
|
+
end
|
45
|
+
|
46
|
+
def info(message)
|
47
|
+
Rainbow(message).green
|
48
|
+
end
|
49
|
+
|
50
|
+
def pass(message)
|
51
|
+
Rainbow(message).black.bg(:green)
|
52
|
+
end
|
53
|
+
|
54
|
+
def fail(message)
|
55
|
+
Rainbow(message).black.bg(:red)
|
56
|
+
end
|
57
|
+
|
58
|
+
def focus(message)
|
59
|
+
Rainbow(message).bright.white.bg(:blue)
|
60
|
+
end
|
61
|
+
|
62
|
+
def warn(message)
|
63
|
+
Rainbow(message).yellow.bg(:black)
|
64
|
+
end
|
65
|
+
|
66
|
+
def error(message)
|
67
|
+
Rainbow(message).red.bg(:black)
|
68
|
+
end
|
69
|
+
|
70
|
+
def fatal(message)
|
71
|
+
Rainbow(message).white.bg(:black)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
class Telemetry
|
2
|
+
module Logger
|
3
|
+
class ConsoleLogger
|
4
|
+
include Levels
|
5
|
+
|
6
|
+
attr_reader :name
|
7
|
+
attr_reader :device
|
8
|
+
|
9
|
+
attr_reader :level
|
10
|
+
attr_reader :level_number
|
11
|
+
|
12
|
+
dependency :clock, Clock::Local
|
13
|
+
|
14
|
+
def self.build(subject)
|
15
|
+
name = logger_name(subject)
|
16
|
+
device = Defaults.device
|
17
|
+
instance = new(name, device)
|
18
|
+
instance.level = Defaults.level
|
19
|
+
Clock::Local.configure instance
|
20
|
+
instance
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.logger_name(subject)
|
24
|
+
if subject.is_a?(Class) || subject.is_a?(Module)
|
25
|
+
name = subject.name
|
26
|
+
elsif subject.is_a? String
|
27
|
+
name = subject
|
28
|
+
else
|
29
|
+
name = subject.class.name
|
30
|
+
end
|
31
|
+
name
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(name, device)
|
35
|
+
@name = name
|
36
|
+
@device = device
|
37
|
+
end
|
38
|
+
|
39
|
+
def write(message)
|
40
|
+
return if Defaults.activation == 'off'
|
41
|
+
device.write "#{message}#{$INPUT_RECORD_SEPARATOR}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def format(message, level)
|
45
|
+
return message if Defaults.color == 'off'
|
46
|
+
Telemetry::Logger::Color.apply(level, message)
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_metadata(text)
|
50
|
+
return text if Defaults.color == 'off'
|
51
|
+
Telemetry::Logger::Color.metadata(text)
|
52
|
+
end
|
53
|
+
|
54
|
+
def level=(level)
|
55
|
+
index = ordinal(level)
|
56
|
+
|
57
|
+
raise "Unknown logger level: #{level}" unless index
|
58
|
+
|
59
|
+
@level_number = index
|
60
|
+
@level = level
|
61
|
+
end
|
62
|
+
|
63
|
+
module Defaults
|
64
|
+
def self.level
|
65
|
+
level = ENV['LOG_LEVEL']
|
66
|
+
return level.to_sym if level
|
67
|
+
|
68
|
+
:info
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.device
|
72
|
+
setting = ENV['CONSOLE_DEVICE']
|
73
|
+
device = nil
|
74
|
+
if setting && !['stderr', 'stdout'].include?(setting)
|
75
|
+
raise "The CONSOLE_DEVICE should be either 'stderr' (default) or 'stdout'"
|
76
|
+
elsif setting
|
77
|
+
device = setting == 'stderr' ? STDERR : STDOUT
|
78
|
+
else
|
79
|
+
device = STDERR
|
80
|
+
end
|
81
|
+
device.sync = true
|
82
|
+
device
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.activation
|
86
|
+
activation = ENV['LOGGER']
|
87
|
+
return activation if activation
|
88
|
+
|
89
|
+
'on'
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.color
|
93
|
+
color = ENV['LOG_COLOR']
|
94
|
+
|
95
|
+
# CONSOLE_COLOR is obsolete. It is here for backwards compatibility
|
96
|
+
if color.nil?
|
97
|
+
color = ENV['CONSOLE_COLOR']
|
98
|
+
|
99
|
+
unless color.nil?
|
100
|
+
puts '*** WARNING: The CONSOLE_COLOR environment variable is obsolete. Use LOG_COLOR instead. Support for CONSOLE_COLOR will be discontinued.'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
return color if color
|
105
|
+
|
106
|
+
if device.tty?
|
107
|
+
'on'
|
108
|
+
else
|
109
|
+
'off'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
class Telemetry
|
2
|
+
module Logger
|
3
|
+
module Levels
|
4
|
+
def self.levels
|
5
|
+
[
|
6
|
+
:todo,
|
7
|
+
:fubar,
|
8
|
+
:obsolete,
|
9
|
+
:data,
|
10
|
+
:trace,
|
11
|
+
:debug,
|
12
|
+
:opt_data,
|
13
|
+
:opt_trace,
|
14
|
+
:opt_debug,
|
15
|
+
:info,
|
16
|
+
:pass,
|
17
|
+
:fail,
|
18
|
+
:focus,
|
19
|
+
:warn,
|
20
|
+
:error,
|
21
|
+
:fatal
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(cls)
|
26
|
+
levels.each do |level|
|
27
|
+
define_level level, cls
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.define_level(level, cls)
|
32
|
+
cls.send :define_method, level do |message|
|
33
|
+
write_level(__method__, message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.level_index
|
38
|
+
@level_index ||= build_level_index
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.build_level_index
|
42
|
+
table = {}
|
43
|
+
|
44
|
+
levels.each_with_index do |level, index|
|
45
|
+
table[level] = index
|
46
|
+
end
|
47
|
+
|
48
|
+
table
|
49
|
+
end
|
50
|
+
|
51
|
+
def level_index
|
52
|
+
Levels.level_index
|
53
|
+
end
|
54
|
+
|
55
|
+
def ordinal(level)
|
56
|
+
if [:_min, :_max].include?(level)
|
57
|
+
if level == :_min
|
58
|
+
return level_index.values.last
|
59
|
+
else
|
60
|
+
return level_index.values.first
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
level_index[level]
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_level(level, message)
|
68
|
+
level_ordinal = ordinal(level)
|
69
|
+
write_message(message, level) if sufficient_level?(level_ordinal) && !omit?(level)
|
70
|
+
end
|
71
|
+
|
72
|
+
def write_message(message, level)
|
73
|
+
message = message.to_s
|
74
|
+
|
75
|
+
if message.length == 0
|
76
|
+
message = '(empty log message)'
|
77
|
+
end
|
78
|
+
|
79
|
+
message.each_line do |line|
|
80
|
+
line = line.chomp("\n") unless line.end_with?("\r\n") || line == "\n"
|
81
|
+
line = line.gsub("\r", "\\r")
|
82
|
+
line = line.gsub("\n", "\\n")
|
83
|
+
|
84
|
+
message = implementer.format(line, level)
|
85
|
+
metadata = metadata(level)
|
86
|
+
header = implementer.format_metadata(metadata)
|
87
|
+
|
88
|
+
implementer.write "#{header}#{message}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def metadata(level)
|
93
|
+
if Defaults.metadata == 'off'
|
94
|
+
return nil
|
95
|
+
elsif Defaults.metadata == 'minimal'
|
96
|
+
return "#{name.split('::').last}: "
|
97
|
+
else
|
98
|
+
level = String(level)
|
99
|
+
|
100
|
+
if level.start_with?('opt_')
|
101
|
+
level = "(#{level.split('_').last})"
|
102
|
+
end
|
103
|
+
|
104
|
+
return "[#{implementer.clock.iso8601}] #{name} #{level.upcase}: "
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def sufficient_level?(level_ordinal)
|
109
|
+
level_ordinal >= level_number
|
110
|
+
end
|
111
|
+
|
112
|
+
def omit?(level)
|
113
|
+
Defaults.optional == 'off' && optional_level?(level)
|
114
|
+
end
|
115
|
+
|
116
|
+
def optional_level?(level)
|
117
|
+
String(level).start_with?('opt_')
|
118
|
+
end
|
119
|
+
|
120
|
+
def implementer
|
121
|
+
self
|
122
|
+
end
|
123
|
+
|
124
|
+
module Defaults
|
125
|
+
def self.metadata
|
126
|
+
metadata = ENV['LOG_METADATA']
|
127
|
+
return metadata if metadata
|
128
|
+
|
129
|
+
'on'
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.optional
|
133
|
+
optional = ENV['LOG_OPTIONAL']
|
134
|
+
return optional if optional
|
135
|
+
|
136
|
+
'off'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Telemetry
|
2
|
+
module Logger
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def build(subject, implementation=nil)
|
6
|
+
implementation ||= Defaults.implementation
|
7
|
+
logger = implementation.build(subject)
|
8
|
+
logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(subject, implementation=nil)
|
12
|
+
build(subject, implementation)
|
13
|
+
end
|
14
|
+
|
15
|
+
def register(subject, implementation=nil)
|
16
|
+
logger = Logger.build self
|
17
|
+
logger.obsolete "The \"register\" method is obsolete (#{caller[0]}). It is replaced with the \"build\" method."
|
18
|
+
|
19
|
+
build(subject, implementation)
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure(receiver, implementation=nil)
|
23
|
+
logger = build(receiver, implementation)
|
24
|
+
receiver.logger = logger
|
25
|
+
logger
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.debug(message)
|
29
|
+
write message
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.write(message, level=nil, subject=nil, implementation=nil)
|
33
|
+
level ||= :debug
|
34
|
+
subject ||= '***'
|
35
|
+
|
36
|
+
logger = build subject, implementation
|
37
|
+
|
38
|
+
logger.write_message message, level
|
39
|
+
end
|
40
|
+
|
41
|
+
module Defaults
|
42
|
+
def self.implementation
|
43
|
+
ConsoleLogger
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
3
|
+
require 'rainbow'; Rainbow.enabled = true
|
4
|
+
|
5
|
+
require 'pathname'
|
6
|
+
require 'clock'
|
7
|
+
require 'dependency'; Dependency.activate
|
8
|
+
|
9
|
+
require 'telemetry/logger/logger'
|
10
|
+
require 'telemetry/logger/levels'
|
11
|
+
require 'telemetry/logger/color'
|
12
|
+
require 'telemetry/logger/null_object'
|
13
|
+
require 'telemetry/logger/console_logger'
|
14
|
+
require 'telemetry/logger/ad_hoc'
|
15
|
+
require 'telemetry/logger/dependency'
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-telemetry-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evt-clock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: evt-dependency
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rainbow
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ntl-test_bench
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: " "
|
70
|
+
email: opensource@eventide-project.org
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/telemetry/logger.rb
|
76
|
+
- lib/telemetry/logger/ad_hoc.rb
|
77
|
+
- lib/telemetry/logger/color.rb
|
78
|
+
- lib/telemetry/logger/console_logger.rb
|
79
|
+
- lib/telemetry/logger/dependency.rb
|
80
|
+
- lib/telemetry/logger/levels.rb
|
81
|
+
- lib/telemetry/logger/logger.rb
|
82
|
+
- lib/telemetry/logger/null_object.rb
|
83
|
+
homepage: https://github.com/eventide-project/telemetry-logger
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 2.3.3
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Logging to STDERR with coloring and levels of severity
|
107
|
+
test_files: []
|