timber-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +56 -0
- data/Gemfile +8 -0
- data/LICENSE.md +15 -0
- data/README.md +12 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/rails-3.0.gemfile +8 -0
- data/gemfiles/rails-3.1.gemfile +8 -0
- data/gemfiles/rails-3.2.gemfile +8 -0
- data/gemfiles/rails-4.0.gemfile +12 -0
- data/gemfiles/rails-4.1.gemfile +12 -0
- data/gemfiles/rails-4.2.gemfile +12 -0
- data/gemfiles/rails-5.0.gemfile +12 -0
- data/gemfiles/rails-5.1.gemfile +12 -0
- data/gemfiles/rails-5.2.gemfile +12 -0
- data/gemfiles/rails-edge.gemfile +11 -0
- data/lib/timber-rails/action_controller/log_subscriber/timber_log_subscriber.rb +46 -0
- data/lib/timber-rails/action_controller/log_subscriber.rb +25 -0
- data/lib/timber-rails/action_controller.rb +17 -0
- data/lib/timber-rails/action_dispatch/debug_exceptions.rb +51 -0
- data/lib/timber-rails/action_dispatch.rb +20 -0
- data/lib/timber-rails/action_view/log_subscriber/timber_log_subscriber.rb +83 -0
- data/lib/timber-rails/action_view/log_subscriber.rb +25 -0
- data/lib/timber-rails/action_view.rb +17 -0
- data/lib/timber-rails/active_record/log_subscriber/timber_log_subscriber.rb +52 -0
- data/lib/timber-rails/active_record/log_subscriber.rb +20 -0
- data/lib/timber-rails/active_record.rb +17 -0
- data/lib/timber-rails/config/action_controller.rb +29 -0
- data/lib/timber-rails/config/action_view.rb +29 -0
- data/lib/timber-rails/config/active_record.rb +29 -0
- data/lib/timber-rails/config.rb +12 -0
- data/lib/timber-rails/error_event.rb +61 -0
- data/lib/timber-rails/logger.rb +15 -0
- data/lib/timber-rails/overrides/active_support_3_tagged_logging.rb +111 -0
- data/lib/timber-rails/overrides/active_support_buffered_logger.rb +22 -0
- data/lib/timber-rails/overrides/active_support_tagged_logging.rb +66 -0
- data/lib/timber-rails/overrides/lograge.rb +18 -0
- data/lib/timber-rails/overrides/rails_stdout_logging.rb +21 -0
- data/lib/timber-rails/overrides.rb +12 -0
- data/lib/timber-rails/rack_logger.rb +58 -0
- data/lib/timber-rails/railtie.rb +27 -0
- data/lib/timber-rails/session_context.rb +40 -0
- data/lib/timber-rails/version.rb +7 -0
- data/lib/timber-rails.rb +63 -0
- data/timber-rails.gemspec +71 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f4f0a765269e2b04700d9f0b5e8be9c8c5a1e2b7335ee31decc53379e0c29c6
|
4
|
+
data.tar.gz: 113255c96a2bcd218ce6d444c665a811f8e4ab47cf09cba3c2cebdc82e998084
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b053eb354944ecac2cdae780546d70b00f10ff9ce00c73d1ef9a210fbe6977fe270e6136270e80124d58ad146423ee57e5c23ddd11be177cca9a4143cbc2f725
|
7
|
+
data.tar.gz: de16848d218e687879c3af22f1ceffe1b84647da03044a7356ae26d009b118b8a308d1d5151f3efdcfb29395fc6c4a25aa82f00a51a9fee1fc102beaec80af89
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 1.9.3
|
6
|
+
- 2.2.10
|
7
|
+
- 2.3.8
|
8
|
+
- 2.4.5
|
9
|
+
- 2.5.3
|
10
|
+
- jruby-9.2.5.0
|
11
|
+
before_install: gem install bundler -v 1.17.3
|
12
|
+
gemfile:
|
13
|
+
- gemfiles/rails-3.2.gemfile
|
14
|
+
- gemfiles/rails-4.0.gemfile
|
15
|
+
- gemfiles/rails-4.1.gemfile
|
16
|
+
- gemfiles/rails-4.2.gemfile
|
17
|
+
- gemfiles/rails-5.0.gemfile
|
18
|
+
- gemfiles/rails-5.1.gemfile
|
19
|
+
- gemfiles/rails-5.2.gemfile
|
20
|
+
- gemfiles/rails-edge.gemfile
|
21
|
+
env:
|
22
|
+
global: RAILS_ENV=test
|
23
|
+
before_script:
|
24
|
+
- echo $BUNDLE_GEMFILE
|
25
|
+
- bundle install
|
26
|
+
script:
|
27
|
+
- bundle exec rspec --format documentation
|
28
|
+
matrix:
|
29
|
+
fast_finish: true
|
30
|
+
exclude:
|
31
|
+
- rvm: 1.9.3
|
32
|
+
- gemfile: gemfiles/rails-edge.gemfile
|
33
|
+
- rvm: 2.4.5
|
34
|
+
gemfile: gemfiles/rails-4.0.gemfile
|
35
|
+
- rvm: 2.4.5
|
36
|
+
gemfile: gemfiles/rails-4.1.gemfile
|
37
|
+
- rvm: 2.5.3
|
38
|
+
gemfile: gemfiles/rails-3.2.gemfile
|
39
|
+
- rvm: 2.5.3
|
40
|
+
gemfile: gemfiles/rails-4.0.gemfile
|
41
|
+
- rvm: 2.5.3
|
42
|
+
gemfile: gemfiles/rails-4.1.gemfile
|
43
|
+
include:
|
44
|
+
- rvm: 2.5.3
|
45
|
+
gemfile: gemfiles/rails-edge.gemfile
|
46
|
+
- rvm: 1.9.3
|
47
|
+
gemfile: gemfiles/rails-3.2.gemfile
|
48
|
+
allow_failures:
|
49
|
+
- rvm: 1.9.3 # bundler wont install the gems
|
50
|
+
- gemfile: gemfiles/rails-edge.gemfile
|
51
|
+
- rvm: jruby-9.2.5.0
|
52
|
+
notifications:
|
53
|
+
email: false
|
54
|
+
slack:
|
55
|
+
rooms:
|
56
|
+
secure: F4BGVLUnaDqJ3YXfuIwx+m6047E8YstCUXs33Tfcs7SUlSuOSChuXqvCfVtnfNy2muF7xgB6VRL3xpFIRm7qNStqGUWCQJXmKq2OEgq1DYGkhAVle4d/LBtVcfBgeLelsoi+1TI9MrUtpZDHPl0li3PLoC+dq7rzSuhrxQ9EOhZlZGVn6LTeVcgNw6cLNzHSWJJ8zpYWLjBWUXgJ75MQvo5qaNbQxyfzm7GzEgRNfSzabFBwpKwB1Tog9X9TKTtPrn30O9Ur9+wmTu6EnwaDWZjaTK6I+AbxE8huIfUGvSrq1aV2JaDIra6zHEQ+d4j0oRYutgFM4YfyN9124MbPE2yH/5lXNQHMpUOsP0bl2U+KGDzq/V5APyrZ6irsvwGYpo3fSXrW8nDIAK4Mh8KB+Ta0zN5H8PmIRK76wJ+wG2zAtrfl+ailxMrdpK6J04fl3pCBuO6eW+AKEJ7Wfi5GiE7a9lk/YewAeDHyyLSnUNFIP0/iFAbTtRh5denCk0ZUS1XyfZNQuFoku7jk5lpe41SNItqOO0jv/jXPF+wensNa2UgMBIP0XkRw55LKn9eY0MKm9P+zp9ePaXs0T0Ttv4e0T4Jxrgf5QBynefgHwAsOI1nHr7GhlPaFQ6u8iNmjNYLB9v1JZMlO08LkytzZFpUuJoHbYYoBaRtUtEosBHg=
|
data/Gemfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# TODO: REMOVE ME
|
4
|
+
gem 'timber', git: 'https://github.com/mitchellhenke/timber-ruby.git', branch: '3.0'
|
5
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in timber-ruby-rails.gemspec
|
8
|
+
gemspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# License
|
2
|
+
|
3
|
+
Copyright (c) 2019, Timber Technologies, Inc.
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
6
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
7
|
+
and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
11
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
13
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
14
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
15
|
+
THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# 🌲 Timber Integration For Rails
|
2
|
+
|
3
|
+
[![ISC License](https://img.shields.io/badge/license-ISC-ff69b4.svg)](LICENSE.md)
|
4
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/timberio/timber-ruby-rails)
|
5
|
+
[![Build Status](https://travis-ci.org/timberio/timber-ruby-rails.svg?branch=master)](https://travis-ci.org/timberio/timber-ruby-rails)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/timberio/timber-ruby-rails/badges/gpa.svg)](https://codeclimate.com/github/timberio/timber-ruby-rails)
|
7
|
+
|
8
|
+
This library integrates the [`timber` Ruby library][timber_ruby] with the [Rails][rails] framework,
|
9
|
+
turning your Rails logs into rich structured events.
|
10
|
+
|
11
|
+
* **Sign-up: [https://app.timber.io](https://app.timber.io)**
|
12
|
+
* **Documentation: [https://docs.timber.io/setup/languages/ruby/integrations/rails](https://docs.timber.io/setup/languages/ruby/integrations/rails)**
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "timber-rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.0.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
gemspec :path => '../'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.1.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
gemspec :path => '../'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.2.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 4.0.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 4.1.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 4.2.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 5.0.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 5.1.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 5.2.0'
|
4
|
+
# TODO: REMOVE ME
|
5
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
6
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
7
|
+
|
8
|
+
if RUBY_PLATFORM == "java"
|
9
|
+
gem 'mime-types', '2.6.2'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec :path => '../'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rack', git: 'https://github.com/rack/rack', branch: 'master'
|
4
|
+
gem 'arel', git: 'https://github.com/rails/arel', branch: 'master'
|
5
|
+
gem 'rails', git: 'https://github.com/rails/rails', branch: 'master'
|
6
|
+
|
7
|
+
# TODO: REMOVE ME
|
8
|
+
gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
|
9
|
+
gem 'timber-rack', git: 'https://github.com/timberio/timber-ruby-rack.git', branch: 'master'
|
10
|
+
|
11
|
+
gemspec :path => '../'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Timber
|
2
|
+
module Integrations
|
3
|
+
module ActionController
|
4
|
+
class LogSubscriber < Integrator
|
5
|
+
# The log subscriber that replaces the default `ActionController::LogSubscriber`.
|
6
|
+
# The intent of this subscriber is to, as transparently as possible, properly
|
7
|
+
# track events that are being logged here. This LogSubscriber will never change
|
8
|
+
# default behavior / log messages.
|
9
|
+
#
|
10
|
+
# @private
|
11
|
+
class TimberLogSubscriber < ::ActionController::LogSubscriber
|
12
|
+
def start_processing(event)
|
13
|
+
return true if silence?
|
14
|
+
|
15
|
+
info do
|
16
|
+
payload = event.payload
|
17
|
+
params = payload[:params].except(*INTERNAL_PARAMS)
|
18
|
+
format = extract_format(payload)
|
19
|
+
format = format.to_s.upcase if format.is_a?(Symbol)
|
20
|
+
|
21
|
+
Events::ControllerCall.new(
|
22
|
+
controller: payload[:controller],
|
23
|
+
action: payload[:action],
|
24
|
+
format: format,
|
25
|
+
params: params
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def extract_format(payload)
|
32
|
+
if payload.key?(:format)
|
33
|
+
payload[:format] # rails > 4.X
|
34
|
+
elsif payload.key?(:formats)
|
35
|
+
payload[:formats].first # rails 3.X
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def silence?
|
40
|
+
ActionController.silence?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Timber
|
2
|
+
module Integrations
|
3
|
+
module ActionController
|
4
|
+
# Responsible for removing the default ActionController::LogSubscriber and installing
|
5
|
+
# the TimberLogSubscriber
|
6
|
+
#
|
7
|
+
# @private
|
8
|
+
class LogSubscriber < Integrator
|
9
|
+
def initialize
|
10
|
+
require "action_controller/log_subscriber"
|
11
|
+
require "timber-rails/action_controller/log_subscriber/timber_log_subscriber"
|
12
|
+
rescue LoadError => e
|
13
|
+
raise RequirementNotMetError.new(e.message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def integrate!
|
17
|
+
return true if Util::ActiveSupportLogSubscriber.subscribed?(:action_controller, TimberLogSubscriber)
|
18
|
+
|
19
|
+
Util::ActiveSupportLogSubscriber.unsubscribe!(:action_controller, ::ActionController::LogSubscriber)
|
20
|
+
TimberLogSubscriber.attach_to(:action_controller)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "timber-rails/action_controller/log_subscriber"
|
2
|
+
|
3
|
+
module Timber
|
4
|
+
module Integrations
|
5
|
+
# Module for holding *all* ActionController integrations. See {Integration} for
|
6
|
+
# configuration details for all integrations.
|
7
|
+
module ActionController
|
8
|
+
extend Integration
|
9
|
+
|
10
|
+
def self.integrate!
|
11
|
+
return false if !enabled?
|
12
|
+
|
13
|
+
LogSubscriber.integrate!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Timber
|
2
|
+
module Integrations
|
3
|
+
module ActionDispatch
|
4
|
+
# Reponsible for disabled logging in the ActionDispatch::DebugExceptions
|
5
|
+
# Rack middleware. We cannot simply remove the middleware because it is
|
6
|
+
# coupled with displaying an exception debug screen if debug exceptions is enabled.
|
7
|
+
#
|
8
|
+
# @private
|
9
|
+
class DebugExceptions < Integrator
|
10
|
+
|
11
|
+
# Patch for disabling logging
|
12
|
+
#
|
13
|
+
# @private
|
14
|
+
module InstanceMethods
|
15
|
+
def self.included(klass)
|
16
|
+
klass.class_eval do
|
17
|
+
private
|
18
|
+
def logger(*args)
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
begin
|
27
|
+
# Rails >= 3.1
|
28
|
+
require "action_dispatch/middleware/debug_exceptions"
|
29
|
+
rescue LoadError
|
30
|
+
# Rails < 3.1
|
31
|
+
require "action_dispatch/middleware/show_exceptions"
|
32
|
+
end
|
33
|
+
rescue LoadError => e
|
34
|
+
raise RequirementNotMetError.new(e.message)
|
35
|
+
end
|
36
|
+
|
37
|
+
def integrate!
|
38
|
+
if defined?(::ActionDispatch::DebugExceptions) && !::ActionDispatch::DebugExceptions.include?(InstanceMethods)
|
39
|
+
::ActionDispatch::DebugExceptions.send(:include, InstanceMethods)
|
40
|
+
end
|
41
|
+
|
42
|
+
if defined?(::ActionDispatch::ShowExceptions) && !::ActionDispatch::ShowExceptions.include?(InstanceMethods)
|
43
|
+
::ActionDispatch::ShowExceptions.send(:include, InstanceMethods)
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "timber-rails/action_dispatch/debug_exceptions"
|
2
|
+
|
3
|
+
module Timber
|
4
|
+
module Integrations
|
5
|
+
# Module for holding *all* ActionDispatch integrations. This
|
6
|
+
# module simply disables the exception tracking middleware so that our middleware
|
7
|
+
# works as expected.
|
8
|
+
module ActionDispatch
|
9
|
+
def self.enabled?
|
10
|
+
Rails::ErrorEvent.enabled?
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.integrate!
|
14
|
+
return false if !enabled?
|
15
|
+
|
16
|
+
DebugExceptions.integrate!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Timber
|
2
|
+
module Integrations
|
3
|
+
module ActionView
|
4
|
+
class LogSubscriber < Integrator
|
5
|
+
|
6
|
+
# The log subscriber that replaces the default `ActionView::LogSubscriber`.
|
7
|
+
# The intent of this subscriber is to, as transparently as possible, properly
|
8
|
+
# track events that are being logged here.
|
9
|
+
#
|
10
|
+
# @private
|
11
|
+
class TimberLogSubscriber < ::ActionView::LogSubscriber
|
12
|
+
def render_template(event)
|
13
|
+
return true if silence?
|
14
|
+
|
15
|
+
info do
|
16
|
+
full_name = from_rails_root(event.payload[:identifier])
|
17
|
+
message = " Rendered #{full_name}"
|
18
|
+
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
19
|
+
message << " (#{event.duration.round(1)}ms)"
|
20
|
+
|
21
|
+
Events::TemplateRender.new(
|
22
|
+
name: full_name,
|
23
|
+
duration_ms: event.duration,
|
24
|
+
message: message
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_partial(event)
|
30
|
+
return true if silence?
|
31
|
+
|
32
|
+
info do
|
33
|
+
full_name = from_rails_root(event.payload[:identifier])
|
34
|
+
message = " Rendered #{full_name}"
|
35
|
+
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
36
|
+
message << " (#{event.duration.round(1)}ms)"
|
37
|
+
message << " #{cache_message(event.payload)}" if event.payload.key?(:cache_hit)
|
38
|
+
|
39
|
+
Events::TemplateRender.new(
|
40
|
+
name: full_name,
|
41
|
+
duration_ms: event.duration,
|
42
|
+
message: message
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def render_collection(event)
|
48
|
+
return true if silence?
|
49
|
+
|
50
|
+
if respond_to?(:render_count, true)
|
51
|
+
info do
|
52
|
+
identifier = event.payload[:identifier] || "templates"
|
53
|
+
full_name = from_rails_root(identifier)
|
54
|
+
message = " Rendered collection of #{full_name}" \
|
55
|
+
" #{render_count(event.payload)} (#{event.duration.round(1)}ms)"
|
56
|
+
|
57
|
+
Events::TemplateRender.new(
|
58
|
+
name: full_name,
|
59
|
+
duration_ms: event.duration,
|
60
|
+
message: message
|
61
|
+
)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
# Older versions of rails delegate this method to #render_template
|
65
|
+
render_template(event)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def log_rendering_start(payload)
|
71
|
+
# Consolidates 2 template rendering events into 1. We don't need 2 events for
|
72
|
+
# rendering a template. If you disagree, please feel free to open a PR and we
|
73
|
+
# can make this an option.
|
74
|
+
end
|
75
|
+
|
76
|
+
def silence?
|
77
|
+
ActionView.silence?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Timber
|
2
|
+
module Integrations
|
3
|
+
module ActionView
|
4
|
+
# Reponsible for uninstalling the default `ActionView::LogSubscriber` and installing
|
5
|
+
# the TimberLogSubscriber.
|
6
|
+
#
|
7
|
+
# @private
|
8
|
+
class LogSubscriber < Integrator
|
9
|
+
def initialize
|
10
|
+
require "action_view/log_subscriber"
|
11
|
+
require "timber-rails/action_view/log_subscriber/timber_log_subscriber"
|
12
|
+
rescue LoadError => e
|
13
|
+
raise RequirementNotMetError.new(e.message)
|
14
|
+
end
|
15
|
+
|
16
|
+
def integrate!
|
17
|
+
return true if Util::ActiveSupportLogSubscriber.subscribed?(:action_view, TimberLogSubscriber)
|
18
|
+
|
19
|
+
Util::ActiveSupportLogSubscriber.unsubscribe!(:action_view, ::ActionView::LogSubscriber)
|
20
|
+
TimberLogSubscriber.attach_to(:action_view)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "timber-rails/action_view/log_subscriber"
|
2
|
+
|
3
|
+
module Timber
|
4
|
+
module Integrations
|
5
|
+
# Module for holding *all* ActionView integrations. See {Integration} for
|
6
|
+
# configuration details for all integrations.
|
7
|
+
module ActionView
|
8
|
+
extend Integration
|
9
|
+
|
10
|
+
def self.integrate!
|
11
|
+
return false if !enabled?
|
12
|
+
|
13
|
+
LogSubscriber.integrate!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# We require all of ActiveRecord because the #logger method in ::ActiveRecord::LogSubscriber
|
2
|
+
# uses ActiveRecord::Base. We can't require active_record/base directly because ActiveRecord
|
3
|
+
# does not require files properly and we receive unintialized constant errors.
|
4
|
+
require "active_record"
|
5
|
+
require "active_record/log_subscriber"
|
6
|
+
|
7
|
+
module Timber
|
8
|
+
module Integrations
|
9
|
+
module ActiveRecord
|
10
|
+
class LogSubscriber < Integrator
|
11
|
+
# The log subscriber that replaces the default `ActiveRecord::LogSubscriber`.
|
12
|
+
# The intent of this subscriber is to, as transparently as possible, properly
|
13
|
+
# track events that are being logged here. This LogSubscriber will never change
|
14
|
+
# default behavior / log messages.
|
15
|
+
#
|
16
|
+
# @private
|
17
|
+
class TimberLogSubscriber < ::ActiveRecord::LogSubscriber
|
18
|
+
def sql(event)
|
19
|
+
return true if silence?
|
20
|
+
|
21
|
+
r = super(event)
|
22
|
+
|
23
|
+
if @message
|
24
|
+
payload = event.payload
|
25
|
+
|
26
|
+
sql_event = Events::SQLQuery.new(
|
27
|
+
sql: payload[:sql],
|
28
|
+
duration_ms: event.duration,
|
29
|
+
message: @message,
|
30
|
+
)
|
31
|
+
|
32
|
+
logger.debug sql_event
|
33
|
+
|
34
|
+
@message = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
r
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def debug(message)
|
42
|
+
@message = message
|
43
|
+
end
|
44
|
+
|
45
|
+
def silence?
|
46
|
+
ActiveRecord.silence?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "timber-rails/active_record/log_subscriber/timber_log_subscriber"
|
2
|
+
|
3
|
+
module Timber
|
4
|
+
module Integrations
|
5
|
+
module ActiveRecord
|
6
|
+
# Reponsible for uninstalling the default `ActiveRecord::LogSubscriber` and replacing it
|
7
|
+
# with the `TimberLogSubscriber`.
|
8
|
+
#
|
9
|
+
# @private
|
10
|
+
class LogSubscriber < Integrator
|
11
|
+
def integrate!
|
12
|
+
return true if Util::ActiveSupportLogSubscriber.subscribed?(:active_record, TimberLogSubscriber)
|
13
|
+
|
14
|
+
Util::ActiveSupportLogSubscriber.unsubscribe!(:active_record, ::ActiveRecord::LogSubscriber)
|
15
|
+
TimberLogSubscriber.attach_to(:active_record)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "timber-rails/active_record/log_subscriber"
|
2
|
+
|
3
|
+
module Timber
|
4
|
+
module Integrations
|
5
|
+
# Module for holding *all* ActiveRecord integrations. See {Integration} for
|
6
|
+
# configuration details for all integrations.
|
7
|
+
module ActiveRecord
|
8
|
+
extend Integration
|
9
|
+
|
10
|
+
def self.integrate!
|
11
|
+
return false if !enabled?
|
12
|
+
|
13
|
+
LogSubscriber.integrate!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|