forked from e621ng/e621ng
Add some cheap exception logging until something better is made
This commit is contained in:
parent
f2c408d3eb
commit
4fb3c9fedb
13
app/controllers/admin/exceptions_controller.rb
Normal file
13
app/controllers/admin/exceptions_controller.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module Admin
|
||||
class ExceptionsController < ApplicationController
|
||||
before_action :admin_only
|
||||
|
||||
def index
|
||||
@exception_logs = ExceptionLog.paginate(params[:page], limit: 100)
|
||||
end
|
||||
|
||||
def show
|
||||
@exception_log = ExceptionLog.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
@ -88,6 +88,14 @@ class ApplicationController < ActionController::Base
|
||||
puts "---"
|
||||
end
|
||||
|
||||
ExceptionLog.add(exception, CurrentUser.ip_addr, {
|
||||
host: Socket.gethostname,
|
||||
params: params,
|
||||
user_id: CurrentUser.id,
|
||||
referrer: request.referrer,
|
||||
user_agent: request.user_agent
|
||||
})
|
||||
|
||||
if Rails.env.development?
|
||||
Rails.logger.error("<<< \n #{exception.class} exception thrown: #{exception.message}\n#{exception.backtrace.join("\n")}\n<<<")
|
||||
end
|
||||
|
19
app/models/exception_log.rb
Normal file
19
app/models/exception_log.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require 'securerandom'
|
||||
|
||||
class ExceptionLog < ApplicationRecord
|
||||
serialize :extra_params
|
||||
|
||||
def self.add(exc, ip_addr, params = {})
|
||||
log = self.new(
|
||||
ip_addr: ip_addr,
|
||||
class_name: exc.class.name,
|
||||
message: exc.message,
|
||||
trace: exc.backtrace.join("\n"),
|
||||
code: SecureRandom.uuid,
|
||||
version: Danbooru.config.version,
|
||||
extra_params: params
|
||||
)
|
||||
log.save!
|
||||
log
|
||||
end
|
||||
end
|
30
app/views/admin/exceptions/index.html.erb
Normal file
30
app/views/admin/exceptions/index.html.erb
Normal file
@ -0,0 +1,30 @@
|
||||
<table class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 200px">Created At</th>
|
||||
<th>Code</th>
|
||||
<th style="width: 100px">Version</th>
|
||||
<th>Class Name</th>
|
||||
<th>Message</th>
|
||||
<th>Stacktrace</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%- @exception_logs.each do |exception_log| %>
|
||||
<tr style="cursor: click;">
|
||||
<td><%= exception_log.created_at.strftime("%b %d, %Y %l:%M %p") %></td>
|
||||
<td><%= exception_log.code %></td>
|
||||
<td><%= exception_log.version %></td>
|
||||
<td><%= exception_log.class_name %></td>
|
||||
<td><%= exception_log.message %></td>
|
||||
<td>
|
||||
<%= link_to "View", admin_exception_path(exception_log) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= numbered_paginator(@exception_logs) %>
|
||||
</div>
|
15
app/views/admin/exceptions/show.html.erb
Normal file
15
app/views/admin/exceptions/show.html.erb
Normal file
@ -0,0 +1,15 @@
|
||||
<div>
|
||||
<div class="box-section">
|
||||
<h3><%= @exception_log.class_name %></h3>
|
||||
<p><%= @exception_log.message %></p>
|
||||
<p>
|
||||
Error Code: <%= @exception_log.code %><br/>
|
||||
Created At: <%= @exception_log.created_at.strftime("%b %d, %Y %l:%M %p") %><br/>
|
||||
Version: <%= @exception_log.version %>
|
||||
</p>
|
||||
</div>
|
||||
<strong>Extra Params:</strong>
|
||||
<pre class="box-section"><%= JSON.pretty_generate(@exception_log.extra_params) %></pre>
|
||||
<strong>Stacktrace:</strong>
|
||||
<pre class="box-section"><%= @exception_log.trace %></pre>
|
||||
</div>
|
@ -9,6 +9,7 @@ Rails.application.routes.draw do
|
||||
resources :users, :only => [:edit, :update]
|
||||
resource :alias_and_implication_import, :only => [:new, :create]
|
||||
resource :dashboard, :only => [:show]
|
||||
resources :exceptions, only: [:index, :show]
|
||||
end
|
||||
resources :edit_histories
|
||||
namespace :moderator do
|
||||
|
15
db/migrate/20190717205018_add_exception_logs.rb
Normal file
15
db/migrate/20190717205018_add_exception_logs.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class AddExceptionLogs < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :exception_logs do |t|
|
||||
t.timestamps
|
||||
t.string :class_name, null: false
|
||||
t.column :ip_addr, :inet, null: false
|
||||
t.string :version, null: false
|
||||
t.text :extra_params, null: true
|
||||
t.text :message, null: false
|
||||
t.text :trace, null: false
|
||||
t.column :code, :uuid, null: false
|
||||
t.integer :user_id, null: true
|
||||
end
|
||||
end
|
||||
end
|
@ -849,6 +849,44 @@ CREATE SEQUENCE public.email_blacklists_id_seq
|
||||
ALTER SEQUENCE public.email_blacklists_id_seq OWNED BY public.email_blacklists.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: exception_logs; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.exception_logs (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
class_name character varying NOT NULL,
|
||||
ip_addr inet NOT NULL,
|
||||
version character varying NOT NULL,
|
||||
extra_params text,
|
||||
message text NOT NULL,
|
||||
trace text NOT NULL,
|
||||
code uuid NOT NULL,
|
||||
user_id integer
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: exception_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.exception_logs_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: exception_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.exception_logs_id_seq OWNED BY public.exception_logs.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: favorite_groups; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@ -2838,6 +2876,13 @@ ALTER TABLE ONLY public.edit_histories ALTER COLUMN id SET DEFAULT nextval('publ
|
||||
ALTER TABLE ONLY public.email_blacklists ALTER COLUMN id SET DEFAULT nextval('public.email_blacklists_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: exception_logs id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.exception_logs ALTER COLUMN id SET DEFAULT nextval('public.exception_logs_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: favorite_groups id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@ -3335,6 +3380,14 @@ ALTER TABLE ONLY public.email_blacklists
|
||||
ADD CONSTRAINT email_blacklists_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: exception_logs exception_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.exception_logs
|
||||
ADD CONSTRAINT exception_logs_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: favorite_groups favorite_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -5126,6 +5179,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20190604125828'),
|
||||
('20190613025850'),
|
||||
('20190623070654'),
|
||||
('20190714122705');
|
||||
('20190714122705'),
|
||||
('20190717205018');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user