console 1.13.1 → 1.15.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8c8affd2da03cdb084d7ef8af7c666409d12606c4459da493bf01a96d6b7bf3
4
- data.tar.gz: d0af1c352b7b89f91b57ea737a5069282177be325f1bae82db3cb8de2ee76f57
3
+ metadata.gz: 3a22bd139802242d9acc996a612905f05419887881056973d48545ad504502c5
4
+ data.tar.gz: 5c855c52b01e37118bfae82dfbfa59848283b3d008d705fa478d0e173f667a37
5
5
  SHA512:
6
- metadata.gz: b9c453a4bfc44ac3b87c034e8854addb31d4a1c4d2cbdc9abf698f3dbf657ff99fa636d8e46dd0262e30cd195d1c3b12ba6d64c5e8b75668ec05d8b26952f494
7
- data.tar.gz: 9ca8d1ade8c3b7fc3c4dd307a27e2e67f236526bd60619cb30cc7c70af179846050bd22d0e67d1e55f3019702052ffeb593c5eed1d1522c577e73cebc2e56795
6
+ metadata.gz: da5f8a41f1d6655a74b0c563b0fb52dfbff0c163afbce5ecfd58b706c39ec640e59ed1f4e509d740ca58ffbcfd412469d28b2c97e4ba9b49cafaee51f4230436
7
+ data.tar.gz: 9150e31d177ec0a71f1c235dd5dbf08592f04d12912afd755c657799c018a835eba0f6dfd5ee5e7337f90755c7d804ad8928e5d26e22ab19942eab3fe069e967
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ��C �^��� ����ى/E�}ܛi�n��\N�b
2
+ ��ub|ǣK� �d�]�y,����P�@�vrkY�����,^b���� 0ԁ(aN�.I曉��0�J�D'oe�c�,d��3� ��*c�߇��@���������w27���s ��Y(��ǵz��5E��=:\|�?��2p�ON8���2*���S.>�ԣ ���؎�5���O�OW0�k-ܤ5���x�."�O'��� ml9��.
@@ -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
@@ -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
data/lib/console/clock.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -0,0 +1,85 @@
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 'logger'
24
+
25
+ module Console
26
+ module Compatible
27
+ class Logger < ::Logger
28
+ class LogDevice
29
+ def initialize(subject, output)
30
+ @subject = subject
31
+ @output = output
32
+ end
33
+
34
+ def write(message)
35
+ @output.call(@subject, message)
36
+ end
37
+
38
+ def call(*arguments, **options)
39
+ @output.call(*arguments, **options)
40
+ end
41
+
42
+ def reopen
43
+ end
44
+
45
+ def close
46
+ end
47
+ end
48
+
49
+ def initialize(subject, output)
50
+ super(nil)
51
+
52
+ @progname = subject
53
+ @logdev = LogDevice.new(@subject, output)
54
+ end
55
+
56
+ def add(severity, message = nil, progname = nil)
57
+ severity ||= UNKNOWN
58
+
59
+ if @logdev.nil? or severity < level
60
+ return true
61
+ end
62
+
63
+ if progname.nil?
64
+ progname = @progname
65
+ end
66
+
67
+ if message.nil?
68
+ if block_given?
69
+ message = yield
70
+ else
71
+ message = progname
72
+ progname = @progname
73
+ end
74
+ end
75
+
76
+ @logdev.call(
77
+ progname, message,
78
+ severity: format_severity(severity)
79
+ )
80
+
81
+ return true
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,4 +1,5 @@
1
- # frozen_string_literals: true
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
5
  #
@@ -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 as_json
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)
@@ -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
@@ -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
@@ -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
@@ -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
- self.new(*arguments, **options)
31
+ environment = arguments.shift
32
+ self.new(environment, arguments, options)
30
33
  else
31
- self.new(nil, arguments, **options)
34
+ self.new(nil, arguments, options)
32
35
  end
33
36
  end
34
37
 
35
- def initialize(environment, *arguments, **options)
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
- {environment: @environment, arguments: @arguments, options: @options}
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2021, 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
@@ -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
@@ -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
@@ -22,7 +24,7 @@ require_relative 'filter'
22
24
 
23
25
  module Console
24
26
  class Resolver
25
- # You can change the log level for different classes using CONSOLE_<LEVEL> env vars.
27
+ # You can change the log level for different classes using CONSOLE_$LEVEL env vars.
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
  #
@@ -34,7 +36,7 @@ module Console
34
36
  # @returns [Nil] If there were no custom logging levels specified in the environment.
35
37
  # @returns [Resolver] If there were custom logging levels, then the created resolver is returned.
36
38
  def self.default_resolver(logger, env = ENV)
37
- # Find all CONSOLE_<LEVEL> variables from environment:
39
+ # Find all CONSOLE_$LEVEL variables from environment:
38
40
  levels = logger.class::LEVELS
39
41
  .map{|label, level| [level, env["CONSOLE_#{label.upcase}"]&.split(',')]}
40
42
  .to_h
@@ -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
@@ -59,26 +61,59 @@ module Console
59
61
  record[:subject] = subject
60
62
  end
61
63
 
62
- if arguments.any?
63
- record[:arguments] = arguments
64
- end
65
-
66
- if options.any?
67
- record[:options] = options
68
- end
64
+ message = arguments
69
65
 
70
66
  if block_given?
71
67
  if block.arity.zero?
72
- record[:message] = yield
68
+ message << yield
73
69
  else
74
70
  buffer = StringIO.new
75
71
  yield buffer
76
- record[:message] = buffer.string
72
+ message << buffer.string
77
73
  end
78
74
  end
79
75
 
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
+
80
92
  @io.puts(self.dump(record))
81
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
116
+ end
82
117
  end
83
118
  end
84
119
  end
data/lib/console/split.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
4
  #
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.13.1"
24
+ VERSION = "1.15.1"
23
25
  end
data/lib/console.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
5
  #
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Robert Schulze
9
+ - Bryan Powell
10
+ - Michael Adams
11
+ - Cyril Roelandt
12
+ - Cédric Boutillier
13
+ - Olle Jonsson
8
14
  autorequire:
9
15
  bindir: bin
10
- cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
20
+ ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
21
+ MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
22
+ aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
23
+ AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
24
+ xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
25
+ eNMDgKsMJtC7u/43abRKx7TCURW3iWyR19NRngsJJmaR51yGGGm2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9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
42
+ RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
43
+ HiLJ8VOFx6w=
44
+ -----END CERTIFICATE-----
45
+ date: 2022-05-12 00:00:00.000000000 Z
12
46
  dependencies:
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: fiber-local
@@ -105,6 +139,7 @@ files:
105
139
  - lib/console/buffer.rb
106
140
  - lib/console/capture.rb
107
141
  - lib/console/clock.rb
142
+ - lib/console/compatible/logger.rb
108
143
  - lib/console/event.rb
109
144
  - lib/console/event/failure.rb
110
145
  - lib/console/event/generic.rb
@@ -149,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
184
  - !ruby/object:Gem::Version
150
185
  version: '0'
151
186
  requirements: []
152
- rubygems_version: 3.3.0.dev
187
+ rubygems_version: 3.1.6
153
188
  signing_key:
154
189
  specification_version: 4
155
190
  summary: Beautiful logging for Ruby.
metadata.gz.sig ADDED
Binary file