console 1.28.1 → 1.29.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 +0 -0
- data/lib/console/capture.rb +2 -1
- data/lib/console/event/failure.rb +2 -2
- data/lib/console/interface.rb +53 -0
- data/lib/console/logger.rb +6 -15
- data/lib/console/output/default.rb +5 -2
- data/lib/console/output/failure.rb +32 -0
- data/lib/console/output/null.rb +4 -0
- data/lib/console/output/serialized.rb +7 -2
- data/lib/console/output/terminal.rb +5 -0
- data/lib/console/output/wrapper.rb +6 -0
- data/lib/console/version.rb +1 -1
- data/lib/console/warn.rb +13 -17
- data/lib/console.rb +2 -35
- data/readme.md +6 -0
- data/releases.md +20 -0
- data.tar.gz.sig +0 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa166f5900ef3a9c90b337ce6dd57faa99527fd9746a47aa61bb7f7535e606d
|
4
|
+
data.tar.gz: c6d7d06fdd475006e000c3da6d65fdcd3a5c58e10c90afa8b380f795d45a16d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620b134d260d72d3b69a57e455584d556d611aa8a441fbd7624722b1cfaf3541015335717b82da8ea2aa0682f94e2898c9f28c4162fa5b5842297035f81bd5c0
|
7
|
+
data.tar.gz: be9318b5f775a9bd33f5c8951ffae4b921dbe0618f209080645a3eb12dcd096ef092d94f1239564e03497961ebbfbbb926d43294b8b524a94486e6b62a835b1a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/console/capture.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative "filter"
|
7
|
+
require_relative "output/failure"
|
7
8
|
|
8
9
|
module Console
|
9
10
|
# A general sink which captures all events into a buffer.
|
@@ -58,7 +59,7 @@ module Console
|
|
58
59
|
@verbose
|
59
60
|
end
|
60
61
|
|
61
|
-
def call(subject = nil, *arguments, severity: UNKNOWN, event: nil,
|
62
|
+
def call(subject = nil, *arguments, severity: UNKNOWN, event: nil, **options, &block)
|
62
63
|
record = {
|
63
64
|
time: ::Time.now.iso8601,
|
64
65
|
severity: severity,
|
@@ -28,9 +28,9 @@ module Console
|
|
28
28
|
def self.log(subject, exception, **options)
|
29
29
|
Console.error(subject, **self.for(exception).to_hash, **options)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
attr_reader :exception
|
33
|
-
|
33
|
+
|
34
34
|
def initialize(exception, root = Dir.getwd)
|
35
35
|
@exception = exception
|
36
36
|
@root = root
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright 2024, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "logger"
|
7
|
+
|
8
|
+
module Console
|
9
|
+
# The public logger interface.
|
10
|
+
module Interface
|
11
|
+
# Get the current logger instance.
|
12
|
+
def logger
|
13
|
+
Logger.instance
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set the current logger instance.
|
17
|
+
#
|
18
|
+
# The current logger instance is assigned per-fiber.
|
19
|
+
def logger= instance
|
20
|
+
Logger.instance= instance
|
21
|
+
end
|
22
|
+
|
23
|
+
# Emit a debug log message.
|
24
|
+
def debug(...)
|
25
|
+
Logger.instance.debug(...)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Emit an informational log message.
|
29
|
+
def info(...)
|
30
|
+
Logger.instance.info(...)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Emit a warning log message.
|
34
|
+
def warn(...)
|
35
|
+
Logger.instance.warn(...)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Emit an error log message.
|
39
|
+
def error(...)
|
40
|
+
Logger.instance.error(...)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Emit a fatal log message.
|
44
|
+
def fatal(...)
|
45
|
+
Logger.instance.fatal(...)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Emit a log message with arbitrary arguments and options.
|
49
|
+
def call(...)
|
50
|
+
Logger.instance.call(...)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/console/logger.rb
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
# Copyright, 2021, by Robert Schulze.
|
7
7
|
|
8
8
|
require_relative "output"
|
9
|
+
require_relative "output/failure"
|
10
|
+
|
9
11
|
require_relative "filter"
|
10
12
|
require_relative "event"
|
11
13
|
require_relative "resolver"
|
@@ -47,6 +49,7 @@ module Console
|
|
47
49
|
end
|
48
50
|
|
49
51
|
output = Output.new(output, env, **options)
|
52
|
+
|
50
53
|
logger = self.new(output, **options)
|
51
54
|
|
52
55
|
Resolver.default_resolver(logger)
|
@@ -61,6 +64,9 @@ module Console
|
|
61
64
|
DEFAULT_LEVEL = 1
|
62
65
|
|
63
66
|
def initialize(output, **options)
|
67
|
+
# This is the expected default behaviour, but it may be nice to have a way to override it.
|
68
|
+
output = Output::Failure.new(output, **options)
|
69
|
+
|
64
70
|
super(output, **options)
|
65
71
|
end
|
66
72
|
|
@@ -69,20 +75,5 @@ module Console
|
|
69
75
|
|
70
76
|
Progress.new(subject, total, **options)
|
71
77
|
end
|
72
|
-
|
73
|
-
def error(subject, *arguments, **options, &block)
|
74
|
-
# This is a special case where we want to create a failure event from an exception.
|
75
|
-
# It's common to see `Console.error(self, exception)` in code.
|
76
|
-
if arguments.first.is_a?(Exception)
|
77
|
-
exception = arguments.shift
|
78
|
-
options[:event] = Event::Failure.for(exception)
|
79
|
-
end
|
80
|
-
|
81
|
-
super
|
82
|
-
end
|
83
|
-
|
84
|
-
def failure(subject, exception, **options)
|
85
|
-
error(subject, event: Event::Failure.for(exception), **options)
|
86
|
-
end
|
87
78
|
end
|
88
79
|
end
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
require_relative "terminal"
|
7
7
|
require_relative "serialized"
|
8
|
+
require_relative "failure"
|
8
9
|
|
9
10
|
module Console
|
10
11
|
module Output
|
@@ -13,10 +14,12 @@ module Console
|
|
13
14
|
output ||= $stderr
|
14
15
|
|
15
16
|
if output.tty?
|
16
|
-
Terminal.new(output, **options)
|
17
|
+
output = Terminal.new(output, **options)
|
17
18
|
else
|
18
|
-
Serialized.new(output, **options)
|
19
|
+
output = Serialized.new(output, **options)
|
19
20
|
end
|
21
|
+
|
22
|
+
return output
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2021-2024, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "wrapper"
|
7
|
+
require_relative "../event/failure"
|
8
|
+
|
9
|
+
module Console
|
10
|
+
module Output
|
11
|
+
# A wrapper for outputting failure messages, which can include exceptions.
|
12
|
+
class Failure < Wrapper
|
13
|
+
def initialize(output, **options)
|
14
|
+
super(output, **options)
|
15
|
+
end
|
16
|
+
|
17
|
+
# The exception must be either the last argument or passed as an option.
|
18
|
+
def call(subject = nil, *arguments, exception: nil, **options, &block)
|
19
|
+
if exception.nil?
|
20
|
+
last = arguments.last
|
21
|
+
if last.is_a?(Exception)
|
22
|
+
options[:event] = Event::Failure.for(last)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
options[:event] = Event::Failure.for(exception)
|
26
|
+
end
|
27
|
+
|
28
|
+
super(subject, *arguments, **options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/console/output/null.rb
CHANGED
@@ -10,11 +10,16 @@ require "fiber/annotation"
|
|
10
10
|
module Console
|
11
11
|
module Output
|
12
12
|
class Serialized
|
13
|
-
def initialize(
|
14
|
-
@io =
|
13
|
+
def initialize(io, format: Format.default, **options)
|
14
|
+
@io = io
|
15
15
|
@format = format
|
16
16
|
end
|
17
17
|
|
18
|
+
# This a final output that then writes to an IO object.
|
19
|
+
def last_output
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
18
23
|
attr :io
|
19
24
|
attr :format
|
20
25
|
|
data/lib/console/version.rb
CHANGED
data/lib/console/warn.rb
CHANGED
@@ -3,35 +3,31 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
+
require_relative "logger"
|
7
|
+
|
6
8
|
module Console
|
7
9
|
# Whether the current fiber is emitting a warning.
|
8
10
|
Fiber.attr_accessor :console_warn
|
9
11
|
|
12
|
+
# Redirect warnings to Console.warn.
|
10
13
|
module Warn
|
11
|
-
|
14
|
+
# Redirect warnings to {Console.warn}.
|
15
|
+
def warn(message, **options)
|
12
16
|
fiber = Fiber.current
|
13
17
|
|
14
|
-
# We do this to be extra pendantic about avoiding infinite recursion
|
18
|
+
# We do this to be extra pendantic about avoiding infinite recursion.
|
15
19
|
return super if fiber.console_warn
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if arguments.last.is_a?(Exception)
|
22
|
-
exception = arguments.pop
|
21
|
+
begin
|
22
|
+
fiber.console_warn = true
|
23
|
+
message.chomp!
|
23
24
|
|
24
|
-
Console::
|
25
|
-
|
26
|
-
|
27
|
-
fiber.console_warn = true
|
28
|
-
Console.warn(*arguments, **options)
|
29
|
-
ensure
|
30
|
-
fiber.console_warn = false
|
31
|
-
end
|
25
|
+
Console::Logger.instance.warn(message, **options)
|
26
|
+
ensure
|
27
|
+
fiber.console_warn = false
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
|
-
::
|
32
|
+
::Warning.extend(Warn)
|
37
33
|
end
|
data/lib/console.rb
CHANGED
@@ -7,41 +7,8 @@
|
|
7
7
|
# Copyright, 2021, by Cédric Boutillier.
|
8
8
|
|
9
9
|
require_relative "console/version"
|
10
|
-
require_relative "console/
|
11
|
-
require_relative "console/warn"
|
10
|
+
require_relative "console/interface"
|
12
11
|
|
13
12
|
module Console
|
14
|
-
|
15
|
-
def logger
|
16
|
-
Logger.instance
|
17
|
-
end
|
18
|
-
|
19
|
-
def logger= instance
|
20
|
-
Logger.instance= instance
|
21
|
-
end
|
22
|
-
|
23
|
-
def debug(...)
|
24
|
-
Logger.instance.debug(...)
|
25
|
-
end
|
26
|
-
|
27
|
-
def info(...)
|
28
|
-
Logger.instance.info(...)
|
29
|
-
end
|
30
|
-
|
31
|
-
def warn(...)
|
32
|
-
Logger.instance.warn(...)
|
33
|
-
end
|
34
|
-
|
35
|
-
def error(...)
|
36
|
-
Logger.instance.error(...)
|
37
|
-
end
|
38
|
-
|
39
|
-
def fatal(...)
|
40
|
-
Logger.instance.fatal(...)
|
41
|
-
end
|
42
|
-
|
43
|
-
def call(...)
|
44
|
-
Logger.instance.call(...)
|
45
|
-
end
|
46
|
-
end
|
13
|
+
Console.extend(Interface)
|
47
14
|
end
|
data/readme.md
CHANGED
@@ -32,6 +32,12 @@ Please see the [project documentation](https://socketry.github.io/console/) for
|
|
32
32
|
|
33
33
|
Please see the [project releases](https://socketry.github.io/console/releases/index) for all releases.
|
34
34
|
|
35
|
+
### v1.29.0
|
36
|
+
|
37
|
+
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
38
|
+
- Remove deprecated `Console::Logger#failure`.
|
39
|
+
- [Consistent Handling of Exceptions](https://socketry.github.io/console/releases/index#consistent-handling-of-exceptions)
|
40
|
+
|
35
41
|
### v1.28.0
|
36
42
|
|
37
43
|
- Add support for `Kernel#warn` redirection to `Console.warn`.
|
data/releases.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v1.29.0
|
4
|
+
|
5
|
+
- Don't make `Kernel#warn` redirection to `Console.warn` the default behavior, you must `require 'console/warn'` to enable it.
|
6
|
+
- Remove deprecated `Console::Logger#failure`.
|
7
|
+
|
8
|
+
### Consistent Handling of Exceptions
|
9
|
+
|
10
|
+
`Console.call` and all wrapper methods will now consistently handle exceptions that are the last positional argument or keyword argument. This means that the following code will work as expected:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
begin
|
14
|
+
rescue => error
|
15
|
+
# Last positional argument:
|
16
|
+
Console.warn(self, "There may be an issue", error)
|
17
|
+
|
18
|
+
# Keyword argument (preferable):
|
19
|
+
Console.error(self, "There is an issue", exception: error)
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
3
23
|
## v1.28.0
|
4
24
|
|
5
25
|
- Add support for `Kernel#warn` redirection to `Console.warn`.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.29.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -47,7 +47,7 @@ cert_chain:
|
|
47
47
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
48
48
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
49
49
|
-----END CERTIFICATE-----
|
50
|
-
date: 2024-11-
|
50
|
+
date: 2024-11-06 00:00:00.000000000 Z
|
51
51
|
dependencies:
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: fiber-annotation
|
@@ -110,9 +110,11 @@ files:
|
|
110
110
|
- lib/console/filter.rb
|
111
111
|
- lib/console/format.rb
|
112
112
|
- lib/console/format/safe.rb
|
113
|
+
- lib/console/interface.rb
|
113
114
|
- lib/console/logger.rb
|
114
115
|
- lib/console/output.rb
|
115
116
|
- lib/console/output/default.rb
|
117
|
+
- lib/console/output/failure.rb
|
116
118
|
- lib/console/output/null.rb
|
117
119
|
- lib/console/output/sensitive.rb
|
118
120
|
- lib/console/output/serialized.rb
|
metadata.gz.sig
CHANGED
Binary file
|