console-adapter-rails 0.4.1 → 0.5.1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +15 -0
- data/context/index.yaml +12 -0
- data/lib/console/adapter/rails/action_controller.rb +10 -7
- data/lib/console/adapter/rails/active_record.rb +9 -4
- data/lib/console/adapter/rails/logger.rb +32 -6
- data/lib/console/adapter/rails/railtie.rb +19 -10
- data/lib/console/adapter/rails/version.rb +5 -2
- data/lib/console/adapter/rails.rb +3 -3
- data/license.md +2 -1
- data/readme.md +8 -0
- data/releases.md +5 -0
- data.tar.gz.sig +0 -0
- metadata +10 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87a3133534ae9fef350296fe8f70381f69506077331665169523a7a59fef0786
|
|
4
|
+
data.tar.gz: c23583428a0b77f235b72e2c83b57818e53da8581d9087a739d30cf33e6b535e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8d8d61c59a6c62fc9dbac96c1dbe7e60f00dc3cfd79322cc2e15a4bf7ea37a563516ac682994c96375a69ec5d9cd7cff1ff13b901df33f8b49aacbcf8f4e0cf
|
|
7
|
+
data.tar.gz: 5a3431fdcbe71b50d272ea61f0d56295b4a19520e77ee03cb7f42995faa884f35aab8dc01ed5b5c29702e5ec956e9061eb9c99176d7d8a4db386e24ee76ae575
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
This guide explains how to integrate the `console-adapter-rails` gem into your Rails application.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your project:
|
|
8
|
+
|
|
9
|
+
~~~ bash
|
|
10
|
+
$ bundle add console-adapter-rails
|
|
11
|
+
~~~
|
|
12
|
+
|
|
13
|
+
The gem includes a Railtie that will set up all required logging configuration for you.
|
|
14
|
+
|
|
15
|
+
If you wish to log ActiveRecord, add `Console::Adapter::Rails::ActiveRecord.apply!` into your `config/environment.rb` file, before the `Rails.application.initialize!` call.
|
data/context/index.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Automatically generated context index for Utopia::Project guides.
|
|
2
|
+
# Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
|
|
3
|
+
---
|
|
4
|
+
description: Adapt Rails logs and events to the console gem.
|
|
5
|
+
metadata:
|
|
6
|
+
documentation_uri: https://socketry.github.io/console-adapter-rails/
|
|
7
|
+
source_code_uri: https://github.com/socketry/console-adapter-rails.git
|
|
8
|
+
files:
|
|
9
|
+
- path: getting-started.md
|
|
10
|
+
title: Getting Started
|
|
11
|
+
description: This guide explains how to integrate the `console-adapter-rails` gem
|
|
12
|
+
into your Rails application.
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2023-
|
|
4
|
+
# Copyright, 2023-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
|
-
require
|
|
6
|
+
require "console"
|
|
7
7
|
|
|
8
|
-
require
|
|
9
|
-
require
|
|
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
|
-
#
|
|
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[
|
|
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-
|
|
4
|
+
# Copyright, 2023-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
|
-
require
|
|
6
|
+
require "console"
|
|
7
7
|
|
|
8
|
-
require
|
|
9
|
-
require
|
|
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-
|
|
4
|
+
# Copyright, 2023-2025, by Samuel Williams.
|
|
5
5
|
# Copyright, 2024, by Michael Adams.
|
|
6
6
|
|
|
7
|
-
require
|
|
7
|
+
require "console/compatible/logger"
|
|
8
8
|
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
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
|
|
8
|
-
require
|
|
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
|
|
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
|
|
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
|
|
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-
|
|
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.
|
|
12
|
+
VERSION = "0.5.1"
|
|
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
|
|
8
|
-
require_relative
|
|
9
|
-
require_relative
|
|
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-
|
|
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/readme.md
CHANGED
|
@@ -10,6 +10,14 @@ Please see the [project documentation](https://socketry.github.io/console-adapte
|
|
|
10
10
|
|
|
11
11
|
- [Getting Started](https://socketry.github.io/console-adapter-rails/guides/getting-started/index) - This guide explains how to integrate the `console-adapter-rails` gem into your Rails application.
|
|
12
12
|
|
|
13
|
+
## Releases
|
|
14
|
+
|
|
15
|
+
Please see the [project releases](https://socketry.github.io/console-adapter-rails/releases/index) for all releases.
|
|
16
|
+
|
|
17
|
+
### v0.5.0
|
|
18
|
+
|
|
19
|
+
- Improved compatibilty with Rails 8+.
|
|
20
|
+
|
|
13
21
|
## Contributing
|
|
14
22
|
|
|
15
23
|
We welcome contributions to this project.
|
data/releases.md
ADDED
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
|
+
version: 0.5.1
|
|
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:
|
|
42
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
43
43
|
dependencies:
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
45
|
name: console
|
|
@@ -75,20 +75,20 @@ dependencies:
|
|
|
75
75
|
requirements:
|
|
76
76
|
- - ">="
|
|
77
77
|
- !ruby/object:Gem::Version
|
|
78
|
-
version: '
|
|
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: '
|
|
86
|
-
description:
|
|
87
|
-
email:
|
|
85
|
+
version: '7.0'
|
|
88
86
|
executables: []
|
|
89
87
|
extensions: []
|
|
90
88
|
extra_rdoc_files: []
|
|
91
89
|
files:
|
|
90
|
+
- context/getting-started.md
|
|
91
|
+
- context/index.yaml
|
|
92
92
|
- lib/console/adapter/rails.rb
|
|
93
93
|
- lib/console/adapter/rails/action_controller.rb
|
|
94
94
|
- lib/console/adapter/rails/active_record.rb
|
|
@@ -97,13 +97,13 @@ files:
|
|
|
97
97
|
- lib/console/adapter/rails/version.rb
|
|
98
98
|
- license.md
|
|
99
99
|
- readme.md
|
|
100
|
+
- releases.md
|
|
100
101
|
homepage: https://github.com/socketry/console-adapter-rails
|
|
101
102
|
licenses:
|
|
102
103
|
- MIT
|
|
103
104
|
metadata:
|
|
104
105
|
documentation_uri: https://socketry.github.io/console-adapter-rails/
|
|
105
106
|
source_code_uri: https://github.com/socketry/console-adapter-rails.git
|
|
106
|
-
post_install_message:
|
|
107
107
|
rdoc_options: []
|
|
108
108
|
require_paths:
|
|
109
109
|
- lib
|
|
@@ -111,15 +111,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
111
111
|
requirements:
|
|
112
112
|
- - ">="
|
|
113
113
|
- !ruby/object:Gem::Version
|
|
114
|
-
version: '3.
|
|
114
|
+
version: '3.2'
|
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
requirements:
|
|
117
117
|
- - ">="
|
|
118
118
|
- !ruby/object:Gem::Version
|
|
119
119
|
version: '0'
|
|
120
120
|
requirements: []
|
|
121
|
-
rubygems_version: 3.
|
|
122
|
-
signing_key:
|
|
121
|
+
rubygems_version: 3.6.9
|
|
123
122
|
specification_version: 4
|
|
124
123
|
summary: Adapt Rails logs and events to the console gem.
|
|
125
124
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|