console 1.9.1 → 1.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console.rb +7 -66
- data/lib/console/clock.rb +50 -0
- data/lib/console/event/failure.rb +9 -2
- data/lib/console/event/measure.rb +42 -0
- data/lib/console/event/metric.rb +10 -1
- data/lib/console/logger.rb +50 -2
- data/lib/console/measure.rb +49 -0
- data/lib/console/progress.rb +5 -24
- data/lib/console/resolver.rb +30 -0
- data/lib/console/terminal/logger.rb +15 -13
- data/lib/console/version.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149a9d0738e731ea3ef3159cd25a449f663070406dfa232538a5996fb93c9ce9
|
4
|
+
data.tar.gz: 212772395d4aef7dc7a510d6630e11dfabeb4c8cf2c70f5d272c279a3d2a32ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d02021cfb6dbf99651d5f1b8653394dd59f2c830b0a62b8c394b70b275030cd2c066a786a9cb1281df55029f9a69455c00a73a1763785cba3a5ccf8769766654
|
7
|
+
data.tar.gz: be05f291ccae55c3a6cce6ed2e5e79fa968682d856bcc502693408c69cc85b563017e8505a0459f6cb0d628bbdc57b58efd28146b460e09b45695652e6263145
|
data/lib/console.rb
CHANGED
@@ -20,83 +20,24 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
+
require_relative 'console/version'
|
23
24
|
require_relative 'console/logger'
|
24
|
-
require_relative 'console/resolver'
|
25
|
-
require_relative 'console/terminal/logger'
|
26
25
|
|
27
26
|
module Console
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# Set the default log level based on `$DEBUG` and `$VERBOSE`.
|
32
|
-
# You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
|
33
|
-
# https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
|
34
|
-
def default_log_level(env = ENV)
|
35
|
-
if level = (env['CONSOLE_LEVEL'] || env['CONSOLE_LOG_LEVEL'])
|
36
|
-
Logger::LEVELS[level.to_sym] || Logger.warn
|
37
|
-
elsif $DEBUG
|
38
|
-
Logger::DEBUG
|
39
|
-
elsif $VERBOSE.nil?
|
40
|
-
Logger::WARN
|
41
|
-
else
|
42
|
-
Logger::INFO
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# You can change the log level for different classes using CONSOLE_<LEVEL> env vars.
|
47
|
-
#
|
48
|
-
# e.g. `CONSOLE_WARN=Acorn,Banana CONSOLE_DEBUG=Cat` will set the log level for Acorn and Banana to warn and Cat to
|
49
|
-
# debug. This overrides the default log level.
|
50
|
-
#
|
51
|
-
# @param logger [Logger] A logger instance to set the logging levels on.
|
52
|
-
# @param env [Hash] Environment to read levels from.
|
53
|
-
#
|
54
|
-
# @return [nil] if there were no custom logging levels specified in the environment.
|
55
|
-
# @return [Resolver] if there were custom logging levels, then the created resolver is returned.
|
56
|
-
def default_resolver(logger, env = ENV)
|
57
|
-
# find all CONSOLE_<LEVEL> variables from environment
|
58
|
-
levels = Logger::LEVELS
|
59
|
-
.map { |label, level| [level, env["CONSOLE_#{label.to_s.upcase}"]&.split(',')] }
|
60
|
-
.to_h
|
61
|
-
.compact
|
62
|
-
|
63
|
-
# if we have any levels, then create a class resolver, and each time a class is resolved, set the log level for
|
64
|
-
# that class to the specified level
|
65
|
-
if levels.any?
|
66
|
-
resolver = Resolver.new
|
67
|
-
levels.each do |level, names|
|
68
|
-
resolver.bind(names) do |klass|
|
69
|
-
logger.enable(klass, level)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
return resolver
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Controls verbose output using `$VERBOSE`.
|
77
|
-
def verbose?
|
78
|
-
!$VERBOSE.nil?
|
79
|
-
end
|
80
|
-
|
81
|
-
def build(output, verbose: self.verbose?, level: self.default_log_level)
|
82
|
-
terminal = Terminal::Logger.new(output, verbose: verbose)
|
83
|
-
|
84
|
-
logger = Logger.new(terminal, verbose: verbose, level: level)
|
85
|
-
|
86
|
-
return logger
|
87
|
-
end
|
27
|
+
def self.logger
|
28
|
+
Logger.instance
|
88
29
|
end
|
89
30
|
|
90
|
-
|
91
|
-
|
92
|
-
|
31
|
+
def self.logger= instance
|
32
|
+
Logger.instance= instance
|
33
|
+
end
|
93
34
|
|
94
35
|
def logger= logger
|
95
36
|
@logger = logger
|
96
37
|
end
|
97
38
|
|
98
39
|
def logger
|
99
|
-
@logger ||
|
40
|
+
@logger || Logger.instance
|
100
41
|
end
|
101
42
|
|
102
43
|
def self.extended(klass)
|
@@ -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,13 +68,18 @@ module Console
|
|
66
68
|
output.puts " #{terminal[:exception_detail]}#{line}#{terminal.reset}"
|
67
69
|
end
|
68
70
|
|
71
|
+
root_pattern = /^#{@root}\// if @root
|
72
|
+
|
69
73
|
exception.backtrace&.each_with_index do |line, index|
|
70
74
|
path, offset, message = line.split(":")
|
75
|
+
style = :exception_backtrace
|
71
76
|
|
72
77
|
# Make the path a bit more readable
|
73
|
-
path.
|
78
|
+
if root_pattern and path.sub!(root_pattern, "").nil?
|
79
|
+
style = :exception_backtrace_other
|
80
|
+
end
|
74
81
|
|
75
|
-
output.puts " #{index == 0 ? "→" : " "} #{terminal[
|
82
|
+
output.puts " #{index == 0 ? "→" : " "} #{terminal[style]}#{path}:#{offset}#{terminal[:exception_message]} #{message}#{terminal.reset}"
|
76
83
|
end
|
77
84
|
|
78
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,10 +19,51 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'filter'
|
22
|
+
require_relative 'measure'
|
22
23
|
require_relative 'progress'
|
23
24
|
|
25
|
+
require_relative 'resolver'
|
26
|
+
require_relative 'terminal/logger'
|
27
|
+
|
28
|
+
require 'fiber/local'
|
29
|
+
|
24
30
|
module Console
|
25
31
|
class Logger < Filter[debug: 0, info: 1, warn: 2, error: 3, fatal: 4]
|
32
|
+
extend Fiber::Local
|
33
|
+
|
34
|
+
# Set the default log level based on `$DEBUG` and `$VERBOSE`.
|
35
|
+
# You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
|
36
|
+
# https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
|
37
|
+
def self.default_log_level(env = ENV)
|
38
|
+
if level = (env['CONSOLE_LEVEL'] || env['CONSOLE_LOG_LEVEL'])
|
39
|
+
LEVELS[level.to_sym] || level.to_i
|
40
|
+
elsif $DEBUG
|
41
|
+
DEBUG
|
42
|
+
elsif $VERBOSE.nil?
|
43
|
+
WARN
|
44
|
+
else
|
45
|
+
INFO
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Controls verbose output using `$VERBOSE`.
|
50
|
+
def self.verbose?(env = ENV)
|
51
|
+
!$VERBOSE.nil? || env['CONSOLE_VERBOSE']
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.default_logger(output, verbose: self.verbose?, level: self.default_log_level)
|
55
|
+
terminal = Terminal::Logger.new(output, verbose: verbose)
|
56
|
+
|
57
|
+
logger = self.new(terminal, verbose: verbose, level: level)
|
58
|
+
Resolver.default_resolver(logger)
|
59
|
+
|
60
|
+
return logger
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.local
|
64
|
+
self.default_logger($stderr)
|
65
|
+
end
|
66
|
+
|
26
67
|
DEFAULT_LEVEL = 1
|
27
68
|
|
28
69
|
def initialize(output, **options)
|
@@ -33,8 +74,15 @@ module Console
|
|
33
74
|
Progress.new(self, subject, total, **options)
|
34
75
|
end
|
35
76
|
|
36
|
-
|
37
|
-
|
77
|
+
def measure(subject, name = "block", **tags, &block)
|
78
|
+
measure = Measure.new(self, subject, **tags)
|
79
|
+
|
80
|
+
if block_given?
|
81
|
+
return measure.duration(name, &block)
|
82
|
+
else
|
83
|
+
return measure
|
84
|
+
end
|
85
|
+
end
|
38
86
|
|
39
87
|
def failure(subject, exception, *arguments, &block)
|
40
88
|
fatal(subject, *arguments, Event::Failure.new(exception), &block)
|
@@ -0,0 +1,49 @@
|
|
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, **tags)
|
27
|
+
@output = output
|
28
|
+
@subject = subject
|
29
|
+
@tags = tags
|
30
|
+
end
|
31
|
+
|
32
|
+
attr :tags
|
33
|
+
|
34
|
+
# Measure the execution of a block of code.
|
35
|
+
def duration(name, &block)
|
36
|
+
@output.info(@subject) {Event::Enter.new(name)}
|
37
|
+
|
38
|
+
start_time = Clock.now
|
39
|
+
|
40
|
+
result = yield(self)
|
41
|
+
|
42
|
+
duration = Clock.now - start_time
|
43
|
+
|
44
|
+
@output.info(@subject) {Event::Exit.new(name, duration, **@tags)}
|
45
|
+
|
46
|
+
return result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/console/progress.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'event/progress'
|
22
|
+
require_relative 'clock'
|
22
23
|
|
23
24
|
module Console
|
24
25
|
class Progress
|
@@ -93,7 +94,7 @@ module Console
|
|
93
94
|
|
94
95
|
def to_s
|
95
96
|
if estimated_remaining_time = self.estimated_remaining_time
|
96
|
-
"#{@current}/#{@total} completed in #{
|
97
|
+
"#{@current}/#{@total} completed in #{Clock.formatted_duration(self.duration)}, #{Clock.formatted_duration(estimated_remaining_time)} remaining."
|
97
98
|
else
|
98
99
|
"#{@current}/#{@total} completed, waiting for estimate..."
|
99
100
|
end
|
@@ -108,33 +109,13 @@ module Console
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def output?
|
111
|
-
if
|
112
|
+
if remaining.zero?
|
113
|
+
return true
|
114
|
+
elsif duration = duration_since_last_output
|
112
115
|
return duration > @minimum_output_duration
|
113
116
|
else
|
114
117
|
return true
|
115
118
|
end
|
116
119
|
end
|
117
|
-
|
118
|
-
def formatted_duration(duration)
|
119
|
-
if duration < 60.0
|
120
|
-
return "#{duration.round(2)}s"
|
121
|
-
end
|
122
|
-
|
123
|
-
duration /= 60.0
|
124
|
-
|
125
|
-
if duration < 60.0
|
126
|
-
return "#{duration.round}m"
|
127
|
-
end
|
128
|
-
|
129
|
-
duration /= 60.0
|
130
|
-
|
131
|
-
if duration < 60.0
|
132
|
-
return "#{duration.round(1)}h"
|
133
|
-
end
|
134
|
-
|
135
|
-
duration /= 24.0
|
136
|
-
|
137
|
-
return "#{duration.round(1)}d"
|
138
|
-
end
|
139
120
|
end
|
140
121
|
end
|
data/lib/console/resolver.rb
CHANGED
@@ -22,6 +22,36 @@ require_relative 'filter'
|
|
22
22
|
|
23
23
|
module Console
|
24
24
|
class Resolver
|
25
|
+
# You can change the log level for different classes using CONSOLE_<LEVEL> env vars.
|
26
|
+
#
|
27
|
+
# 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
|
+
#
|
29
|
+
# @parameter logger [Logger] A logger instance to set the logging levels on.
|
30
|
+
# @parameter env [Hash] The environment to read levels from.
|
31
|
+
#
|
32
|
+
# @returns [Nil] If there were no custom logging levels specified in the environment.
|
33
|
+
# @returns [Resolver] If there were custom logging levels, then the created resolver is returned.
|
34
|
+
def self.default_resolver(logger, env = ENV)
|
35
|
+
# Find all CONSOLE_<LEVEL> variables from environment:
|
36
|
+
levels = Logger::LEVELS
|
37
|
+
.map{|label, level| [level, env["CONSOLE_#{label.upcase}"]&.split(',')]}
|
38
|
+
.to_h
|
39
|
+
.compact
|
40
|
+
|
41
|
+
# 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 levels.any?
|
43
|
+
resolver = Resolver.new
|
44
|
+
|
45
|
+
levels.each do |level, names|
|
46
|
+
resolver.bind(names) do |klass|
|
47
|
+
logger.enable(klass, level)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
return resolver
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
25
55
|
def initialize
|
26
56
|
@names = {}
|
27
57
|
|
@@ -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,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fiber-local
|
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'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,14 +104,17 @@ files:
|
|
90
104
|
- lib/console.rb
|
91
105
|
- lib/console/buffer.rb
|
92
106
|
- lib/console/capture.rb
|
107
|
+
- lib/console/clock.rb
|
93
108
|
- lib/console/event.rb
|
94
109
|
- lib/console/event/failure.rb
|
95
110
|
- lib/console/event/generic.rb
|
111
|
+
- lib/console/event/measure.rb
|
96
112
|
- lib/console/event/metric.rb
|
97
113
|
- lib/console/event/progress.rb
|
98
114
|
- lib/console/event/spawn.rb
|
99
115
|
- lib/console/filter.rb
|
100
116
|
- lib/console/logger.rb
|
117
|
+
- lib/console/measure.rb
|
101
118
|
- lib/console/progress.rb
|
102
119
|
- lib/console/resolver.rb
|
103
120
|
- lib/console/serialized/logger.rb
|
@@ -126,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
143
|
- !ruby/object:Gem::Version
|
127
144
|
version: '0'
|
128
145
|
requirements: []
|
129
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.2.3
|
130
147
|
signing_key:
|
131
148
|
specification_version: 4
|
132
149
|
summary: Beautiful logging for Ruby.
|