console 1.30.2 → 1.32.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: 4a3a941ea83d20a38ee9478245b0a7c7a0845b7aac0cc64311f081bef9fbc809
4
- data.tar.gz: d2619ea91b4599616c5129c1880468e5d28250fc4756445b778a65b114a27b6d
3
+ metadata.gz: 51db72e147d6bbe3aa01e48b78ebc454cb34a719be4f936b58542c5623fb803d
4
+ data.tar.gz: 4ca2801323f3ee8149e6d967d1fe8920aff5958db3a6b37980251fde3e51fc61
5
5
  SHA512:
6
- metadata.gz: dc3f9bee5ec9205e1a144606188da0629688a53ec59a82d5ed90987f78dffdb833d2ccee63cbf091c8e4c06d3d1ea535b1ebfc6c35314a624d7f01232704fbce
7
- data.tar.gz: 0e65d355fceba6fc1ae152d5aa0a71e314fc21c5d558c9e23ee211fd3f62c764b9060d2d7f0b1fc90b3856a41a2f2d211b3531e90aa9e91d49df27cdbdc7ad9c
6
+ metadata.gz: 42b590f516d239a57d796b5ac8a8c3f3a40da40bc3430e0a797940ffa3f2bbaa47be07c3943ce9df1a94121ea70288c41615f7b71d166094e43bde91681ac1c4
7
+ data.tar.gz: 17fa1288f63cdb231f5c1c91e10098550b3418d6d2c1743939a15d5380d7fc68c7a95997327b417a28686bb0b9784196ce832615b2cd1d98bedf65cb29360c57
checksums.yaml.gz.sig CHANGED
Binary file
@@ -18,9 +18,10 @@ module Console
18
18
  # @attribute [Array(Hash)] All records captured by this buffer.
19
19
  attr :records
20
20
 
21
- # @deprecated Use {#records} instead of {#buffer}.
21
+ # @deprecated Use {records} instead of {buffer}.
22
22
  alias buffer records
23
23
 
24
+ # @deprecated Use {records} instead of {to_a}.
24
25
  alias to_a records
25
26
 
26
27
  # @attribute [Boolean] If true, the buffer will capture verbose messages.
@@ -30,12 +30,15 @@ module Console
30
30
  # Load the default configuration.
31
31
  # @returns [Config] The default configuration.
32
32
  def self.default
33
- @default ||= self.load(PATH)
33
+ @default ||= self.load(PATH).freeze
34
34
  end
35
35
 
36
36
  # Set the default log level based on `$DEBUG` and `$VERBOSE`.
37
37
  # You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
38
38
  # https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
39
+ #
40
+ # @parameter env [Hash] The environment to read the log level from.
41
+ # @returns [Integer | Symbol] The default log level.
39
42
  def log_level(env = ENV)
40
43
  Logger.default_log_level(env)
41
44
  end
@@ -7,6 +7,13 @@ module Console
7
7
  module Event
8
8
  # A generic event which can be used to represent structured data.
9
9
  class Generic
10
+ # Convert the event to a hash suitable for JSON serialization.
11
+ #
12
+ # @returns [Hash] The hash representation of the event.
13
+ def to_hash
14
+ {}
15
+ end
16
+
10
17
  # Convert the event to a hash suitable for JSON serialization.
11
18
  #
12
19
  # @returns [Hash] The hash representation of the event.
@@ -11,7 +11,7 @@ module Console
11
11
 
12
12
  # A log filter which can be used to filter log messages based on severity, subject, and other criteria.
13
13
  class Filter
14
- if Object.const_defined?(:Ractor) and RUBY_VERSION >= "3.1"
14
+ if Object.const_defined?(:Ractor) and RUBY_VERSION >= "3.4"
15
15
  # Define a method which can be shared between ractors.
16
16
  def self.define_immutable_method(name, &block)
17
17
  block = Ractor.make_shareable(block)
@@ -70,10 +70,16 @@ module Console
70
70
  # @parameter verbose [Boolean] Enable verbose output.
71
71
  # @parameter level [Integer] The log level.
72
72
  # @parameter options [Hash] Additional options.
73
- def initialize(output, verbose: true, level: self.class::DEFAULT_LEVEL, **options)
73
+ def initialize(output, verbose: true, level: nil, **options)
74
74
  @output = output
75
75
  @verbose = verbose
76
- @level = level
76
+
77
+ # Set the log level using the behaviour implemented in `level=`:
78
+ if level
79
+ self.level = level
80
+ else
81
+ @level = self.class::DEFAULT_LEVEL
82
+ end
77
83
 
78
84
  @subjects = {}
79
85
 
