console 1.11.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -0
- data/lib/console/buffer.rb +2 -0
- data/lib/console/capture.rb +6 -0
- data/lib/console/clock.rb +2 -0
- data/lib/console/event/failure.rb +2 -1
- data/lib/console/event/generic.rb +4 -2
- data/lib/console/event/measure.rb +2 -0
- data/lib/console/event/metric.rb +2 -0
- data/lib/console/event/progress.rb +2 -0
- data/lib/console/event/spawn.rb +11 -4
- data/lib/console/event.rb +2 -0
- data/lib/console/filter.rb +6 -3
- data/lib/console/logger.rb +17 -5
- data/lib/console/measure.rb +2 -0
- data/lib/console/output/default.rb +40 -0
- data/lib/console/output/json.rb +33 -0
- data/lib/console/output/sensitive.rb +120 -0
- data/lib/console/output/text.rb +33 -0
- data/lib/console/output/xterm.rb +33 -0
- data/lib/console/output.rb +42 -0
- data/lib/console/progress.rb +2 -0
- data/lib/console/resolver.rb +31 -8
- data/lib/console/serialized/logger.rb +52 -11
- data/lib/console/split.rb +1 -0
- data/lib/console/terminal/logger.rb +4 -2
- data/lib/console/terminal/text.rb +2 -0
- data/lib/console/terminal/xterm.rb +2 -0
- data/lib/console/terminal.rb +2 -0
- data/lib/console/version.rb +3 -1
- data/lib/console.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +38 -4
- metadata.gz.sig +1 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43a78b129f0b1f778d063513a3726aaa832390761f3987fb3b1b77286f51af1a
|
4
|
+
data.tar.gz: b790c9b840bd37bfcbd6e7f98de70e45bf2d27d049c54b2f9763070edc318a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58e0e37313d0388c439c80a06e3583f57fa96271be8bd1f1e28e3f4a973ba46618143629af6474bc812b8395c51ace42af4de6a5dcc92f281eba9ce1d66d40a
|
7
|
+
data.tar.gz: b472be4850adac00472c1abfcadf3f65fc3d1ad4c180d51eb7ef15cf71831757cc411f393b40ca5b71155d9881bb83a445b3fca1ab481e2a2ae93ada1da62158
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
���u��i��7k�'��È\��a�W�a�0��]:X<�Qw��J��ˈ�
|
data/lib/console/buffer.rb
CHANGED
data/lib/console/capture.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -33,6 +35,10 @@ module Console
|
|
33
35
|
@buffer.last
|
34
36
|
end
|
35
37
|
|
38
|
+
def include?(pattern)
|
39
|
+
JSON.dump(@buffer).include?(pattern)
|
40
|
+
end
|
41
|
+
|
36
42
|
def clear
|
37
43
|
@buffer.clear
|
38
44
|
end
|
data/lib/console/clock.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -27,8 +29,8 @@ module Console
|
|
27
29
|
def to_h
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
to_h
|
32
|
+
def to_json(*arguments)
|
33
|
+
JSON.generate([self.class, to_h], *arguments)
|
32
34
|
end
|
33
35
|
|
34
36
|
def format(buffer, terminal)
|
data/lib/console/event/metric.rb
CHANGED
data/lib/console/event/spawn.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -26,13 +28,14 @@ module Console
|
|
26
28
|
def self.for(*arguments, **options)
|
27
29
|
# Extract out the command environment:
|
28
30
|
if arguments.first.is_a?(Hash)
|
29
|
-
|
31
|
+
environment = arguments.shift
|
32
|
+
self.new(environment, arguments, options)
|
30
33
|
else
|
31
|
-
self.new(nil, arguments,
|
34
|
+
self.new(nil, arguments, options)
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
def initialize(environment,
|
38
|
+
def initialize(environment, arguments, options)
|
36
39
|
@environment = environment
|
37
40
|
@arguments = arguments
|
38
41
|
@options = options
|
@@ -53,7 +56,11 @@ module Console
|
|
53
56
|
end
|
54
57
|
|
55
58
|
def to_h
|
56
|
-
|
59
|
+
Hash.new.tap do |hash|
|
60
|
+
hash[:environment] = @environment if @environment&.any?
|
61
|
+
hash[:arguments] = @arguments if @arguments&.any?
|
62
|
+
hash[:options] = @options if @options&.any?
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
def format(output, terminal, verbose)
|
data/lib/console/event.rb
CHANGED
data/lib/console/filter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -26,11 +28,12 @@ module Console
|
|
26
28
|
class Filter
|
27
29
|
def self.[] **levels
|
28
30
|
klass = Class.new(self)
|
31
|
+
min_level, max_level = levels.values.minmax
|
29
32
|
|
30
33
|
klass.instance_exec do
|
31
34
|
const_set(:LEVELS, levels)
|
32
|
-
const_set(:MINIMUM_LEVEL,
|
33
|
-
const_set(:MAXIMUM_LEVEL,
|
35
|
+
const_set(:MINIMUM_LEVEL, min_level)
|
36
|
+
const_set(:MAXIMUM_LEVEL, max_level)
|
34
37
|
|
35
38
|
levels.each do |name, level|
|
36
39
|
const_set(name.to_s.upcase, level)
|
@@ -102,7 +105,7 @@ module Console
|
|
102
105
|
end
|
103
106
|
|
104
107
|
def all!
|
105
|
-
@level = -1
|
108
|
+
@level = self.class::MINIMUM_LEVEL - 1
|
106
109
|
end
|
107
110
|
|
108
111
|
# You can enable and disable logging for classes. This function checks if logging for a given subject is enabled.
|
data/lib/console/logger.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -18,12 +20,14 @@
|
|
18
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
21
|
# THE SOFTWARE.
|
20
22
|
|
23
|
+
require_relative 'output'
|
21
24
|
require_relative 'filter'
|
22
25
|
require_relative 'measure'
|
23
26
|
require_relative 'progress'
|
24
27
|
|
25
28
|
require_relative 'resolver'
|
26
29
|
require_relative 'terminal/logger'
|
30
|
+
require_relative 'serialized/logger'
|
27
31
|
|
28
32
|
require 'fiber/local'
|
29
33
|
|
@@ -35,7 +39,7 @@ module Console
|
|
35
39
|
# You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
|
36
40
|
# https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
|
37
41
|
def self.default_log_level(env = ENV)
|
38
|
-
if level =
|
42
|
+
if level = env['CONSOLE_LEVEL']
|
39
43
|
LEVELS[level.to_sym] || level.to_i
|
40
44
|
elsif $DEBUG
|
41
45
|
DEBUG
|
@@ -51,17 +55,25 @@ module Console
|
|
51
55
|
!$VERBOSE.nil? || env['CONSOLE_VERBOSE']
|
52
56
|
end
|
53
57
|
|
54
|
-
def self.default_logger(output,
|
55
|
-
|
58
|
+
def self.default_logger(output = $stderr, env = ENV, **options)
|
59
|
+
if options[:verbose].nil?
|
60
|
+
options[:verbose] = self.verbose?(env)
|
61
|
+
end
|
62
|
+
|
63
|
+
if options[:level].nil?
|
64
|
+
options[:level] = self.default_log_level(env)
|
65
|
+
end
|
66
|
+
|
67
|
+
output = Output.new(output, env, **options)
|
68
|
+
logger = self.new(output, **options)
|
56
69
|
|
57
|
-
logger = self.new(terminal, verbose: verbose, level: level)
|
58
70
|
Resolver.default_resolver(logger)
|
59
71
|
|
60
72
|
return logger
|
61
73
|
end
|
62
74
|
|
63
75
|
def self.local
|
64
|
-
self.default_logger
|
76
|
+
self.default_logger
|
65
77
|
end
|
66
78
|
|
67
79
|
DEFAULT_LEVEL = 1
|
data/lib/console/measure.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative 'xterm'
|
24
|
+
require_relative 'json'
|
25
|
+
|
26
|
+
module Console
|
27
|
+
module Output
|
28
|
+
module Default
|
29
|
+
def self.new(output, **options)
|
30
|
+
output ||= $stderr
|
31
|
+
|
32
|
+
if output.tty?
|
33
|
+
XTerm.new(output, **options)
|
34
|
+
else
|
35
|
+
JSON.new(output, **options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../serialized/logger'
|
24
|
+
|
25
|
+
module Console
|
26
|
+
module Output
|
27
|
+
module JSON
|
28
|
+
def self.new(output, **options)
|
29
|
+
Serialized::Logger.new(output, format: ::JSON, **options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../serialized/logger'
|
24
|
+
|
25
|
+
module Console
|
26
|
+
module Output
|
27
|
+
class Sensitive
|
28
|
+
def initialize(output, **options)
|
29
|
+
@output = output
|
30
|
+
end
|
31
|
+
|
32
|
+
REDACT = /
|
33
|
+
phone
|
34
|
+
| email
|
35
|
+
| full_?name
|
36
|
+
| first_?name
|
37
|
+
| last_?name
|
38
|
+
|
39
|
+
| device_name
|
40
|
+
| user_agent
|
41
|
+
|
42
|
+
| zip
|
43
|
+
| address
|
44
|
+
| location
|
45
|
+
| latitude
|
46
|
+
| longitude
|
47
|
+
|
48
|
+
| ip
|
49
|
+
| gps
|
50
|
+
|
51
|
+
| sex
|
52
|
+
| gender
|
53
|
+
|
54
|
+
| token
|
55
|
+
| password
|
56
|
+
/xi
|
57
|
+
|
58
|
+
def redact?(text)
|
59
|
+
text.match?(REDACT)
|
60
|
+
end
|
61
|
+
|
62
|
+
def redact_hash(arguments, filter)
|
63
|
+
arguments.transform_values do |value|
|
64
|
+
redact(value, filter)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def redact_array(array, filter)
|
69
|
+
array.map do |value|
|
70
|
+
redact(value, filter)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def redact(argument, filter)
|
75
|
+
case argument
|
76
|
+
when String
|
77
|
+
if filter
|
78
|
+
filter.call(argument)
|
79
|
+
elsif redact?(argument)
|
80
|
+
"[REDACTED]"
|
81
|
+
else
|
82
|
+
argument
|
83
|
+
end
|
84
|
+
when Array
|
85
|
+
redact_array(argument, filter)
|
86
|
+
when Hash
|
87
|
+
redact_hash(argument, filter)
|
88
|
+
else
|
89
|
+
redact(argument.to_s, filter)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Filter
|
94
|
+
def initialize(substitutions)
|
95
|
+
@substitutions = substitutions
|
96
|
+
@pattern = Regexp.union(substitutions.keys)
|
97
|
+
end
|
98
|
+
|
99
|
+
def call(text)
|
100
|
+
text.gsub(@pattern, @substitutions)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def call(subject = nil, *arguments, sensitive: true, **options, &block)
|
105
|
+
if sensitive
|
106
|
+
if sensitive.respond_to?(:call)
|
107
|
+
filter = sensitive
|
108
|
+
elsif sensitive.is_a?(Hash)
|
109
|
+
filter = Filter.new(sensitive)
|
110
|
+
end
|
111
|
+
|
112
|
+
subject = redact(subject, filter)
|
113
|
+
arguments = redact_array(arguments, filter)
|
114
|
+
end
|
115
|
+
|
116
|
+
@output.call(subject, *arguments, **options)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../terminal/logger'
|
24
|
+
|
25
|
+
module Console
|
26
|
+
module Output
|
27
|
+
module Text
|
28
|
+
def self.new(output, **options)
|
29
|
+
Terminal::Logger.new(output, format: Terminal::Text, **options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../terminal/logger'
|
24
|
+
|
25
|
+
module Console
|
26
|
+
module Output
|
27
|
+
module XTerm
|
28
|
+
def self.new(output, **options)
|
29
|
+
Terminal::Logger.new(output, format: Terminal::XTerm, **options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative 'output/default'
|
24
|
+
require_relative 'output/json'
|
25
|
+
require_relative 'output/text'
|
26
|
+
require_relative 'output/xterm'
|
27
|
+
|
28
|
+
module Console
|
29
|
+
module Output
|
30
|
+
def self.new(output = nil, env = ENV, **options)
|
31
|
+
if names = env['CONSOLE_OUTPUT']
|
32
|
+
names = names.split(',').reverse
|
33
|
+
|
34
|
+
names.inject(output) do |output, name|
|
35
|
+
Output.const_get(name).new(output, **options)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
return Output::Default.new(output, **options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/console/progress.rb
CHANGED
data/lib/console/resolver.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -26,6 +28,8 @@ module Console
|
|
26
28
|
#
|
27
29
|
# e.g. `CONSOLE_WARN=Acorn,Banana CONSOLE_DEBUG=Cat` will set the log level for the classes Acorn and Banana to `warn` and Cat to `debug`. This overrides the default log level.
|
28
30
|
#
|
31
|
+
# You can enable all log levels for a given class by using `CONSOLE_ON=MyClass`. Similarly you can disable all logging using `CONSOLE_OFF=MyClass`.
|
32
|
+
#
|
29
33
|
# @parameter logger [Logger] A logger instance to set the logging levels on.
|
30
34
|
# @parameter env [Hash] The environment to read levels from.
|
31
35
|
#
|
@@ -33,23 +37,42 @@ module Console
|
|
33
37
|
# @returns [Resolver] If there were custom logging levels, then the created resolver is returned.
|
34
38
|
def self.default_resolver(logger, env = ENV)
|
35
39
|
# Find all CONSOLE_<LEVEL> variables from environment:
|
36
|
-
levels =
|
40
|
+
levels = logger.class::LEVELS
|
37
41
|
.map{|label, level| [level, env["CONSOLE_#{label.upcase}"]&.split(',')]}
|
38
42
|
.to_h
|
39
43
|
.compact
|
40
44
|
|
45
|
+
off_klasses = env['CONSOLE_OFF']&.split(',')
|
46
|
+
on_klasses = env['CONSOLE_ON']&.split(',')
|
47
|
+
|
48
|
+
resolver = nil
|
49
|
+
|
41
50
|
# If we have any levels, then create a class resolver, and each time a class is resolved, set the log level for that class to the specified level:
|
42
|
-
if
|
43
|
-
resolver
|
51
|
+
if on_klasses&.any?
|
52
|
+
resolver ||= Resolver.new
|
53
|
+
|
54
|
+
resolver.bind(on_klasses) do |klass|
|
55
|
+
logger.enable(klass, logger.class::MINIMUM_LEVEL - 1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if off_klasses&.any?
|
60
|
+
resolver ||= Resolver.new
|
44
61
|
|
45
|
-
|
46
|
-
|
47
|
-
logger.enable(klass, level)
|
48
|
-
end
|
62
|
+
resolver.bind(off_klasses) do |klass|
|
63
|
+
logger.disable(klass)
|
49
64
|
end
|
65
|
+
end
|
66
|
+
|
67
|
+
levels.each do |level, names|
|
68
|
+
resolver ||= Resolver.new
|
50
69
|
|
51
|
-
|
70
|
+
resolver.bind(names) do |klass|
|
71
|
+
logger.enable(klass, level)
|
72
|
+
end
|
52
73
|
end
|
74
|
+
|
75
|
+
return resolver
|
53
76
|
end
|
54
77
|
|
55
78
|
def initialize
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -27,10 +29,11 @@ require 'json'
|
|
27
29
|
module Console
|
28
30
|
module Serialized
|
29
31
|
class Logger
|
30
|
-
def initialize(io = $stderr, format: JSON)
|
32
|
+
def initialize(io = $stderr, format: JSON, verbose: false, **options)
|
31
33
|
@io = io
|
32
34
|
@start = Time.now
|
33
35
|
@format = format
|
36
|
+
@verbose = verbose
|
34
37
|
end
|
35
38
|
|
36
39
|
attr :io
|
@@ -38,6 +41,11 @@ module Console
|
|
38
41
|
attr :format
|
39
42
|
|
40
43
|
def verbose!(value = true)
|
44
|
+
@verbose = true
|
45
|
+
end
|
46
|
+
|
47
|
+
def dump(record)
|
48
|
+
@format.dump(record)
|
41
49
|
end
|
42
50
|
|
43
51
|
def call(subject = nil, *arguments, severity: UNKNOWN, **options, &block)
|
@@ -53,25 +61,58 @@ module Console
|
|
53
61
|
record[:subject] = subject
|
54
62
|
end
|
55
63
|
|
56
|
-
|
57
|
-
record[:arguments] = arguments
|
58
|
-
end
|
59
|
-
|
60
|
-
if options.any?
|
61
|
-
record[:options] = options
|
62
|
-
end
|
64
|
+
message = arguments
|
63
65
|
|
64
66
|
if block_given?
|
65
67
|
if block.arity.zero?
|
66
|
-
|
68
|
+
message << yield
|
67
69
|
else
|
68
70
|
buffer = StringIO.new
|
69
71
|
yield buffer
|
70
|
-
|
72
|
+
message << buffer.string
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
|
76
|
+
if message.size == 1
|
77
|
+
record[:message] = message.first
|
78
|
+
elsif message.any?
|
79
|
+
record[:message] = message
|
80
|
+
end
|
81
|
+
|
82
|
+
if exception = find_exception(message)
|
83
|
+
record[:error] = {
|
84
|
+
kind: exception.class,
|
85
|
+
message: exception.message,
|
86
|
+
stack: format_stack(exception)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
record.update(options)
|
91
|
+
|
92
|
+
@io.puts(self.dump(record))
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def find_exception(message)
|
98
|
+
message.find{|part| part.is_a?(Exception)}
|
99
|
+
end
|
100
|
+
|
101
|
+
def format_stack(exception)
|
102
|
+
buffer = StringIO.new
|
103
|
+
format_backtrace(exception, buffer)
|
104
|
+
return buffer.string
|
105
|
+
end
|
106
|
+
|
107
|
+
def format_backtrace(exception, buffer)
|
108
|
+
buffer.puts exception.backtrace
|
109
|
+
|
110
|
+
if exception = exception.cause
|
111
|
+
buffer.puts
|
112
|
+
buffer.puts "Caused by: #{exception.class} #{exception.message}"
|
113
|
+
|
114
|
+
format_backtrace(exception, buffer)
|
115
|
+
end
|
75
116
|
end
|
76
117
|
end
|
77
118
|
end
|
data/lib/console/split.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -55,11 +57,11 @@ module Console
|
|
55
57
|
end
|
56
58
|
|
57
59
|
class Logger
|
58
|
-
def initialize(io = $stderr, verbose: nil, start_at: Terminal.start_at!, **options)
|
60
|
+
def initialize(io = $stderr, verbose: nil, start_at: Terminal.start_at!, format: nil, **options)
|
59
61
|
@io = io
|
60
62
|
@start_at = start_at
|
61
63
|
|
62
|
-
@terminal = Terminal.for(io)
|
64
|
+
@terminal = format.nil? ? Terminal.for(io) : format.new(io)
|
63
65
|
|
64
66
|
if verbose.nil?
|
65
67
|
@verbose = !@terminal.colors?
|
data/lib/console/terminal.rb
CHANGED
data/lib/console/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -19,5 +21,5 @@
|
|
19
21
|
# THE SOFTWARE.
|
20
22
|
|
21
23
|
module Console
|
22
|
-
VERSION = "1.
|
24
|
+
VERSION = "1.14.0"
|
23
25
|
end
|
data/lib/console.rb
CHANGED
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
14
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
15
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
16
|
+
aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
|
17
|
+
AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
|
18
|
+
xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
|
19
|
+
eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2Kfsr+JtKKLtL
|
20
|
+
L188Wm3f13KAx7QJU8qyuBnj1/gWem076hzdA7xi1DbrZrch9GCRz62xymJlrJHn
|
21
|
+
9iZEZ7AxrS7vokhMlzSr/XMUihx/8aFKtk+tMLClqxZSmBWIErWdicCGTULXCBNb
|
22
|
+
E/mljo4zEVKhlTWpJklMIhr55ZRrSarKFuW7en0+tpJrfsYiAmXMJNi4XAYJH7uL
|
23
|
+
rgJuJwSaa/dMz+VmUoo7VKtSfCoOI+6v5/z0sK3oT6sG6ZwyI47DBq2XqNC6tnAj
|
24
|
+
w+XmCywiTQrFzMMAvcA7rPI4F0nU1rZId51rOvvfxaONp+wgTi4P8owZLw0/j0m4
|
25
|
+
8C20DYi6EYx4AHDXiLpElWh3AgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8E
|
26
|
+
BAMCBLAwHQYDVR0OBBYEFB6ZaeWKxQjGTI+pmz7cKRmMIywwMC4GA1UdEQQnMCWB
|
27
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWB
|
28
|
+
I3NhbXVlbC53aWxsaWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEB
|
29
|
+
CwUAA4IBgQBVoM+pu3dpdUhZM1w051iw5GfiqclAr1Psypf16Tiod/ho//4oAu6T
|
30
|
+
9fj3DPX/acWV9P/FScvqo4Qgv6g4VWO5ZU7z2JmPoTXZtYMunRAmQPFL/gSUc6aK
|
31
|
+
vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
|
32
|
+
x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
|
33
|
+
bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
|
34
|
+
Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
|
35
|
+
y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
|
36
|
+
RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
|
37
|
+
HiLJ8VOFx6w=
|
38
|
+
-----END CERTIFICATE-----
|
39
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
40
|
dependencies:
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: fiber-local
|
@@ -115,6 +143,12 @@ files:
|
|
115
143
|
- lib/console/filter.rb
|
116
144
|
- lib/console/logger.rb
|
117
145
|
- lib/console/measure.rb
|
146
|
+
- lib/console/output.rb
|
147
|
+
- lib/console/output/default.rb
|
148
|
+
- lib/console/output/json.rb
|
149
|
+
- lib/console/output/sensitive.rb
|
150
|
+
- lib/console/output/text.rb
|
151
|
+
- lib/console/output/xterm.rb
|
118
152
|
- lib/console/progress.rb
|
119
153
|
- lib/console/resolver.rb
|
120
154
|
- lib/console/serialized/logger.rb
|
@@ -143,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
177
|
- !ruby/object:Gem::Version
|
144
178
|
version: '0'
|
145
179
|
requirements: []
|
146
|
-
rubygems_version: 3.2.
|
180
|
+
rubygems_version: 3.2.29
|
147
181
|
signing_key:
|
148
182
|
specification_version: 4
|
149
183
|
summary: Beautiful logging for Ruby.
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
H�.��������Y��Ʒ�~m�:�M�.�̄��@hu|��֊���{�#�2#�
|