console 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9f91e3e103d4d8999923473901b90855e7c8ee5a2f1bf5fa7be4b87a435e0e2
4
- data.tar.gz: 78cc14aa29facd5ef1909fc08bcd255d11c251f1075dbe92692f26a249557cbf
3
+ metadata.gz: 9a62f7c19673292c5cd3c0d8b9d93350ca4b36ac0a5c0a0466deef6543b388ba
4
+ data.tar.gz: f382353a7b052c056936fdd2c95ad0bd20cfb8619db2f6d2af1ce7e9e0cd7967
5
5
  SHA512:
6
- metadata.gz: bda52b2ed24d9825905e8e929809d9629ba61755059d7e00ef8ceb693839a191d98647bc13fd2c3a7699f8f664560e4f35c316e21bb9e37c24b8d1265c31dd91
7
- data.tar.gz: 22a7f6c0be0617140c608b5063c25d3dd220670afc570860f0cd54fea36f889c3b128d168f9dd6bf92c01c271e335b4d73dfd06cfe918f2360911aa8991fcfba
6
+ metadata.gz: 6638ede52de5f0954a38adf71e910997eb643d2e39ef59645f320ce16ebefd4f804cb062e47e03472ac742fb46591c310217da72eb63eb87fe91d93090f8ee5f
7
+ data.tar.gz: 15f4929956b45e0c445e95774dfa3ac1c4bb485401e1b0003835c9ae5435a25ebda70b69ad475cf0e6b48131b0cc41258e3c5bb8c70121daaa9fe482c12b5404
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require_relative 'filter'
7
7
 
@@ -55,6 +55,10 @@ module Console
55
55
  message[:arguments] = arguments
56
56
  end
57
57
 
58
+ if annotation = Fiber.current.annotation
59
+ message[:annotation] = annotation
60
+ end
61
+
58
62
  if block_given?
59
63
  if block.arity.zero?
60
64
  message[:message] = yield
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2023, by Samuel Williams.
5
5
 
6
6
  require 'logger'
7
7
 
@@ -43,8 +43,18 @@ module Console
43
43
  format_exception(@exception, nil, output, terminal, verbose)
44
44
  end
45
45
 
46
+ if Exception.method_defined?(:detailed_message)
47
+ def detailed_message(exception)
48
+ exception.detailed_message
49
+ end
50
+ else
51
+ def detailed_message(exception)
52
+ exception.message
53
+ end
54
+ end
55
+
46
56
  def format_exception(exception, prefix, output, terminal, verbose)
47
- lines = exception.message.lines.map(&:chomp)
57
+ lines = detailed_message(exception).lines.map(&:chomp)
48
58
 
49
59
  output.puts " #{prefix}#{terminal[:exception_title]}#{exception.class}#{terminal.reset}: #{lines.shift}"
50
60
 
@@ -55,7 +65,7 @@ module Console
55
65
  root_pattern = /^#{@root}\// if @root
56
66
 
57
67
  exception.backtrace&.each_with_index do |line, index|
58
- path, offset, message = line.split(":")
68
+ path, offset, message = line.split(":", 3)
59
69
  style = :exception_backtrace
60
70
 
61
71
  # Make the path a bit more readable
@@ -12,6 +12,17 @@ module Console
12
12
  UNKNOWN = 'unknown'
13
13
 
14
14
  class Filter
15
+ if Object.const_defined?(:Ractor) and RUBY_VERSION >= '3.1'
16
+ def self.define_immutable_method(name, &block)
17
+ block = Ractor.make_shareable(block)
18
+ self.define_method(name, &block)
19
+ end
20
+ else
21
+ def self.define_immutable_method(name, &block)
22
+ define_method(name, &block)
23
+ end
24
+ end
25
+
15
26
  def self.[] **levels
16
27
  klass = Class.new(self)
17
28
  minimum_level, maximum_level = levels.values.minmax
@@ -24,17 +35,17 @@ module Console
24
35
  levels.each do |name, level|
25
36
  const_set(name.to_s.upcase, level)
26
37
 
27
- define_method(name) do |subject = nil, *arguments, **options, &block|
38
+ define_immutable_method(name) do |subject = nil, *arguments, **options, &block|
28
39
  if self.enabled?(subject, level)
29
40
  self.call(subject, *arguments, severity: name, **options, **@options, &block)
30
41
  end
31
42
  end
32
43
 
33
- define_method("#{name}!") do
44
+ define_immutable_method("#{name}!") do
34
45
  @level = level
35
46
  end
36
47
 
37
- define_method("#{name}?") do
48
+ define_immutable_method("#{name}?") do
38
49
  @level <= level
39
50
  end
40
51
  end
@@ -18,14 +18,47 @@ module Console
18
18
 
19
19
  def dump(object)
20
20
  @format.dump(object, @limit)
21
- rescue => error
21
+ rescue SystemStackError, StandardError => error
22
22
  @format.dump(safe_dump(object, error))
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def default_objects
28
- Hash.new.compare_by_identity
27
+ def filter_backtrace(error)
28
+ frames = error.backtrace
29
+ filtered = {}
30
+ filtered_count = nil
31
+ skipped = nil
32
+
33
+ frames = frames.filter_map do |frame|
34
+ if filtered[frame]
35
+ if filtered_count == nil
36
+ filtered_count = 1
37
+ skipped = frame.dup
38
+ else
39
+ filtered_count += 1
40
+ nil
41
+ end
42
+ else
43
+ if skipped
44
+ if filtered_count > 1
45
+ skipped.replace("[... #{filtered_count} frames skipped ...]")
46
+ end
47
+
48
+ filtered_count = nil
49
+ skipped = nil
50
+ end
51
+
52
+ filtered[frame] = true
53
+ frame
54
+ end
55
+ end
56
+
57
+ if skipped && filtered_count > 1
58
+ skipped.replace("[... #{filtered_count} frames skipped ...]")
59
+ end
60
+
61
+ return frames
29
62
  end
