rails_custom_logging 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a8cf2972315f37dc34b1a93b0a35c9f16fcf5a4446c1be943185976aa8b4ded
4
- data.tar.gz: 77b245d3dd1cc94996f9c2192efaf3bd05e53c3d2a0011b1e0979ca940c7fa16
3
+ metadata.gz: 30e889ddb6c1d71e3d4421e86b1dd75f14abb92c8e06da9718f7faf2f4e00796
4
+ data.tar.gz: e912f4562b9d71502284fd19101eff6b30cb988d08e58ab60cbf9ac31626bc4f
5
5
  SHA512:
6
- metadata.gz: 93e886789b96665662ad93e05f166f5fff1bc5ef1d68dd45e84c501273db2b9f413f4f13b812c92017f6c370777e7ae72bdb8ab12f6d6d171d8b9a1dd7072944
7
- data.tar.gz: 40490845dda83e4a27d6d340426441d1a9a410629d0a602c91f5b8dea83775d3be4d499826a22d410cbda1ed683da45038d500570e046a3734dd0e712defc360
6
+ metadata.gz: 136e2d7325bbe61f219b16f0b7603e306cda5687d0ddb87cf08b771660685652f228527ac1307738d711aaffdf1929cc28c802c2f3ece40286602065e7a677af
7
+ data.tar.gz: 8a7d941f7b6c870fa71fc8679e7d81d3b1e85811f21509e5f9c8e39c2ca491b9fadc47c8018562eb8115ad3d4d0c18a6dfdfa6d58ad3c031d75de5a52c4eb00c
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ /.byebug_history
11
+ /Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ env:
6
+ - "RAILS_VERSION=6.0.0"
7
+ - "RAILS_VERSION=6.1.0"
8
+ - "RAILS_VERSION=7.0.0"
9
+ rvm:
10
+ - 2.6.5
11
+ - 2.7.2
12
+ - 3.0.0
13
+ before_install: gem update bundler
14
+ jobs:
15
+ exclude:
16
+ - rvm: 2.6.5
17
+ env: "RAILS_VERSION=7.0.0"
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.2.0
4
+ * Drop support for Rails 5.2
5
+ * Add support for Rails 7
6
+ * Add travis configuration
7
+ * Remove `request` and `response` from the default formatter's result
8
+
9
+ ## 0.1.0
10
+ * Initial release
data/Gemfile CHANGED
@@ -5,5 +5,16 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in rails_custom_logging.gemspec
6
6
  gemspec
7
7
 
8
- gem "rake", "~> 13.0"
9
- gem "minitest", "~> 5.0"
8
+ rails_version = ENV['RAILS_VERSION'] || 'default'
9
+
10
+ version = case rails_version
11
+ when 'master'
12
+ { github: 'rails/rails' }
13
+ when "default"
14
+ '~> 6.1.3'
15
+ else
16
+ "~> #{rails_version}"
17
+ end
18
+
19
+ gem 'activerecord', version
20
+ gem 'activesupport', version
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # RailsCustomLogging
1
+ # Rails Custom Logging
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_custom_logging`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ An oponionated yet fully customizable way to tranform your Rails logs into useful data.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Currently supported Ruby versions: 2.6, 2.7, 3.0.
6
+ Currently supported Rails versions: 6.0, 6.1, 7.0
6
7
 
7
8
  ## Installation
8
9
 
@@ -12,23 +13,21 @@ Add this line to your application's Gemfile:
12
13
  gem 'rails_custom_logging'
13
14
  ```
14
15
 
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install rails_custom_logging
22
-
23
16
  ## Usage
24
17
 
25
- TODO: Write usage instructions here
18
+ Enable the gem in an initializer or in any environment config:
26
19
 
27
- ## Development
20
+ ```ruby
21
+ # config/initializers/logging.rb
22
+
23
+ RailsCustomLogging.configure do |config|
24
+ config.enabled = Rails.env.production?
25
+ end
26
+ ```
28
27
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+ ## Customization
30
29
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+ TODO
32
31
 
33
32
  ## Contributing
34
33
 
@@ -7,10 +7,12 @@ module RailsCustomLogging
7
7
  # MRI trick to force the order of the payload keys with a very light cost of a single
8
8
  # merge. MRI hash's `to_a` method will return values in the order in which they are
9
9
  # defined by implemention. `merge` follows the same pattern.
10
- #
11
10
  # If you're using another implemention of Ruby (jRuby/truffleruby) you might end up
12
11
  # with unordered keys.
13
12
  #
