console-adapter-rails 0.4.0 → 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: 5cc4bca3597337b67f0d19a87e57e5bd5e989f3e99052e6a07968db52e4e77a1
4
- data.tar.gz: 2a2cd5896bf6966db23d612a05f481c41b44735ee8a36e4ea7bd1c0d6e6b7a70
3
+ metadata.gz: 057f12398013c527127c67b8b6ff58ff7c791fc198be826220054b52eb3ca931
4
+ data.tar.gz: 8e6b4ad82981ec6f48b308fe1e06cde8d186e33b863137aa0f94fc61e854a482
5
5
  SHA512:
6
- metadata.gz: 02a6978fad7e5c8d645af5e5994b610e1b71b3c618858de3a4d621c5387cb3964102e4306f0941b6c117b710ccc1d46e2a52b45a738bbb288d663da1949426bf
7
- data.tar.gz: ec8cffd46a7cd02fe812713fd87123af1ffbd880f19d79b45b8ad731def893148d2069084211ee6125ea0893971a8c83decaecc996781e8aca89be083e9aecde
6
+ metadata.gz: 100427e87bc7c51add63a4192af5b6e87a49ffd06125aa7dfd5169c0ea21d3d25a87bbcd0a6620948f2858246297ac4a15cc53cb9fe77fbb340cea10974ed74a
7
+ data.tar.gz: eea1a96c7862fbf5a60db16969acf8c4c335b0394bfdd20cd5762e15634dda0383229b6eacfa6510fb0a43487faea564630eca54b58fae7db505c4cd6ff48c59
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require "console"
7
7
 
8
- require 'action_controller/log_subscriber'
8
+ require "active_support/log_subscriber"
9
+ require "action_controller/log_subscriber"
9
10
 
10
11
  module Console
11
12
  module Adapter
12
- # A Rails adapter for the console logger.
13
13
  module Rails
14
+ # ActionController integration for Console logger. Provides log subscribers that convert Rails ActionController events into Console-compatible log messages.
14
15
  module ActionController
15
- # 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.
16
17
  class LogSubscriber < ::ActiveSupport::LogSubscriber
17
18
  # Log an ActionController `process_action` event.
18
19
  #
@@ -46,7 +47,7 @@ module Console
46
47
 
47
48
  if response and headers = response.headers
48
49
  # Extract redirect location if any:
49
- location = response.headers['Location'] || response.headers['location']
50
+ location = response.headers["Location"] || response.headers["location"]
50
51
  if location
51
52
  payload[:location] = location
52
53
  end
@@ -59,6 +60,9 @@ module Console
59
60
  end
60
61
  end
61
62
 
63
+ # Attach the log subscriber to ActionController events.
64
+ #
65
+ # @parameter notifications [ActiveSupport::Notifications] The notifications system to attach to.
62
66
  def self.apply!(notifications: ActiveSupport::Notifications)
63
67
  LogSubscriber.attach_to(:action_controller, LogSubscriber.new, notifications)
64
68
  end
@@ -1,16 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
5
 
6
- require 'console'
6
+ require "console"
7
7
 
8
- require 'active_record/log_subscriber'
8
+ require "active_support/log_subscriber"
9
+ require "active_record/log_subscriber"
9
10
 
10
11
  module Console
11
12
  module Adapter
12
13
  module Rails
14
+ # ActiveRecord integration for Console logger. Provides log subscribers that convert Rails ActiveRecord events into Console-compatible log messages.
13
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.
14
17
  class LogSubscriber < ::ActiveSupport::LogSubscriber
15
18
  IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN", "TRANSACTION"]
16
19
 
@@ -61,10 +64,13 @@ module Console
61
64
  end
62
65
  end
63
66
 
67
+ # Attach the log subscriber to ActiveRecord events.
68
+ #
69
+ # @parameter notifications [ActiveSupport::Notifications] The notifications system to attach to.
64
70
  def self.apply!(notifications: ActiveSupport::Notifications)
65
71
  LogSubscriber.attach_to(:active_record, LogSubscriber.new, notifications)
66
72
  end
67
73
  end
68
74
  end
69
75
  end
70
- end
76
+ end
@@ -1,19 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, by Samuel Williams.
4
+ # Copyright, 2023-2025, by Samuel Williams.
5
+ # Copyright, 2024, by Michael Adams.
5
6
 
6
- require 'console/compatible/logger'
7
+ require "console/compatible/logger"
7
8
 
8
- require 'fiber/storage'
9
- require 'active_support/logger'
10
- require 'active_support/tagged_logging'
11
- 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"
12
13
 
