exception-track 0.6.2 → 1.0.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: b096b42d1e359c95d02180e76597932827bf0552887c98c30ab4c5655c014d86
4
- data.tar.gz: 47f461e204a87e35cf4c0bad912fa2b99e38662ff12678e21f3faa9ffd0bd13c
3
+ metadata.gz: 2b4beb51819395e0c6b21ef49abb59bc7095781ce085e0926e7c63f5b6d2e117
4
+ data.tar.gz: 50f9c9af65bbab093ca3ed4e50b1a3d4ae6ad5768672ec11d4fce68a3a5c2cc1
5
5
  SHA512:
6
- metadata.gz: ecd0dfa7ebc4a8ec10622ee01f3109f140b6174288fb23cc90cca5f8f1539e0c7cf40a4340211486e3cafd5f41da32201144c969abf0e1f5d14bd35df33af1bc
7
- data.tar.gz: ee57578ba6af00e75eb92200434de9d4c3bdd96f49f68ba3bca44221c14831f771757059217c4bd0a8dd3bb9210b9ddf32e197be3389c5392ee2a11a571a6017
6
+ metadata.gz: 46741761f713ee98cb71ea661d10048131e67b0e309f402cbfa1921e7780a52225c58e9f3ec082500360514aecc32982a2c33066d2949f9e2466be02bedc58f3
7
+ data.tar.gz: f2c71737f37cf474633477bbf00ce601875d68c4b6040be260e857f264818d247707c1f2b4ab38f29fe58e963a4a5604bcce0ee66a7f940ecc0209b3eec4d6b9
@@ -12,7 +12,7 @@ module ExceptionTrack
12
12
 
13
13
  def export
14
14
  @logs = Log.order("id desc").where("created_at >= ?", 3.months.ago)
15
- send_data JSON.pretty_generate(@logs.as_json(only: [:title, :body, :created_at, :updated_at])), filename: "#{Date.current}.json", disposition: "attachment"
15
+ send_data JSON.pretty_generate(@logs.as_json(only: %i[title body created_at updated_at])), filename: "#{Date.current}.json", disposition: "attachment"
16
16
  end
17
17
 
18
18
  # GET /exception_logs/1
@@ -25,7 +25,6 @@ module ExceptionTrack
25
25
  end
26
26
 
27
27
  private
28
-
29
28
  # Use callbacks to share common setup or constraints between actions.
30
29
  def set_log
31
30
  @log = Log.find(params[:id])
@@ -9,10 +9,15 @@ ExceptionTrack.configure do
9
9
  end
10
10
 
11
11
  # ExceptionNotification.configure do |config|
12
- # config.ignored_exceptions += %w(ActionView::TemplateError
13
- # ActionController::InvalidAuthenticityToken
14
- # ActionController::BadRequest
15
- # ActionView::MissingTemplate
16
- # ActionController::UrlGenerationError
17
- # ActionController::UnknownFormat)
12
+ # config.ignored_exceptions += %w[
13
+ # ActionView::TemplateError
14
+ # ActionController::InvalidAuthenticityToken
15
+ # ActionController::BadRequest
16
+ # ActionView::MissingTemplate
17
+ # ActionController::UrlGenerationError
18
+ # ActionController::UnknownFormat
19
+ # ActionController::InvalidCrossOriginRequest
20
+ # ActionController::ParameterMissing
21
+ # Mime::Type::InvalidMimeType
22
+ # ]
18
23
  # end
@@ -4,7 +4,7 @@ class CreateExceptionTrackLogs < ActiveRecord::Migration[5.0]
4
4
  def change
5
5
  create_table :exception_tracks do |t|
6
6
  t.string :title
7
- t.text :body, limit: 16777215
7
+ t.text :body, limit: 16_777_215
8
8
 
9
9
  t.timestamps
10
10
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "exception-track/version"
4
4
  require "exception-track/configuration"
5
+ require "exception-track/log_subscriber"
5
6
  require "exception-track/engine"
6
7
 
7
8
  require "exception_notification"
@@ -14,6 +15,7 @@ module ExceptionTrack
14
15
  class << self
15
16
  def config
16
17
  return @config if defined?(@config)
18
+
17
19
  @config = Configuration.new
18
20
  @config.environments = %i[development production]
19
21
  @config
@@ -8,6 +8,7 @@ module ExceptionTrack
8
8
 
9
9
  def enabled_env?(env)
10
10
  return false if env.blank?
11
+
11
12
  environments.include?(env.to_sym)
12
13
  end
13
14
  end
@@ -5,7 +5,9 @@ module ExceptionTrack
5
5
  isolate_namespace ExceptionTrack
6
6
 
7
7
  initializer "exception-track.assets.precompile", group: :all do |app|
