console 1.10.2 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console/clock.rb +50 -0
- data/lib/console/event/failure.rb +10 -5
- data/lib/console/event/measure.rb +42 -0
- data/lib/console/event/metric.rb +10 -1
- data/lib/console/logger.rb +10 -2
- data/lib/console/measure.rb +46 -0
- data/lib/console/terminal/logger.rb +15 -13
- data/lib/console/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5928a2a5d4c07c44e8ad937edbab2b8fa326ff13553ffb4bf89c0854184f1bd8
|
4
|
+
data.tar.gz: e0495d1933a3a0991b23193aae3988fb679389f02514d57c9a15ce7ccbf73497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69af353f0397d3620654d9108b2cb7fffe4d601e4a4f9feea7cdf09a7cd40aa3f310faded79abfc8de5735c257b59713bb9d5a91d5320a1dca15d0df4a92804
|
7
|
+
data.tar.gz: c46ec0e33e56260345710facc882d89edb4782179ccdb7ec97ed70c3d83087465b4758ceecdaa7f8ac4e2508dc18f46968974bee19a694c62c5314157a8402fe
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Console
|
22
|
+
module Clock
|
23
|
+
def self.formatted_duration(duration)
|
24
|
+
if duration < 60.0
|
25
|
+
return "#{duration.round(2)}s"
|
26
|
+
end
|
27
|
+
|
28
|
+
duration /= 60.0
|
29
|
+
|
30
|
+
if duration < 60.0
|
31
|
+
return "#{duration.round}m"
|
32
|
+
end
|
33
|
+
|
34
|
+
duration /= 60.0
|
35
|
+
|
36
|
+
if duration < 60.0
|
37
|
+
return "#{duration.round(1)}h"
|
38
|
+
end
|
39
|
+
|
40
|
+
duration /= 24.0
|
41
|
+
|
42
|
+
return "#{duration.round(1)}d"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get the current elapsed monotonic time.
|
46
|
+
def self.now
|
47
|
+
::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -47,6 +47,8 @@ module Console
|
|
47
47
|
terminal[:exception_title] ||= terminal.style(:red, nil, :bold)
|
48
48
|
terminal[:exception_detail] ||= terminal.style(:yellow)
|
49
49
|
terminal[:exception_backtrace] ||= terminal.style(:red)
|
50
|
+
terminal[:exception_backtrace_other] ||= terminal.style(:red, nil, :faint)
|
51
|
+
terminal[:exception_message] ||= terminal.style(:default)
|
50
52
|
end
|
51
53
|
|
52
54
|
def to_h
|
@@ -66,15 +68,18 @@ module Console
|
|
66
68
|
output.puts " #{terminal[:exception_detail]}#{line}#{terminal.reset}"
|
67
69
|
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
root_pattern = /^#{@root}\// if @root
|
72
|
+
|
71
73
|
exception.backtrace&.each_with_index do |line, index|
|
72
74
|
path, offset, message = line.split(":")
|
75
|
+
style = :exception_backtrace
|
73
76
|
|
74
77
|
# Make the path a bit more readable
|
75
|
-
path.sub!(
|
76
|
-
|
77
|
-
|
78
|
+
if root_pattern and path.sub!(root_pattern, "").nil?
|
79
|
+
style = :exception_backtrace_other
|
80
|
+
end
|
81
|
+
|
82
|
+
output.puts " #{index == 0 ? "→" : " "} #{terminal[style]}#{path}:#{offset}#{terminal[:exception_message]} #{message}#{terminal.reset}"
|
78
83
|
end
|
79
84
|
|
80
85
|
if exception.cause
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'metric'
|
22
|
+
require_relative '../clock'
|
23
|
+
|
24
|
+
module Console
|
25
|
+
module Event
|
26
|
+
class Enter < Generic
|
27
|
+
def initialize(name)
|
28
|
+
@name = name
|
29
|
+
end
|
30
|
+
|
31
|
+
def format(output, terminal, verbose)
|
32
|
+
output.puts "→ #{@name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Exit < Metric
|
37
|
+
def value_string
|
38
|
+
"← #{@name} took #{Clock.formatted_duration(@value)}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/console/event/metric.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'generic'
|
22
|
+
require_relative '../clock'
|
22
23
|
|
23
24
|
module Console
|
24
25
|
module Event
|
@@ -41,8 +42,16 @@ module Console
|
|
41
42
|
{name: @name, value: @value, tags: @tags}
|
42
43
|
end
|
43
44
|
|
45
|
+
def value_string
|
46
|
+
"#{@name}: #{@value}"
|
47
|
+
end
|
48
|
+
|
44
49
|
def format(output, terminal, verbose)
|
45
|
-
|
50
|
+
if @tags&.any?
|
51
|
+
output.puts "#{value_string} #{@tags.inspect}"
|
52
|
+
else
|
53
|
+
output.puts value_string
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
48
57
|
end
|
data/lib/console/logger.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'filter'
|
22
|
+
require_relative 'measure'
|
22
23
|
require_relative 'progress'
|
23
24
|
|
24
25
|
require_relative 'resolver'
|
@@ -73,8 +74,15 @@ module Console
|
|
73
74
|
Progress.new(self, subject, total, **options)
|
74
75
|
end
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
def measure(subject, name = "block", **options, &block)
|
78
|
+
measure = Measure.new(self, subject)
|
79
|
+
|
80
|
+
if block_given?
|
81
|
+
measure.duration(name, **options, &block)
|
82
|
+
end
|
83
|
+
|
84
|
+
return measure
|
85
|
+
end
|
78
86
|
|
79
87
|
def failure(subject, exception, *arguments, &block)
|
80
88
|
fatal(subject, *arguments, Event::Failure.new(exception), &block)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'event/measure'
|
22
|
+
require_relative 'clock'
|
23
|
+
|
24
|
+
module Console
|
25
|
+
class Measure
|
26
|
+
def initialize(output, subject)
|
27
|
+
@output = output
|
28
|
+
@subject = subject
|
29
|
+
end
|
30
|
+
|
31
|
+
# Measure the execution of a block of code.
|
32
|
+
def duration(name, **tags, &block)
|
33
|
+
@output.info(@subject) {Event::Enter.new(name)}
|
34
|
+
|
35
|
+
start_time = Clock.now
|
36
|
+
|
37
|
+
yield
|
38
|
+
|
39
|
+
duration = Clock.now - start_time
|
40
|
+
|
41
|
+
@output.info(@subject) {Event::Exit.new(name, duration, **tags)}
|
42
|
+
|
43
|
+
return duration
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -25,6 +25,7 @@ require_relative 'text'
|
|
25
25
|
require_relative 'xterm'
|
26
26
|
|
27
27
|
require 'json'
|
28
|
+
require 'fiber'
|
28
29
|
|
29
30
|
module Console
|
30
31
|
module Terminal
|
@@ -66,7 +67,6 @@ module Console
|
|
66
67
|
@verbose = verbose
|
67
68
|
end
|
68
69
|
|
69
|
-
@terminal[:logger_prefix] ||= @terminal.style(nil, nil, nil)
|
70
70
|
@terminal[:logger_suffix] ||= @terminal.style(:white, nil, :faint)
|
71
71
|
@terminal[:subject] ||= @terminal.style(nil, nil, :bold)
|
72
72
|
@terminal[:debug] = @terminal.style(:cyan)
|
@@ -136,7 +136,7 @@ module Console
|
|
136
136
|
def format_argument(argument, output)
|
137
137
|
case argument
|
138
138
|
when Exception
|
139
|
-
Event::Failure.
|
139
|
+
Event::Failure.for(argument).format(output, @terminal, @verbose)
|
140
140
|
when Event::Generic
|
141
141
|
argument.format(output, @terminal, @verbose)
|
142
142
|
else
|
@@ -154,11 +154,21 @@ module Console
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
def default_suffix(object = nil)
|
158
|
+
buffer = +" #{@terminal[:logger_suffix]}"
|
159
|
+
|
160
|
+
if object
|
161
|
+
buffer << "[oid=0x#{object.object_id.to_s(16)}] "
|
162
|
+
end
|
163
|
+
|
164
|
+
buffer << "[ec=0x#{Fiber.current.object_id.to_s(16)}] [pid=#{Process.pid}] [#{::Time.now}]#{@terminal.reset}"
|
165
|
+
end
|
166
|
+
|
157
167
|
def format_object_subject(severity, prefix, subject, output)
|
158
168
|
prefix_style = @terminal[severity]
|
159
169
|
|
160
170
|
if @verbose
|
161
|
-
suffix =
|
171
|
+
suffix = default_suffix(subject)
|
162
172
|
end
|
163
173
|
|
164
174
|
prefix = "#{prefix_style}#{prefix}:#{@terminal.reset} "
|
@@ -170,7 +180,7 @@ module Console
|
|
170
180
|
prefix_style = @terminal[severity]
|
171
181
|
|
172
182
|
if @verbose
|
173
|
-
suffix =
|
183
|
+
suffix = default_suffix
|
174
184
|
end
|
175
185
|
|
176
186
|
prefix = "#{prefix_style}#{prefix}:#{@terminal.reset} "
|
@@ -187,15 +197,7 @@ module Console
|
|
187
197
|
end
|
188
198
|
|
189
199
|
def time_offset_prefix
|
190
|
-
|
191
|
-
minutes = (offset/60).floor
|
192
|
-
seconds = (offset - (minutes*60))
|
193
|
-
|
194
|
-
if minutes > 0
|
195
|
-
"#{minutes}m#{seconds.floor}s"
|
196
|
-
else
|
197
|
-
"#{seconds.round(2)}s"
|
198
|
-
end.rjust(6)
|
200
|
+
Clock.formatted_duration(Time.now - @start_at).rjust(6)
|
199
201
|
end
|
200
202
|
|
201
203
|
def build_prefix(name)
|
data/lib/console/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fiber-local
|
@@ -104,14 +104,17 @@ files:
|
|
104
104
|
- lib/console.rb
|
105
105
|
- lib/console/buffer.rb
|
106
106
|
- lib/console/capture.rb
|
107
|
+
- lib/console/clock.rb
|
107
108
|
- lib/console/event.rb
|
108
109
|
- lib/console/event/failure.rb
|
109
110
|
- lib/console/event/generic.rb
|
111
|
+
- lib/console/event/measure.rb
|
110
112
|
- lib/console/event/metric.rb
|
111
113
|
- lib/console/event/progress.rb
|
112
114
|
- lib/console/event/spawn.rb
|
113
115
|
- lib/console/filter.rb
|
114
116
|
- lib/console/logger.rb
|
117
|
+
- lib/console/measure.rb
|
115
118
|
- lib/console/progress.rb
|
116
119
|
- lib/console/resolver.rb
|
117
120
|
- lib/console/serialized/logger.rb
|