13
14
  if ActiveSupport::Logger.respond_to?(:logger_outputs_to?)
14
15
  # https://github.com/rails/rails/issues/44800
16
+ # Monkey patch to fix ActiveSupport::Logger compatibility.
17
+ # @namespace
15
18
  module ActiveSupport
19
+ # Extension to ActiveSupport::Logger for compatibility.
16
20
  class Logger
21
+ # Override to always return `true` for compatibility with Console logger.
22
+ #
23
+ # @returns [Boolean] Always returns `true`.
17
24
  def self.logger_outputs_to?(*)
18
25
  true
19
26
  end
@@ -25,22 +32,32 @@ module Console
25
32
  module Adapter
26
33
  # A Rails adapter for the console logger.
27
34
  module Rails
35
+ # Represents a Rails-compatible logger that extends Console::Compatible::Logger with support for silencing and fiber-local log levels.
28
36
  class Logger < ::Console::Compatible::Logger
37
+ # Initialize the logger with fiber-local silence support.
29
38
  def initialize(...)
30
39
  super
31
40
 
32
41
  @silence_key = :"#{self.class}.silence.#{object_id}"
33
42
  end
34
43
 
44
+ # Set the fiber-local log level for silencing.
45
+ # @parameter severity [Integer] The log level severity.
35
46
  def local_level= severity
36
47
  Fiber[@silence_key] = severity
37
48
  end
38
49
 
50
+ # Get the fiber-local log level.
51
+ # @returns [Integer | Nil] The current fiber-local log level, if any.
39
52
  def local_level
40
53
  Fiber[@silence_key]
41
54
  end
42
55
 
43
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.
44
61
  def silence(severity = Logger::ERROR)
45
62
  current = Fiber[@silence_key]
46
63
  Fiber[@silence_key] = severity
@@ -49,18 +66,28 @@ module Console
49
66
  Fiber[@silence_key] = current
50
67
  end
51
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.
52
73
  def silenced?(severity)
53
74
  if current = Fiber[@silence_key]
54
75
  severity < current
55
76
  end
56
77
  end
57
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.
58
83
  def add(severity, message = nil, progname = nil, &block)
59
84
  return if silenced?(severity)
60
85
 
61
86
  super(severity, message, progname, &block)
62
87
  end
63
88
 
89
+ # Configure Rails to use the Console logger.
90
+ # @parameter configuration [Rails::Configuration] The Rails configuration object to update.
64
91
  def self.apply!(configuration: ::Rails.configuration)
65
92
  # Set the logger to a compatible logger to catch `Rails.logger` output:
