console-adapter-rails 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0482a25ab09b8ca5a4cd8b52c7509da5626a5a9c66c623d2d370348bc6701846'
4
+ data.tar.gz: f10ed2abff10dc4a103b7d2b23e57e2586f13f1e0f5c156335f89ec204077f95
5
+ SHA512:
6
+ metadata.gz: 8259a2f4a8177535c620c77933d9ec09688392119cdc344b4118817bb8e16447eb9ca1d73f3dccd04728bdff3d2ea9b83046331399c8abdc1fa7efa058d15461
7
+ data.tar.gz: b6d4b017db0f3e69f871551884a1f4144d029f3caad6bfd1568e695ede9d77428dcdabd303f5a5690bc25fea52dbf8149164fec46e59f4a2a1f68d3a8a267f65
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ module Console
7
+ module Adapter
8
+ module Rails
9
+ VERSION = "0.1.0"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require 'console'
7
+
8
+ require 'active_support/log_subscriber'
9
+ require 'action_controller/log_subscriber'
10
+ require 'action_view/log_subscriber'
11
+ require 'active_job/log_subscriber'
12
+
13
+ module Console
14
+ module Adapter
15
+ # A Rails adapter for the console logger.
16
+ module Rails
17
+ # A Rails log subscriber which is compatible with `Console::Logger`. It receives events from `ActiveSupport::Notifications` and logs them to the console.
18
+ class LogSubscriber < ActiveSupport::LogSubscriber
19
+ # Log controller action events.
20
+ #
21
+ # Includes the following fields:
22
+ # - `subject`: "process_action.action_controller"
23
+ # - `controller`: The name of the controller.
24
+ # - `action`: The action performed.
25
+ # - `format`: The format of the response.
26
+ # - `method`: The HTTP method of the request.
27
+ # - `path`: The path of the request.
28
+ # - `status`: The HTTP status code of the response.
29
+ # - `view_runtime`: The time spent rendering views.
30
+ # - `db_runtime`: The time spent querying the database.
31
+ # - `location`: The redirect location if any.
32
+ # - `allocations`: The number of allocations performed.
33
+ # - `duration`: The total time spent processing the request.
34
+ def process_action(event)
35
+ payload = event.payload.dup
36
+
37
+ # This may contain sensitive information:
38
+ params = payload.delete(:params)
39
+
40
+ # These objects are not useful and may not serialize correctly:
41
+ headers = payload.delete(:headers)
42
+ request = payload.delete(:request)
43
+ response = payload.delete(:response)
44
+
45
+ # Extract redirect location if any:
46
+ location = response.headers['Location'] || response.headers['location']
47
+ if location
48
+ payload[:location] = location
49
+ end
50
+
51
+ payload[:allocations] = event.allocations
52
+ payload[:duration] = event.duration
53
+
54
+ Console.logger.info(event.name, **payload)
55
+ end
56
+ end
57
+
58
+ # Apply the Rails adapter to the current process and Rails application.
59
+ # @parameter notifications [ActiveSupport::Notifications] The notifications object to use.
60
+ # @parameter configuration [Rails::Configuration] The configuration object to use.
61
+ def self.apply!(notifications: ActiveSupport::Notifications, configuration: ::Rails.configuration)
62
+ if notifications
63
+ # Clear out all the existing subscribers otherwise you'll get double the logs:
64
+ notifications.notifier = ActiveSupport::Notifications::Fanout.new
65
+ end
66
+
67
+ if configuration
68
+ # Set the logger to a compatible logger to catch `Rails.logger` output:
69
+ configuration.logger = Console::Compatible::Logger.new("Rails", Console.logger)
70
+ # Delete `Rails::Rack::Logger` as it also doubles up on request logs:
71
+ configuration.middleware.delete ::Rails::Rack::Logger
72
+ end
73
+
74
+ # Attach our log subscriber for action_controller events:
75
+ LogSubscriber.attach_to(:action_controller, LogSubscriber.new, notifications)
76
+ end
77
+ end
78
+ end
79
+ end
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2023, by Samuel Williams.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,33 @@
1
+ # Console::Adapter::Rails
2
+
3
+ Adapt Rails event logs for `console`.
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)
7
+
8
+ ## Usage
9
+
10
+ Please see the [project documentation](https://github.com/socketry/console-adapter-rails) for more details.
11
+
12
+ - [Getting Started](https://github.com/socketry/console-adapter-railsguides/getting-started/index) - This guide
13
+ explains how to integrate the `console-adapter-rails` gem into your Rails application.
14
+
15
+ ## Contributing
16
+
17
+ We welcome contributions to this project.
18
+
19
+ 1. Fork it.
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
22
+ 4. Push to the branch (`git push origin my-new-feature`).
23
+ 5. Create new Pull Request.
24
+
25
+ ### Developer Certificate of Origin
26
+
27
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this
28
+ project must agree to this document to have their contributions accepted.
29
+
30
+ ### Contributor Covenant
31
+
32
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and
33
+ participants agree to abide by its terms.
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: console-adapter-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
14
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
15
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
16
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
17
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
18
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
19
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
20
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
21
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
22
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
23
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrV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: 2023-08-02 00:00:00.000000000 Z
41
+ dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: console
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '6.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '6.1'
70
+ description:
71
+ email:
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/console/adapter/rails.rb
77
+ - lib/console/adapter/rails/version.rb
78
+ - license.md
79
+ - readme.md
80
+ homepage: https://github.com/socketry/console-adapter-rails
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '3.0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.4.10
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Adapt Rails logs and events to the console gem.
103
+ test_files: []
metadata.gz.sig ADDED
Binary file