@@ -156,7 +162,7 @@ module Console
156
162
  #
157
163
  # You can enable and disable logging for classes. This function checks if logging for a given subject is enabled.
158
164
  #
159
- # @parameter subject [Module] The subject to check.
165
+ # @parameter subject [Module | Object] The subject to check.
160
166
  # @parameter level [Integer] The log level.
161
167
  # @returns [Boolean] Whether logging is enabled.
162
168
  def enabled?(subject, level = self.class::MINIMUM_LEVEL)
@@ -14,12 +14,13 @@ module Console
14
14
  # Create a new output format based on the given stream.
15
15
  #
16
16
  # @parameter io [IO] The output stream.
17
+ # @parameter env [Hash] Environment variables (defaults to ENV for testing).
17
18
  # @parameter options [Hash] Additional options to customize the output.
18
19
  # @returns [Console::Output::Terminal | Console::Output::Serialized] The output instance, depending on whether the `io` is a terminal or not.
19
- def self.new(stream, **options)
20
+ def self.new(stream, env: ENV, **options)
20
21
  stream ||= $stderr
21
22
 
22
- if stream.tty?
23
+ if stream.tty? || mail?(env)
23
24
  output = Terminal.new(stream, **options)
24
25
  else
25
26
  output = Serialized.new(stream, **options)
@@ -27,6 +28,17 @@ module Console
27
28
 
28
29
  return output
29
30
  end
31
+
32
+ private
33
+
34
+ # Detect if we're running in a cron job or mail context where human-readable output is preferred.
35
+ # Cron jobs often have MAILTO set and lack TERM, or have minimal TERM values.
36
+ def self.mail?(env = ENV)
37
+ # Check for common cron environment indicators
38
+ return true if env.key?("MAILTO") && !env["MAILTO"].empty?
39
+
40
+ false
41
+ end
30
42
  end
31
43
  end
32
44
  end
@@ -51,8 +51,9 @@ module Console
51
51
  record = {
52
52
  time: Time.now.iso8601,
53
53
  severity: severity,
54
- oid: subject.object_id,
55
54
  pid: Process.pid,
55
+ oid: subject.object_id,
56
+ fiber_id: Fiber.current.object_id,
56
57
  }
57
58
 
58
59
  # We want to log just a brief subject:
@@ -41,6 +41,7 @@ module Console
41
41
  end
42
42
  end
43
43
 
44
+ # Write a line to the buffer.
44
45
  alias << puts
45
46
  end
46
47
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2025, by Samuel Williams.
5
+ # Copyright, 2025, by Patrik Wenger.
5
6
 
6
7
  require "io/console"
7
8
 
@@ -78,15 +79,19 @@ module Console
78
79
  end
79
80
  end
80
81
 
81
- # Write the given arguments to the output stream using the given style. The reset sequence is automatically appended.
82
+ # Write the given arguments to the output stream using the given style. The reset sequence is automatically
83
+ # appended at the end of each line.
82
84
  #
83
85
  # @parameter arguments [Array] The arguments to write, each on a new line.
84
86
  # @parameter style [Symbol] The style to apply.
85
87
  def puts(*arguments, style: nil)
86
88
  if style and prefix = self[style]
87
- @stream.write(prefix)
88
- @stream.puts(*arguments)
89
- @stream.write(self.reset)
89
+ arguments.each do |argument|
90
+ argument.to_s.lines.each do |line|
91
+ @stream.write(prefix, line.chomp)
92
+ @stream.puts(self.reset)
93
+ end
94
+ end
90
95
  else
91
96
  @stream.puts(*arguments)
92
97
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2025, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.30.2"
7
+ VERSION = "1.32.0"
8
8
  end
data/license.md CHANGED
@@ -10,7 +10,7 @@ Copyright, 2021, by Robert Schulze.
10
10
  Copyright, 2022, by Anton Sozontov.
11
11
  Copyright, 2022, by William T. Nelson.
12
12
  Copyright, 2023, by Felix Yan.
13
- Copyright, 2024, by Patrik Wenger.
13
+ Copyright, 2024-2025, by Patrik Wenger.
14
14
  Copyright, 2025, by Shigeru Nakajima.
15
15
 
