exception-track 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecd9495c4a02dfa2be9d6afe4e3b416262529666
4
+ data.tar.gz: bca5b7008c476e70806a19a875a05ece945c29da
5
+ SHA512:
6
+ metadata.gz: c1158b0ade22de97f3d1dc6042b557cf1d52d18547ff3b4329e84593b0face93d2d4d3c8138520b30b80c4243d035226633c818fd2c5871cc227d9863ddd637a
7
+ data.tar.gz: e079a9e5db30f3c9a9fcc070ac25597c01d25052c1780fc53fbebbd821ea2fd58a4c0c50a0c798165d5fdfd72997099a810d15282442badfe50da0115d939eba
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Jason Lee
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ ExceptionTrack
2
+ --------------
3
+
4
+ Tracking exceptions for Rails application store them in database.
5
+
6
+ This gem is base on [exception_notification](https://github.com/smartinez87/exception_notification/).
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/exception-track.svg)](https://badge.fury.io/rb/exception-track) [![Build Status](https://travis-ci.org/rails-engine/exception-track.svg)](https://travis-ci.org/rails-engine/exception-track) [![Code Climate](https://codeclimate.com/github/rails-engine/exception-track/badges/gpa.svg)](https://codeclimate.com/github/rails-engine/exception-track) [![codecov.io](https://codecov.io/github/rails-engine/exception-track/coverage.svg?branch=master)](https://codecov.io/github/rails-engine/exception-track?branch=master) [![](http://inch-ci.org/github/rails-engine/exception-track.svg?branch=master)](http://inch-ci.org/github/rails-engine/exception-track?branch=master)
9
+
10
+ ![2017-02-17 12 35 18](https://cloud.githubusercontent.com/assets/5518/23052599/8e267c02-f50d-11e6-8d6e-cef0cc1991b7.png)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'exception-track'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```bash
23
+ $ bundle
24
+ ```
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/exception-track.js
2
+ //= link_directory ../stylesheets/exception-track.css
@@ -0,0 +1,170 @@
1
+
2
+ body {
3
+ margin: 0;
4
+ padding: 20px 0;
5
+ background-color: #eee;
6
+ }
7
+
8
+ body, textarea {
9
+ font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
10
+ font-size: 14px;
11
+ line-height: 1.4;
12
+ color: #333;
13
+ }
14
+
15
+ .footer {
16
+ padding: 15px;
17
+ text-align: center;
18
+ color: #999;
19
+ }
20
+ .footer a:link,
21
+ .footer a:visited { color: #666; text-decoration: underline;}
22
+
23
+ a, a:visited, a:active {
24
+ color: #364cc9;
25
+ text-decoration: none;
26
+ }
27
+
28
+ a:hover {
29
+ text-decoration: underline;
30
+ }
31
+
32
+ table {
33
+ width: 100%;
34
+ border-collapse: collapse;
35
+ border-spacing: 0;
36
+ margin-bottom: 20px;
37
+ }
38
+
39
+ th {
40
+ text-align: left;
41
+ border-bottom: solid 1px #ddd;
42
+ }
43
+
44
+ td.date { width: 150px; font-size: 12px; }
45
+
46
+ h1 {
47
+ margin-top: 0;
48
+ font-size: 20px;
49
+ font-weight: bold;
50
+ }
51
+
52
+ h1, p {
53
+ margin-bottom: 20px;
54
+ }
55
+
56
+ h3 {
57
+ text-align: center;
58
+ }
59
+
60
+ ul {
61
+ list-style-type: none;
62
+ padding: 0;
63
+ margin: 0;
64
+ }
65
+
66
+ table td, table th {
67
+ padding: 10px 15px;
68
+ }
69
+ th { background: #f5f5f5; border-bottom: 1px solid #eee; }
70
+ td {
71
+ border-top: solid 1px #ddd;
72
+ }
73
+
74
+ pre {
75
+ background-color: #eee;
76
+ padding: 10px;
77
+ white-space: pre-wrap;
78
+ word-break: break-word;
79
+ }
80
+
81
+ textarea {
82
+ width: 100%;
83
+ height: 100px;
84
+ border: solid 1px #ddd;
85
+ padding: 10px;
86
+ }
87
+
88
+ hr {
89
+ border: none;
90
+ height: 0;
91
+ border-top: solid 1px #ddd;
92
+ margin-bottom: 15px;
93
+ }
94
+
95
+ .btn {
96
+ display: inline-block;
97
+ margin-bottom: 0;
98
+ font-size: 14px;
99
+ font-weight: 400;
100
+ line-height: 1.42857143;
101
+ text-align: center;
102
+ white-space: nowrap;
103
+ vertical-align: middle;
104
+ cursor: pointer;
105
+ -webkit-user-select: none;
106
+ -moz-user-select: none;
107
+ -ms-user-select: none;
108
+ user-select: none;
109
+ border-radius: 3px;
110
+ border: 1px solid #ccc;
111
+ padding: 8px 18px;
112
+ outline: 0 !important;
113
+ background: #FFF;
114
+ }
115
+ .btn:hover { text-decoration: none; }
116
+ .btn-danger { background: #E25517; color: #fff; border: #D44323;}
117
+
118
+ .container {
119
+ max-width: 1000px;
120
+ margin-left: auto;
121
+ margin-right: auto;
122
+ padding: 20px;
123
+ background-color: #fff;
124
+ }
125
+
126
+ .no-record {
127
+ padding: 50px;
128
+ text-align: center;
129
+ font-size: 16px;
130
+ }
131
+
132
+ .toolbar {
133
+ margin-bottom: 15px;
134
+ height: 34px;
135
+ line-height: 34px;
136
+ }
137
+ .toolbar .pull-right { float: right; }
138
+
139
+ #notice {
140
+ padding: 8px 15px;
141
+ background: #3CBD46;
142
+ color: #fff;
143
+ margin-bottom: 15px;
144
+ border-radius: 3px;
145
+ }
146
+
147
+ pre {
148
+ background: #f9f9f9;
149
+ padding: 10px;
150
+ border: 1px solid #eee;
151
+ font-size: 12px;
152
+ font-family: Menlo, Monaco, Consolas, monospace;
153
+ }
154
+
155
+ h1 { font-size: 16px; }
156
+
157
+ .pagination {
158
+ padding-bottom: 15px;
159
+ font-size: 14px;
160
+ }
161
+ .pagination a {
162
+ padding: 5px 10px;
163
+ border: 1px solid #eee;
164
+ }
165
+ .pagination em {
166
+ padding: 5px 10px;
167
+ border: 1px solid #f0f0f0;
168
+ background: #f0f0f0;
169
+ font-style: normal;
170
+ }
@@ -0,0 +1,27 @@
1
+ module ExceptionTrack
2
+ class LogsController < ActionController::Base
3
+ layout 'exception-track/application'
4
+ before_action :set_log, only: [:show, :destroy]
5
+
6
+ # GET /exception_logs
7
+ def index
8
+ @logs = Log.order('id desc').paginate(page: params[:page], per_page: 10)
9
+ end
10
+
11
+ # GET /exception_logs/1
12
+ def show
13
+ end
14
+
15
+ # DELETE /exception_logs/all
16
+ def all
17
+ Log.delete_all
18
+ redirect_to logs_url, notice: 'Logs was successfully destroyed.'
19
+ end
20
+
21
+ private
22
+ # Use callbacks to share common setup or constraints between actions.
23
+ def set_log
24
+ @log = Log.find(params[:id])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module ExceptionTrack
2
+ class Log < ActiveRecord::Base
3
+ self.table_name = 'exception_tracks'
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ <script type="text/javascript">
2
+ function confirmDestroyAll() {
3
+ if (!confirm('This will destroy all Exception logs, are you sure?')) {
4
+ return false;
5
+ }
6
+ }
7
+ </script>
8
+ <div class="toolbar">
9
+ <%= @logs.total_entries %> exceptions
10
+
11
+ <div class="pull-right">
12
+ <%= form_tag(all_logs_path, method: 'delete') do %>
13
+ <button type="submit" class="btn btn-danger" onclick="return confirmDestroyAll()">Delete All</button>
14
+ <% end %>
15
+ </div>
16
+ </div>
17
+
18
+ <% if @logs.blank? %>
19
+ <div class="no-record">Good! This have no Exception logs.</div>
20
+ <% else %>
21
+ <%= will_paginate @logs %>
22
+
23
+ <table class="table table-borded tabl">
24
+ <thead>
25
+ <tr>
26
+ <th>#</th>
27
+ <th>Summary</th>
28
+ <th class="date"></th>
29
+ </tr>
30
+ </thead>
31
+
32
+ <tbody>
33
+ <% @logs.each do |log| %>
34
+ <tr>
35
+ <td><%= log.id %></td>
36
+ <td><%= link_to log.title, log %></td>
37
+ <td class="date"><%= log.created_at.to_s %></td>
38
+ </tr>
39
+ <% end %>
40
+ </tbody>
41
+ </table>
42
+
43
+ <%= will_paginate @logs %>
44
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <div class="toolbar">
2
+ <%= link_to 'Back', logs_path, class: 'btn' %>
3
+ </div>
4
+
5
+ <h1><%= @log.title %></h1>
6
+
7
+ <pre class="exception-log"><%= @log.body %></pre>
8
+
9
+
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Exception track</title>
5
+ <%= stylesheet_link_tag "exception-track/application", media: "all" %>
6
+ <%= csrf_meta_tags %>
7
+ </head>
8
+ <body>
9
+
10
+ <div class="container">
11
+ <% if notice %>
12
+ <div id="notice"><%= notice %></div>
13
+ <% end %>
14
+
15
+ <%= yield %>
16
+ </div>
17
+
18
+ <div class="footer">
19
+ <a href="https://github.com/rails-engine/exception-track">ExceptionTrack</a> powered.
20
+ </div>
21
+
22
+ </body>
23
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ ExceptionTrack::Engine.routes.draw do
2
+ resources :logs, path: '' do
3
+ collection do
4
+ delete :all
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ class CreateExceptionTrackLogs < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :exception_tracks do |t|
4
+ t.string :title
5
+ t.longtext :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ require 'exception-track/version'
2
+ require 'exception-track/configuration'
3
+ require 'exception-track/engine'
4
+
5
+ require 'exception_notification'
6
+ require 'exception_notification/rails'
7
+ require 'exception_notifier/exception_track_notifier'
8
+
9
+ require 'will_paginate'
10
+ require 'will_paginate/active_record'
11
+
12
+ module ExceptionTrack
13
+ class << self
14
+ def config
15
+ return @config if defined?(@config)
16
+ @config = Configuration.new
17
+ @config.environments = %i(development test production)
18
+ @config
19
+ end
20
+
21
+ def configure(&block)
22
+ config.instance_exec(&block)
23
+ end
24
+ end
25
+ end
26
+
27
+ ExceptionNotification.configure do |config|
28
+ config.add_notifier :exception_track, {}
29
+ end
@@ -0,0 +1,12 @@
1
+ module ExceptionTrack
2
+ class Configuration
3
+ # environments for store Exception log in to database.
4
+ # default: [:development, :test, :production]
5
+ attr_accessor :environments
6
+
7
+ def enabled_env?(env)
8
+ return false if env.blank?
9
+ environments.include?(env.to_sym)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module ExceptionTrack
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ExceptionTrack
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ExceptionTrack
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,41 @@
1
+ # 异常通知
2
+ module ExceptionNotifier
3
+ class ExceptionTrackNotifier
4
+ def initialize(_options)
5
+ end
6
+
7
+ def call(exception, _options = {})
8
+ # send the notification
9
+ @title = exception.message
10
+ messages = []
11
+ messages << exception.inspect
12
+ messages << "\n"
13
+ messages << "--------------------------------------------------"
14
+ messages << headers_for_env(_options[:env])
15
+ messages << "--------------------------------------------------"
16
+ unless exception.backtrace.blank?
17
+ messages << "\n"
18
+ messages << exception.backtrace
19
+ end
20
+
21
+ if ExceptionTrack.config.enabled_env?(Rails.env)
22
+ ExceptionTrack::Log.create(title: @title, body: messages.join("\n"))
23
+ end
24
+ end
25
+
26
+ # Log Request headers from Rack env
27
+ def headers_for_env(env)
28
+ return '' if env.blank?
29
+
30
+ headers = []
31
+ headers << "Method: #{env['REQUEST_METHOD']}"
32
+ headers << "URL: #{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}"
33
+ headers << "User-Agent: #{env['HTTP_USER_AGENT']}"
34
+ headers << "Language: #{env['HTTP_ACCEPT_LANGUAGE']}"
35
+ headers << "Server: #{Socket.gethostname}"
36
+ headers << "Process: #{$$}"
37
+
38
+ headers.join("\n")
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception-track
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: exception_notification
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.1'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: will_paginate
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: mysql2
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Tracking exceptions for Rails application store them in database by exception_notification
76
+ gem.
77
+ email:
78
+ - huacnlee@gmail.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - MIT-LICENSE
84
+ - README.md
85
+ - app/assets/config/exception_track_manifest.js
86
+ - app/assets/stylesheets/exception-track/application.css
87
+ - app/controllers/exception_track/logs_controller.rb
88
+ - app/models/exception_track/log.rb
89
+ - app/views/exception_track/logs/index.html.erb
90
+ - app/views/exception_track/logs/show.html.erb
91
+ - app/views/layouts/exception-track/application.html.erb
92
+ - config/routes.rb
93
+ - db/migrate/20170217023900_create_exception_track_logs.rb
94
+ - lib/exception-track.rb
95
+ - lib/exception-track/configuration.rb
96
+ - lib/exception-track/engine.rb
97
+ - lib/exception-track/version.rb
98
+ - lib/exception_notifier/exception_track_notifier.rb
99
+ homepage: https://github.com/rails-engine/exception-track
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.6.8
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Tracking exceptions for Rails application store them in database.
123
+ test_files: []