console-adapter-rails 0.4.1 → 0.5.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: a4e48e85afc72be9449b0da7dcc6ea25c3333daaafe092062429ea8944fcca98
4
- data.tar.gz: 3c325105475e32b6099d9eb35c7fe6ec2ec6990ef920c2b07cb03e4c4d211206
3
+ metadata.gz: 057f12398013c527127c67b8b6ff58ff7c791fc198be826220054b52eb3ca931
4
+ data.tar.gz: 8e6b4ad82981ec6f48b308fe1e06cde8d186e33b863137aa0f94fc61e854a482
5
5
  SHA512:
6
- metadata.gz: d0265cf56ce46b5fac25cc1c3efccc071951b84d57e46d8e572ea5f16a8a70cacc2ea2645d9696acf4ccf5bfcaa1233d7dbd360da9b6738d483c534ca85eb785
7
- data.tar.gz: 3f7377560820af3bd579778be6d85f15a0a83846eff9c1eca3e25a0957df0996010d8fcdfbb31f7a6f156d585cb42223c1bb1094d1b1e2c0ef8ad5591f6cd3fa
6
+ metadata.gz: 100427e87bc7c51add63a4192af5b6e87a49ffd06125aa7dfd5169c0ea21d3d25a87bbcd0a6620948f2858246297ac4a15cc53cb9fe77fbb340cea10974ed74a
7
+ data.tar.gz: eea1a96c7862fbf5a60db16969acf8c4c335b0394bfdd20cd5762e15634dda0383229b6eacfa6510fb0a43487faea564630eca54b58fae7db505c4cd6ff48c59
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023-2024, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require "console"
7
7
 
8
- require 'active_support/log_subscriber'
9
- require 'action_controller/log_subscriber'
8
+ require "active_support/log_subscriber"
9
+ require "action_controller/log_subscriber"
10
10
 
11
11
  module Console
12
12
  module Adapter
13
- # A Rails adapter for the console logger.
14
13
  module Rails
14
+ # ActionController integration for Console logger. Provides log subscribers that convert Rails ActionController events into Console-compatible log messages.
15
15
  module ActionController
16
- # A Rails log subscriber which is compatible with `Console::Logger`. It receives events from `ActiveSupport::Notifications` and logs them to the console.
16
+ # Represents a Rails log subscriber which is compatible with `Console::Logger`. It receives events from `ActiveSupport::Notifications` and logs them to the console.
17
17
  class LogSubscriber < ::ActiveSupport::LogSubscriber
18
18
  # Log an ActionController `process_action` event.
19
19
  #
@@ -47,7 +47,7 @@ module Console
47
47
 
48
48
  if response and headers = response.headers
49
49
  # Extract redirect location if any:
50
- location = response.headers['Location'] || response.headers['location']
50
+ location = response.headers["Location"] || response.headers["location"]
51
51
  if location
52
52
  payload[:location] = location
53
53
  end
@@ -60,6 +60,9 @@ module Console
60
60
  end
61
61
  end
62
62
 
63
+ # Attach the log subscriber to ActionController events.
64
+ #
65
+ # @parameter notifications [ActiveSupport::Notifications] The notifications system to attach to.
63
66
  def self.apply!(notifications: ActiveSupport::Notifications)
64
67
  LogSubscriber.attach_to(:action_controller, LogSubscriber.new, notifications)
65
68
  end
@@ -1,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023-2024, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require "console"
7
7
 
8
- require 'active_support/log_subscriber'
9
- require 'active_record/log_subscriber'
8
+ require "active_support/log_subscriber"
9
+ require "active_record/log_subscriber"
10
10
 
11
11
  module Console
12
12
  module Adapter
13
13
  module Rails
14
+ # ActiveRecord integration for Console logger. Provides log subscribers that convert Rails ActiveRecord events into Console-compatible log messages.
14
15
  module ActiveRecord
16
+ # Represents a Rails log subscriber which is compatible with `Console::Logger`. It receives SQL events from `ActiveSupport::Notifications` and logs them to the console.
15
17
  class LogSubscriber < ::ActiveSupport::LogSubscriber
16
18
  IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN", "TRANSACTION"]
17
19
 
@@ -62,6 +64,9 @@ module Console
62
64
  end
63
65
  end
64
66
 
67
+ # Attach the log subscriber to ActiveRecord events.
68
+ #
69
+ # @parameter notifications [ActiveSupport::Notifications] The notifications system to attach to.
65
70
  def self.apply!(notifications: ActiveSupport::Notifications)
66
71
  LogSubscriber.attach_to(:active_record, LogSubscriber.new, notifications)