13
+ # Additional keys in the payload will be added at the end, ordering being left at
14
+ # your discretion.
15
+ #
14
16
  ORDERED_HASH = {
15
17
  method: nil, path: nil, params: nil, format: nil, status: nil, controller: nil,
16
18
  action: nil, duration: nil, db_runtime: nil, view_runtime: nil, allocations: nil
@@ -1,6 +1,6 @@
1
1
  module RailsCustomLogging
2
2
  module Rack
3
- # Replace `Rails::Rack::Logger` middleware with this one to avoid pesky Rack logs
3
+ # Replaces `Rails::Rack::Logger` middleware with this one to avoid pesky Rack logs
4
4
  # lines like `Started GET /`.
5
5
  #
6
6
  class Logger
@@ -1,22 +1,14 @@
1
- require_relative 'rails_ext/rack/logger'
2
-
3
1
  module RailsCustomLogging
4
2
  class Railtie < Rails::Railtie
5
3
  initializer 'rails_custom_logging.middleware', after: :load_config_initializers do |app|
6
4
  if RailsCustomLogging.enabled?
5
+ require_relative 'rails_ext/rack/logger'
7
6
  app.middleware.swap Rails::Rack::Logger, RailsCustomLogging::Rack::Logger
8
7
  end
9
8
  end
10
9
 
11
10
  config.after_initialize do |app|
12
- if RailsCustomLogging.enabled?
13
- if Rails::VERSION::MAJOR < 6
14
- # Adds missing `detach_from` method in subscriber
15
- require 'rails_custom_logging/rails_ext/active_support/subscriber'
16
- end
17
-
18
- RailsCustomLogging.setup(app)
19
- end
11
+ RailsCustomLogging.setup(app) if RailsCustomLogging.enabled?
20
12
  end
21
13
  end
22
14
  end
@@ -2,17 +2,43 @@
2
2
 
3
3
  module RailsCustomLogging
4
4
  module Transformers
5
+ # Transforms a ActiveSupport::Notifications::Event into a Hash with
6
+ # basic values any application could use.
7
+ #
5
8
  module Default
6
- def self.call(event)
7
- payload = event.payload.dup
9
+ class << self
10
+ def call(event)
11
+ payload = event.payload.dup
8
12
 
9
- payload[:params] = payload[:params]&.except('action', 'controller', 'id')
10
- payload[:duration] = event.duration
13
+ if payload.key?(:params)
14
+ payload[:params] = payload[:params].except('action', 'controller', 'id')
15
+ payload.delete(:params) if payload[:params].empty?
16
+ end
11
17
 
12
- payload.delete(:headers)
13
- payload.delete(:params) if payload[:params]&.empty?
18
+ payload[:duration] = event.duration
19
+ payload[:allocations] = event.allocations
14
20
 
15
- payload
21
+ payload.delete(:headers)
22
+ payload.delete(:response)
23
+ payload[:path] = extract_path(payload)
24
+ payload.delete(:request)
25
+
26
+ payload
27
+ end
28
+
29
+ private
30
+
31
+ if ::ActionPack::VERSION::MAJOR == 6 && ::ActionPack::VERSION::MINOR == 0
32
+ def extract_path(payload)
33
+ path = payload[:path]
34
+ index = path.index("?")
35
+ index ? path.slice(0, index) : path
36
+ end
37
+ else
38
+ def extract_path(payload)
39
+ payload[:request].path
40
+ end
41
+ end
16
42
  end
17
43
  end
18
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsCustomLogging
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -31,6 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_dependency "activesupport", ">= 5.2", "< 7"
35
- spec.add_dependency "actionpack", ">= 5.2", "< 7"
34
+ spec.add_dependency "activesupport", ">= 6.0", "< 8"
35
+ spec.add_dependency "actionpack", ">= 6.0", "< 8"
36
+
37
+ spec.add_development_dependency "rake", "~> 13.0"
38
+ spec.add_development_dependency "minitest", "~> 5.0"
36
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_custom_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Cocchi-Perrier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,40 +16,68 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.2'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '8'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '5.2'
39
+ version: '6.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '7'
42
+ version: '8'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '5.2'
49
+ version: '6.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '7'
52
+ version: '8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '13.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '13.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: minitest
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '5.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '5.0'
53
81
  description: 'Replace Rails'' verbose logs with anything you like, from one-liner
54
82
  keys/values to even more verbose logging (it you think that''s possible).
55
83
 
@@ -61,9 +89,10 @@ extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
91
  - ".gitignore"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
64
94
  - CODE_OF_CONDUCT.md
65
95
  - Gemfile
66
- - Gemfile.lock
67
96
  - LICENSE.txt
68
97
  - README.md
69
98
  - Rakefile
@@ -72,7 +101,6 @@ files:
72
101
  - lib/rails_custom_logging.rb
73
102
  - lib/rails_custom_logging/configuration.rb
74
103
  - lib/rails_custom_logging/formatters/key_value.rb
75
- - lib/rails_custom_logging/rails_ext/active_support/subscriber.rb
76
104
  - lib/rails_custom_logging/rails_ext/rack/logger.rb
77
105
  - lib/rails_custom_logging/railtie.rb
78
106
  - lib/rails_custom_logging/subscribers/action_controller.rb
data/Gemfile.lock DELETED
@@ -1,64 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rails_custom_logging (0.1.0)
5
- actionpack (>= 5.2, < 7)
6
- activesupport (>= 5.2, < 7)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (5.2.4.4)
12
- actionview (= 5.2.4.4)
13
- activesupport (= 5.2.4.4)
14
- rack (~> 2.0, >= 2.0.8)
15
- rack-test (>= 0.6.3)
16
- rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (5.2.4.4)
19
- activesupport (= 5.2.4.4)
20
- builder (~> 3.1)
21
- erubi (~> 1.4)
22
- rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
- activesupport (5.2.4.4)
25
- concurrent-ruby (~> 1.0, >= 1.0.2)
26
- i18n (>= 0.7, < 2)
27
- minitest (~> 5.1)
28
- tzinfo (~> 1.1)
29
- builder (3.2.4)
30
- concurrent-ruby (1.1.8)
31
- crass (1.0.6)
32
- erubi (1.10.0)
33
- i18n (1.8.7)
34
- concurrent-ruby (~> 1.0)
35
- loofah (2.9.0)
36
- crass (~> 1.0.2)
37
- nokogiri (>= 1.5.9)
38
- minitest (5.14.3)
39
- nokogiri (1.11.1-x86_64-darwin)
40
- racc (~> 1.4)
41
- racc (1.5.2)
42
- rack (2.2.3)
43
- rack-test (1.1.0)
44
- rack (>= 1.0, < 3)
45
- rails-dom-testing (2.0.3)
46
- activesupport (>= 4.2.0)
47
- nokogiri (>= 1.6)
48
- rails-html-sanitizer (1.3.0)
49
- loofah (~> 2.3)
50
- rake (13.0.3)
51
- thread_safe (0.3.6)
52
- tzinfo (1.2.9)
53
- thread_safe (~> 0.1)
54
-
55
- PLATFORMS
56
- x86_64-darwin-19
57
-
58
- DEPENDENCIES
59
- minitest (~> 5.0)
60
- rails_custom_logging!
61
- rake (~> 13.0)
62
-
63
- BUNDLED WITH
64
- 2.2.5
@@ -1,49 +0,0 @@
1
- # Backport `detach_from` method added in Rails 6
2
- # https://github.com/rails/rails/blob/v6.1.1/activesupport/lib/active_support/subscriber.rb
3
- #
4
- module RailsCustomLogging
5
- module ActiveSupport
6
- module Subscriber
7
- def detach_from(namespace, notifier = ::ActiveSupport::Notifications)
8
- @namespace = namespace
9
- @subscriber = subscribers.find { |s| s.instance_of?(self) }
10
- @notifier = notifier
11
-
12
- return unless subscriber
13
-
14
- subscribers.delete(subscriber)
15
-
16
- # Remove event subscriber for all existing methods on the class.
17
- subscriber.public_methods(false).each do |event|
18
- remove_event_subscriber(event)
19
- end
20
-
21
- # Reset notifier so that event subscribers will not add for new methods added to the class.
22
- @notifier = nil
23
- end
24
-
25
- private
26
-
27
- def invalid_event?(event)
28
- %i[start finish].include?(event.to_sym)
29
- end
30
-
31
- def remove_event_subscriber(event)
32
- return if invalid_event?(event)
33
-
34
- pattern = "#{event}.#{namespace}"
35
-
36
- return unless subscriber.patterns.include?(pattern)
37
-
38
- subscriber.patterns.delete(pattern)
39
- ::ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |li|
40
- if li.instance_variable_get(:@delegate) == subscriber
41
- notifier.unsubscribe(li)
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
48
-
49
- ::ActiveSupport::Subscriber.extend(RailsCustomLogging::ActiveSupport::Subscriber)