30
63
 
31
64
  def safe_dump(object, error)
@@ -35,6 +68,7 @@ module Console
35
68
  object[:error] = {
36
69
  class: safe_dump_recurse(error.class.name),
37
70
  message: safe_dump_recurse(error.message),
71
+ backtrace: safe_dump_recurse(filter_backtrace(error)),
38
72
  }
39
73
 
40
74
  return object
@@ -51,6 +85,10 @@ module Console
51
85
  end
52
86
  end
53
87
 
88
+ def default_objects
89
+ Hash.new.compare_by_identity
90
+ end
91
+
54
92
  # This will recursively generate a safe version of the object.
55
93
  # Nested hashes and arrays will be transformed recursively.
56
94
  # Strings will be encoded with the given encoding.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
4
+ # Copyright, 2021-2023, by Samuel Williams.
5
5
 
6
6
  require_relative '../serialized/logger'
7
7
 
@@ -119,7 +119,7 @@ module Console
119
119
  protected
120
120
 
121
121
  def format_options(options, output)
122
- format_value(options.to_json, output)
122
+ format_value(::JSON.pretty_generate(options), output)
123
123
  end
124
124
 
125
125
  def format_argument(argument, output)
@@ -149,8 +149,14 @@ module Console
149
149
  buffer = +""
150
150
 
151
151
  if @verbose
152
- if annotation = Fiber.current.annotation and annotation.size > 0
153
- buffer << ": #{@terminal[:annotation]}#{annotation}#{@terminal.reset}"
152
+ if annotation = Fiber.current.annotation
153
+ # While typically annotations should be strings, that is not always the case.
154
+ annotation = annotation.to_s
155
+
156
+ # If the annotation is empty, we don't want to print it, as it will look like a formatting bug.
157
+ if annotation.size > 0
158
+ buffer << ": #{@terminal[:annotation]}#{annotation}#{@terminal.reset}"
159
+ end
154
160
  end
155
161
  end
156
162
 
@@ -193,6 +199,7 @@ module Console
193
199
  string = value.to_s
194
200
 
195
201
  string.each_line do |line|
202
+ line.chomp!
196
203
  output.puts "#{@terminal[:value]}#{line}#{@terminal.reset}"
197
204
  end
198
205
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.23.0"
7
+ VERSION = "1.24.0"
8
8
  end
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2019-2023, by Samuel Williams.
3
+ Copyright, 2019-2024, by Samuel Williams.
4
4
  Copyright, 2019-2021, by Bryan Powell.
5
5
  Copyright, 2019, by Cyril Roelandt.
6
6
  Copyright, 2020, by Olle Jonsson.
data/readme.md CHANGED
@@ -18,7 +18,13 @@ When Ruby decided to reverse the order of exception backtraces, I finally gave u
18
18
 
19
19
  ## Usage
20
20
 
21
- Please see the [project documentation](https://socketry.github.io/console).
21
+ Please see the [project documentation](https://socketry.github.io/console/) for more details.
22
+
23
+ - [Getting Started](https://socketry.github.io/console/guides/getting-started/index) - This guide explains how to use `console` for logging.
24
+
25
+ - [Command Line](https://socketry.github.io/console/guides/command-line/index) - This guide explains how the `console` gem can be controlled using environment variables.
26
+
27
+ - [Integration](https://socketry.github.io/console/guides/integration/index) - This guide explains how to integrate the `console` output into different systems.
22
28
 
23
29
  ## Contributing
24
30
 
@@ -36,4 +42,10 @@ This project uses the [Developer Certificate of Origin](https://developercertifi
36
42
 
37
43
  ### Contributor Covenant
38
44
 
39
- This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
45
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
46
+
47
+ ## See Also
48
+
49
+ - [console-adapter-rails](https://github.com/socketry/console-adapter-rails)
50
+ - [console-adapter-sidekiq](https://github.com/socketry/console-adapter-sidekiq)
51
+ - [console-output-datadog](https://github.com/socketry/console-output-datadog)
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.23.0
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -46,7 +46,7 @@ cert_chain:
46
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
47
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
48
48
  -----END CERTIFICATE-----
49
- date: 2023-08-11 00:00:00.000000000 Z
49
+ date: 2024-04-22 00:00:00.000000000 Z
50
50
  dependencies:
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: fiber-annotation
@@ -76,6 +76,20 @@ dependencies:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: json
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
79
93
  description:
80
94
  email:
81
95
  executables: []
@@ -117,7 +131,7 @@ files:
117
131
  - lib/console/version.rb
118
132
  - license.md
119
133
  - readme.md
120
- homepage: https://github.com/socketry/console
134
+ homepage: https://socketry.github.io/console/
121
135
  licenses:
122
136
  - MIT
123
137
  metadata: {}
@@ -136,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
150
  - !ruby/object:Gem::Version
137
151
  version: '0'
138
152
  requirements: []
139
- rubygems_version: 3.4.10
153
+ rubygems_version: 3.5.3
140
154
  signing_key:
141
155
  specification_version: 4
142
156
  summary: Beautiful logging for Ruby.
metadata.gz.sig CHANGED
Binary file