8
- app.config.assets.precompile += %w( exception-track/application.css )
8
+ app.config.assets.precompile += %w[exception-track/application.css]
9
9
  end
10
+
11
+ ExceptionTrack::LogSubscriber.attach_to :exception_track
10
12
  end
11
13
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExceptionTrack
4
+ class LogSubscriber < ActiveSupport::LogSubscriber
5
+ # ActiveSupport::Notifications.instrument('track.exception_track', action: action)
6
+ def track(event)
7
+ prefix = color("ExceptionTrack", CYAN)
8
+ title = color(event.payload[:title], RED)
9
+ debug " #{prefix} track db (#{event.duration.round(1)}ms)"
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionTrack
4
- VERSION = "0.6.2"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -2,27 +2,31 @@
2
2
 
3
3
  module ExceptionNotifier
4
4
  class ExceptionTrackNotifier < ExceptionNotifier::BaseNotifier
5
- def initialize(_options); end
5
+ def initialize(_opts); end
6
6
 
7
- def call(exception, _options = {})
7
+ def call(exception, opts = {})
8
8
  return unless ExceptionTrack.config.enabled_env?(Rails.env)
9
9
 
10
10
  # send the notification
11
11
  title = exception.message || "None"
12
-
13
12
  messages = []
14
- messages << headers_for_env(_options[:env])
15
- messages << ""
16
- messages << "--------------------------------------------------"
17
- messages << ""
18
- messages << exception.inspect
19
- unless exception.backtrace.blank?
20
- messages << "\n"
21
- messages << exception.backtrace
22
- end
23
13
 
24
- ExceptionTrack::Log.create(title: title[0, 200], body: messages.join("\n"))
25
- rescue => e
14
+ ActiveSupport::Notifications.instrument("track.exception_track", title: title) do
15
+ messages << headers_for_env(opts[:env])
16
+ messages << ""
17
+ messages << "--------------------------------------------------"
18
+ messages << ""
19
+ messages << exception.inspect
20
+ unless exception.backtrace.blank?
21
+ messages << "\n"
22
+ messages << exception.backtrace
23
+ end
24
+
25
+ Rails.logger.silence do
26
+ ExceptionTrack::Log.create(title: title[0, 200], body: messages.join("\n"))
27
+ end
28
+ end
29
+ rescue StandardError => e
26
30
  errs = []
27
31
  errs << "-- [ExceptionTrack] create error ---------------------------"
28
32
  errs << e.message.indent(2)
@@ -43,9 +47,7 @@ module ExceptionNotifier
43
47
  headers = []
44
48
  headers << "Method: #{env['REQUEST_METHOD']}"
45
49
  headers << "URL: #{env['REQUEST_URI']}"
46
- if env['REQUEST_METHOD'].downcase != "get"
47
- headers << "Parameters:\n#{pretty_hash(parameters.except(:controller, :action), 13)}"
48
- end
50
+ headers << "Parameters:\n#{pretty_hash(parameters.except(:controller, :action), 13)}" if env["REQUEST_METHOD"].downcase != "get"
49
51
  headers << "Controller: #{parameters['controller']}##{parameters['action']}"
50
52
  headers << "RequestId: #{env['action_dispatch.request_id']}"
51
53
  headers << "User-Agent: #{env['HTTP_USER_AGENT']}"
@@ -60,10 +62,10 @@ module ExceptionNotifier
60
62
  def filter_parameters(env)
61
63
  parameters = env["action_dispatch.request.parameters"] || {}
62
64
  parameter_filter = ActiveSupport::ParameterFilter.new(env["action_dispatch.parameter_filter"] || [])
63
- return parameter_filter.filter(parameters)
64
- rescue => e
65
+ parameter_filter.filter(parameters)
66
+ rescue StandardError => e
65
67
  Rails.logger.error "filter_parameters error: #{e.inspect}"
66
- return parameters
68
+ parameters
67
69
  end
68
70
 
69
71
  def pretty_hash(params, indent = 0)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception-track
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exception_notification
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - MIT-LICENSE
78
78
  - README.md
79
+ - app/assets/config/exception_track_manifest.js
79
80
  - app/assets/stylesheets/exception-track/application.css
80
81
  - app/controllers/exception_track/logs_controller.rb
81
82
  - app/models/exception_track/log.rb
@@ -88,6 +89,7 @@ files:
88
89
  - lib/exception-track.rb
89
90
  - lib/exception-track/configuration.rb
90
91
  - lib/exception-track/engine.rb
92
+ - lib/exception-track/log_subscriber.rb
91
93
  - lib/exception-track/version.rb
92
94
  - lib/exception_notifier/exception_track_notifier.rb
93
95
  - lib/generators/exception_track/install_generator.rb