66
93
  configuration.logger = ActiveSupport::TaggedLogging.new(
@@ -1,36 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, by Samuel Williams.
4
+ # Copyright, 2024, by Michael Adams.
5
+ # Copyright, 2024, by Samuel Williams.
6
+ # Copyright, 2025, by Jun Jiang.
5
7
 
6
- require 'action_controller/log_subscriber'
7
- require 'action_view/log_subscriber'
8
+ require "action_controller/log_subscriber"
9
+ require "action_view/log_subscriber"
8
10
 
9
11
  module Console
10
12
  module Adapter
11
13
  module Rails
12
14
  # Hook into Rails startup process and replace Rails.logger with our custom hooks
13
15
  class Railtie < ::Rails::Railtie
14
- initializer 'console.adapter.rails', before: :initialize_logger do |app|
16
+ initializer "console.adapter.rails", before: :initialize_logger do |app|
15
17
  # 1. Set up Console to be used as the Rails logger
16
18
  Logger.apply!(configuration: app.config)
17
-
19
+
18
20
  # 2. Remove the Rails::Rack::Logger middleware as it also doubles up on request logs
19
21
  app.middleware.delete ::Rails::Rack::Logger
20
22
  end
21
-
23
+
22
24
  # 3. Remove existing log subscribers for ActionController and ActionView
23
25
  config.after_initialize do
24
- ::ActionController::LogSubscriber.detach_from :action_controller
25
-
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
+
26
32
  # Silence the default action view logs, e.g. "Rendering text template" etc
27
- ::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
28
38
  end
29
-
39
+
30
40
  config.after_initialize do
31
41
  # 4. Add a new log subscriber for ActionController
32
42
  ActionController.apply!
33
-
43
+
34
44
  # 5. (optionally) Add a new log subscriber for ActiveRecord
35
45
  # ActiveRecord.apply!
36
46
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, 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.0"
12
+ VERSION = "0.5.0"
10
13
  end
11
14
  end
12
15
  end
@@ -1,20 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2023, by Samuel Williams.
4
+ # Copyright, 2023-2024, by Samuel Williams.
5
+ # Copyright, 2024, by Michael Adams.
5
6
 
6
- require_relative 'rails/logger'
7
- require_relative 'rails/action_controller'
8
- require_relative 'rails/active_record'
9
- require_relative 'rails/railtie'
10
-
11
- module Console
12
- module Adapter
13
- # A Rails adapter for the console logger.
14
- module Rails
15
- # Placeholder to remain compatible with older clients
16
- def self.apply!
17
- end
18
- end
19
- end
20
- end
7
+ require_relative "rails/logger"
8
+ require_relative "rails/action_controller"
9
+ require_relative "rails/active_record"
10
+ require_relative "rails/railtie" if defined?(Rails::Railtie)
data/license.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2023, by Samuel Williams.
3
+ Copyright, 2023-2025, by Samuel Williams.
4
+ Copyright, 2023, by Joshua Young.
5
+ Copyright, 2024, by Michael Adams.
6
+ Copyright, 2025, by Jun Jiang.
4
7
 
5
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
9
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  Adapt Rails event logs for `console`.
4
4
 
5
- [![Development
6
- Status](https://github.com/socketry/console-adapter-rails/workflows/Test/badge.svg)](https://github.com/socketry/console-adapter-rails/actions?workflow=Test)
5
+ [![Development Status](https://github.com/socketry/console-adapter-rails/workflows/Test/badge.svg)](https://github.com/socketry/console-adapter-rails/actions?workflow=Test)
7
6
 
8
7
  ## Usage
9
8
 
@@ -23,10 +22,8 @@ We welcome contributions to this project.
23
22
 
24
23
  ### Developer Certificate of Origin
25
24
 
26
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this
27
- project must agree to this document to have their contributions accepted.
25
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
28
26
 
29
- ### Contributor Covenant
27
+ ### Community Guidelines
30
28
 
31
- This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and
32
- participants agree to abide by its terms.
29
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ - Joshua Young
9
+ - Jun Jiang
10
+ - Michael Adams
9
11
  bindir: bin
10
12
  cert_chain:
11
13
  - |
@@ -37,7 +39,7 @@ cert_chain:
37
39
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
40
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
41
  -----END CERTIFICATE-----
40
- date: 2024-04-04 00:00:00.000000000 Z
42
+ date: 1980-01-02 00:00:00.000000000 Z
41
43
  dependencies:
42
44
  - !ruby/object:Gem::Dependency
43
45
  name: console
@@ -54,35 +56,33 @@ dependencies:
54
56
  - !ruby/object:Gem::Version
55
57
  version: '1.21'
56
58
  - !ruby/object:Gem::Dependency
57
- name: rails
59
+ name: fiber-storage
58
60
  requirement: !ruby/object:Gem::Requirement
59
61
  requirements:
60
- - - ">="
62
+ - - "~>"
61
63
  - !ruby/object:Gem::Version
62
- version: '6.1'
64
+ version: '1.0'
63
65
  type: :runtime
64
66
  prerelease: false
65
67
  version_requirements: !ruby/object:Gem::Requirement
66
68
  requirements:
67
- - - ">="
69
+ - - "~>"
68
70
  - !ruby/object:Gem::Version
69
- version: '6.1'
71
+ version: '1.0'
70
72
  - !ruby/object:Gem::Dependency
71
- name: fiber-storage
73
+ name: rails
72
74
  requirement: !ruby/object:Gem::Requirement
73
75
  requirements:
74
- - - "~>"
76
+ - - ">="
75
77
  - !ruby/object:Gem::Version
76
- version: '0.1'
78
+ version: '7.0'
77
79
  type: :runtime
78
80
  prerelease: false
79
81
  version_requirements: !ruby/object:Gem::Requirement
80
82
  requirements:
81
- - - "~>"
83
+ - - ">="
82
84
  - !ruby/object:Gem::Version
83
- version: '0.1'
84
- description:
85
- email:
85
+ version: '7.0'
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -100,7 +100,7 @@ licenses:
100
100
  - MIT
101
101
  metadata:
102
102
  documentation_uri: https://socketry.github.io/console-adapter-rails/
103
- post_install_message:
103
+ source_code_uri: https://github.com/socketry/console-adapter-rails.git
104
104
  rdoc_options: []
105
105
  require_paths:
106
106
  - lib
@@ -108,15 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: '3.0'
111
+ version: '3.2'
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.5.3
119
- signing_key:
118
+ rubygems_version: 3.6.9
120
119
  specification_version: 4
121
120
  summary: Adapt Rails logs and events to the console gem.
122
121
  test_files: []
metadata.gz.sig CHANGED
Binary file