16
16
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/readme.md CHANGED
@@ -34,6 +34,17 @@ Please see the [project documentation](https://socketry.github.io/console/) for
34
34
 
35
35
  Please see the [project releases](https://socketry.github.io/console/releases/index) for all releases.
36
36
 
37
+ ### v1.32.0
38
+
39
+ - Add `fiber_id` to serialized output records to help identify which fiber logged the message.
40
+ - Ractor support appears broken in older Ruby versions, so we now require Ruby 3.4 or later for Ractor compatibility, if you need Ractor support.
41
+
42
+ ### v1.31.0
43
+
44
+ - [Ractor compatibility.](https://socketry.github.io/console/releases/index#ractor-compatibility.)
45
+ - [Symbol log level compatibility.](https://socketry.github.io/console/releases/index#symbol-log-level-compatibility.)
46
+ - [Improved output format selection for cron jobs and email contexts.](https://socketry.github.io/console/releases/index#improved-output-format-selection-for-cron-jobs-and-email-contexts.)
47
+
37
48
  ### v1.30.0
38
49
 
39
50
  - [Introduce `Console::Config` for fine grained configuration.](https://socketry.github.io/console/releases/index#introduce-console::config-for-fine-grained-configuration.)
data/releases.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # Releases
2
2
 
3
+ ## v1.32.0
4
+
5
+ - Add `fiber_id` to serialized output records to help identify which fiber logged the message.
6
+ - Ractor support appears broken in older Ruby versions, so we now require Ruby 3.4 or later for Ractor compatibility, if you need Ractor support.
7
+
8
+ ## v1.31.0
9
+
10
+ ### Ractor compatibility.
11
+
12
+ The console library now works correctly with Ruby's Ractor concurrency model. Previously, attempting to use console logging within Ractors would fail with errors about non-shareable objects. This has been fixed by ensuring the default configuration is properly frozen.
13
+
14
+ ``` ruby
15
+ # This now works without errors:
16
+ ractor = Ractor.new do
17
+ require 'console'
18
+ Console.info('Hello from Ractor!')
19
+ 'Ractor completed successfully'
20
+ end
21
+
22
+ result = ractor.take
23
+ puts result # => 'Ractor completed successfully'
24
+ ```
25
+
26
+ The fix is minimal and maintains full backward compatibility while enabling safe parallel logging across multiple Ractors.
27
+
28
+ ### Symbol log level compatibility.
29
+
30
+ Previously, returning symbols from custom `log_level` methods in configuration files would cause runtime errors like "comparison of Integer with :debug failed". This has been fixed to properly convert symbols to their corresponding integer values.
31
+
32
+ ``` ruby
33
+ # config/console.rb - This now works correctly:
34
+ def log_level(env = ENV)
35
+ :debug # Automatically converted to Console::Logger::LEVELS[:debug]
36
+ end
37
+ ```
38
+
39
+ While this fix maintains backward compatibility, the recommended approach is still to use integer values directly:
40
+
41
+ ``` ruby
42
+ # config/console.rb - Recommended approach:
43
+ def log_level(env = ENV)
44
+ Console::Logger::LEVELS[:debug] # Returns 0
45
+ end
46
+ ```
47
+
48
+ ### Improved output format selection for cron jobs and email contexts.
49
+
50
+ When `MAILTO` environment variable is set (typically in cron jobs), the console library now prefers human-readable terminal output instead of JSON serialized output, even when the output stream is not a TTY. This ensures that cron job output sent via email is formatted in a readable way for administrators.
51
+
52
+ ``` ruby
53
+ # Previously in cron jobs (non-TTY), this would output JSON:
54
+ # {"time":"2025-06-07T10:30:00Z","severity":"info","subject":"CronJob","message":["Task completed"]}
55
+
56
+ # Now with MAILTO set, it outputs human-readable format:
57
+ # 0.1s info: CronJob
58
+ # | Task completed
59
+ ```
60
+
61
+ This change is conservative and only affects environments where `MAILTO` is explicitly set, ensuring compatibility with existing deployments.
62
+
3
63
  ## v1.30.0
4
64
 
5
65
  ### Introduce `Console::Config` for fine grained configuration.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.2
4
+ version: 1.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Robert Schulze
9
9
  - Bryan Powell
10
10
  - Michael Adams
11
+ - Patrik Wenger
11
12
  - Anton Sozontov
12
13
  - Cyril Roelandt
13
14
  - Cédric Boutillier
14
15
  - Felix Yan
15
16
  - Olle Jonsson
16
- - Patrik Wenger
17
17
  - Shigeru Nakajima
18
18
  - William T. Nelson
19
19
  bindir: bin
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2025-03-10 00:00:00.000000000 Z
50
+ date: 1980-01-02 00:00:00.000000000 Z
51
51
  dependencies:
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: fiber-annotation
@@ -146,14 +146,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: '3.1'
149
+ version: '3.2'
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.6.2
156
+ rubygems_version: 3.6.7
157
157
  specification_version: 4
158
158
  summary: Beautiful logging for Ruby.
159
159
  test_files: []
metadata.gz.sig CHANGED
Binary file