67
72
  end
@@ -1,20 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023-2024, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
  # Copyright, 2024, by Michael Adams.
6
6
 
7
- require 'console/compatible/logger'
7
+ require "console/compatible/logger"
8
8
 
9
- require 'fiber/storage'
10
- require 'active_support/logger'
11
- require 'active_support/tagged_logging'
12
- require 'active_support/logger_silence'
9
+ require "fiber/storage"
10
+ require "active_support/logger"
11
+ require "active_support/tagged_logging"
12
+ require "active_support/logger_silence"
13
13
 
14
14
  if ActiveSupport::Logger.respond_to?(:logger_outputs_to?)
15
15
  # https://github.com/rails/rails/issues/44800
16
+ # Monkey patch to fix ActiveSupport::Logger compatibility.
17
+ # @namespace
16
18
  module ActiveSupport
19
+ # Extension to ActiveSupport::Logger for compatibility.
17
20
  class Logger
21
+ # Override to always return `true` for compatibility with Console logger.
22
+ #
23
+ # @returns [Boolean] Always returns `true`.
18
24
  def self.logger_outputs_to?(*)
19
25
  true
20
26
  end
@@ -26,22 +32,32 @@ module Console
26
32
  module Adapter
27
33
  # A Rails adapter for the console logger.
28
34
  module Rails
35
+ # Represents a Rails-compatible logger that extends Console::Compatible::Logger with support for silencing and fiber-local log levels.
29
36
  class Logger < ::Console::Compatible::Logger
37
+ # Initialize the logger with fiber-local silence support.
30
38
  def initialize(...)
31
39
  super
32
40
 
33
41
  @silence_key = :"#{self.class}.silence.#{object_id}"
34
42
  end
35
43
 
44
+ # Set the fiber-local log level for silencing.
45
+ # @parameter severity [Integer] The log level severity.
36
46
  def local_level= severity
37
47
  Fiber[@silence_key] = severity
38
48
  end
39
49
 
50
+ # Get the fiber-local log level.
51
+ # @returns [Integer | Nil] The current fiber-local log level, if any.
40
52
  def local_level
41
53
  Fiber[@silence_key]
42
54
  end
43
55
 
44
56
  # Silences the logger for the duration of the block.
57
+ #
58
+ # @parameter severity [Integer] The minimum severity level to log.
59
+ # @yields {|logger| ...} Yields the logger instance to the block.
60
+ # @parameter logger [Logger] The current logger instance.
45
61
  def silence(severity = Logger::ERROR)
46
62
  current = Fiber[@silence_key]
47
63
  Fiber[@silence_key] = severity
@@ -50,18 +66,28 @@ module Console
50
66
  Fiber[@silence_key] = current
51
67
  end
52
68
 
69
+ # Check if the logger is silenced for the given severity level.
70
+ #
71
+ # @parameter severity [Integer] The log level severity to check.
72
+ # @returns [Boolean] `true` if the logger is silenced for this severity.
53
73
  def silenced?(severity)
54
74
  if current = Fiber[@silence_key]
55
75
  severity < current
56
76
  end
57
77
  end
58
78
 
79
+ # Add a log message, respecting the silence level.
80
+ # @parameter severity [Integer] The log level severity.
81
+ # @parameter message [String | Nil] The log message.
82
+ # @parameter progname [String | Nil] The program name.
59
83
  def add(severity, message = nil, progname = nil, &block)
60
84
  return if silenced?(severity)
61
85
 
62
86
  super(severity, message, progname, &block)
63
87
  end
64
88
 
89
+ # Configure Rails to use the Console logger.
90
+ # @parameter configuration [Rails::Configuration] The Rails configuration object to update.
65
91
  def self.apply!(configuration: ::Rails.configuration)
66
92
  # Set the logger to a compatible logger to catch `Rails.logger` output:
67
93
  configuration.logger = ActiveSupport::TaggedLogging.new(
@@ -3,35 +3,44 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Michael Adams.
5
5
  # Copyright, 2024, by Samuel Williams.
6
+ # Copyright, 2025, by Jun Jiang.
6
7
 
7
- require 'action_controller/log_subscriber'
8
- require 'action_view/log_subscriber'
8
+ require "action_controller/log_subscriber"
9
+ require "action_view/log_subscriber"
9
10
 
10
11
  module Console
11
12
  module Adapter
12
13
  module Rails
13
14
  # Hook into Rails startup process and replace Rails.logger with our custom hooks
14
15
  class Railtie < ::Rails::Railtie
15
- initializer 'console.adapter.rails', before: :initialize_logger do |app|
16
+ initializer "console.adapter.rails", before: :initialize_logger do |app|
16
17
  # 1. Set up Console to be used as the Rails logger
17
18
  Logger.apply!(configuration: app.config)
18
-
19
+
19
20
  # 2. Remove the Rails::Rack::Logger middleware as it also doubles up on request logs
20
21
  app.middleware.delete ::Rails::Rack::Logger
21
22
  end
22
-
23
+
23
24
  # 3. Remove existing log subscribers for ActionController and ActionView
24
25
  config.after_initialize do
25
- ::ActionController::LogSubscriber.detach_from :action_controller
26
-
26
+ if ::ActionController::LogSubscriber < ::ActiveSupport::LogSubscriber
27
+ ::ActionController::LogSubscriber.detach_from :action_controller
28
+ else
29
+ ::ActiveSupport.event_reporter.unsubscribe(::ActionController::LogSubscriber)
30
+ end
31
+
27
32
  # Silence the default action view logs, e.g. "Rendering text template" etc
28
- ::ActionView::LogSubscriber.detach_from :action_view
33
+ if ::ActionView::LogSubscriber < ::ActiveSupport::LogSubscriber
34
+ ::ActionView::LogSubscriber.detach_from :action_view
35
+ else
36
+ ::ActiveSupport.event_reporter.unsubscribe(::ActionView::LogSubscriber)
37
+ end
29
38
  end
30
-
39
+
31
40
  config.after_initialize do
32
41
  # 4. Add a new log subscriber for ActionController
33
42
  ActionController.apply!
34
-
43
+
35
44
  # 5. (optionally) Add a new log subscriber for ActiveRecord
36
45
  # ActiveRecord.apply!
37
46
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023-2024, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
 
6
+ # @namespace
6
7
  module Console
8
+ # @namespace
7
9
  module Adapter
10
+ # @namespace
8
11
  module Rails
9
- VERSION = "0.4.1"
12
+ VERSION = "0.5.0"
10
13
  end
11
14
  end
12
15
  end
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
  # Copyright, 2024, by Michael Adams.
6
6
 
7
- require_relative 'rails/logger'
8
- require_relative 'rails/action_controller'
9
- require_relative 'rails/active_record'
7
+ require_relative "rails/logger"
8
+ require_relative "rails/action_controller"
9
+ require_relative "rails/active_record"
10
10
  require_relative "rails/railtie" if defined?(Rails::Railtie)
data/license.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2023-2024, by Samuel Williams.
3
+ Copyright, 2023-2025, by Samuel Williams.
4
4
  Copyright, 2023, by Joshua Young.
5
5
  Copyright, 2024, by Michael Adams.
6
+ Copyright, 2025, by Jun Jiang.
6
7
 
7
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
9
  of this software and associated documentation files (the "Software"), to deal
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console-adapter-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Joshua Young
9
+ - Jun Jiang
9
10
  - Michael Adams
10
- autorequire:
11
11
  bindir: bin
12
12
  cert_chain:
13
13
  - |
@@ -39,7 +39,7 @@ cert_chain:
39
39
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
40
40
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
41
41
  -----END CERTIFICATE-----
42
- date: 2024-08-09 00:00:00.000000000 Z
42
+ date: 1980-01-02 00:00:00.000000000 Z
43
43
  dependencies:
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: console
@@ -75,16 +75,14 @@ dependencies:
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: '6.1'
78
+ version: '7.0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: '6.1'
86
- description:
87
- email:
85
+ version: '7.0'
88
86
  executables: []
89
87
  extensions: []
90
88
  extra_rdoc_files: []
@@ -103,7 +101,6 @@ licenses:
103
101
  metadata:
104
102
  documentation_uri: https://socketry.github.io/console-adapter-rails/
105
103
  source_code_uri: https://github.com/socketry/console-adapter-rails.git
106
- post_install_message:
107
104
  rdoc_options: []
108
105
  require_paths:
109
106
  - lib
@@ -111,15 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
108
  requirements:
112
109
  - - ">="
113
110
  - !ruby/object:Gem::Version
114
- version: '3.1'
111
+ version: '3.2'
115
112
  required_rubygems_version: !ruby/object:Gem::Requirement
116
113
  requirements:
117
114
  - - ">="
118
115
  - !ruby/object:Gem::Version
119
116
  version: '0'
120
117
  requirements: []
121
- rubygems_version: 3.5.11
122
- signing_key:
118
+ rubygems_version: 3.6.9
123
119
  specification_version: 4
124
120
  summary: Adapt Rails logs and events to the console gem.
125
121
  test_files: []
metadata.gz.sig CHANGED
Binary file