From 75656eb51e5d165c372130c3ffb09b0dbb31cec5 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 17 Feb 2017 13:21:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=20ExceptionTrack=20=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E4=B9=8B=E5=89=8D=E7=9A=84=20ExceptionLog=20=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20(#864)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 6 ++- .../admin/exception_logs_controller.rb | 21 ---------- app/controllers/auth/sso_controller.rb | 4 +- app/models/exception_log.rb | 2 - app/views/admin/exception_logs/_base.html.erb | 3 -- app/views/admin/exception_logs/destroy.js.erb | 2 - app/views/admin/exception_logs/index.html.erb | 28 ------------- app/views/admin/exception_logs/show.html.erb | 8 ---- app/views/admin/home/index.html.erb | 1 + app/views/layouts/admin.html.erb | 1 - config/initializers/exception-track.rb | 16 ++++++++ config/initializers/exception_notification.rb | 13 ------ config/locales/admin.en.yml | 2 +- config/locales/admin.zh-CN.yml | 2 +- config/locales/en.yml | 3 -- config/locales/zh-CN.yml | 3 -- config/locales/zh-TW.yml | 3 -- config/routes.rb | 6 +-- ...70217050010_create_exception_track_logs.rb | 13 ++++++ db/schema.rb | 12 +++--- lib/exception_notifier/database_notifier.rb | 41 ------------------- 22 files changed, 47 insertions(+), 145 deletions(-) delete mode 100644 app/controllers/admin/exception_logs_controller.rb delete mode 100644 app/models/exception_log.rb delete mode 100644 app/views/admin/exception_logs/_base.html.erb delete mode 100644 app/views/admin/exception_logs/destroy.js.erb delete mode 100644 app/views/admin/exception_logs/index.html.erb delete mode 100644 app/views/admin/exception_logs/show.html.erb create mode 100644 config/initializers/exception-track.rb delete mode 100644 config/initializers/exception_notification.rb create mode 100644 db/migrate/20170217050010_create_exception_track_logs.rb delete mode 100644 lib/exception_notifier/database_notifier.rb diff --git a/Gemfile b/Gemfile index a91d3875a3..293cb097fb 100644 --- a/Gemfile +++ b/Gemfile @@ -113,7 +113,7 @@ gem 'puma' gem 'rack-cors', require: 'rack/cors' gem 'rack-utf8_sanitizer' -gem 'exception_notification' +gem 'exception-track' gem 'status-page' gem 'bundler-audit', require: false diff --git a/Gemfile.lock b/Gemfile.lock index bb9005a1d5..1fa778a2c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -139,6 +139,10 @@ GEM faraday multi_json erubis (2.7.0) + exception-track (0.1.2) + exception_notification (~> 4.1) + rails (>= 4.2.0, < 5.1) + will_paginate (~> 3) exception_notification (4.2.1) actionmailer (>= 4.0, < 6) activesupport (>= 4.0, < 6) @@ -424,7 +428,7 @@ DEPENDENCIES dropzonejs-rails elasticsearch-model elasticsearch-rails - exception_notification + exception-track factory_girl_rails font-awesome-rails hiredis diff --git a/app/controllers/admin/exception_logs_controller.rb b/app/controllers/admin/exception_logs_controller.rb deleted file mode 100644 index 480cc2de8a..0000000000 --- a/app/controllers/admin/exception_logs_controller.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Admin - class ExceptionLogsController < Admin::ApplicationController - def index - @exception_logs = ExceptionLog.order(id: :desc).paginate(page: params[:page], per_page: 20) - end - - def show - @exception_log = ExceptionLog.find(params[:id]) - end - - def clean - ExceptionLog.delete_all - redirect_to admin_exception_logs_path, notice: '清空成功。' - end - - def destroy - @exception_log = ExceptionLog.find(params[:id]) - @exception_log.destroy - end - end -end diff --git a/app/controllers/auth/sso_controller.rb b/app/controllers/auth/sso_controller.rb index e9e18a2296..c4030e1195 100644 --- a/app/controllers/auth/sso_controller.rb +++ b/app/controllers/auth/sso_controller.rb @@ -39,7 +39,7 @@ def login puts message - ExceptionLog.create(title: "SSO Failed to create or lookup user:", body: message) + ExceptionTrack::Log.create(title: "SSO Failed to create or lookup user:", body: message) render plain: I18n.t("sso.unknown_error"), status: 500 return end @@ -75,4 +75,4 @@ def provider redirect_to sso.to_url(sso.return_sso_url) end end -end \ No newline at end of file +end diff --git a/app/models/exception_log.rb b/app/models/exception_log.rb deleted file mode 100644 index a260e68b12..0000000000 --- a/app/models/exception_log.rb +++ /dev/null @@ -1,2 +0,0 @@ -class ExceptionLog < ApplicationRecord -end diff --git a/app/views/admin/exception_logs/_base.html.erb b/app/views/admin/exception_logs/_base.html.erb deleted file mode 100644 index bd66e9864c..0000000000 --- a/app/views/admin/exception_logs/_base.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% content_for :sitemap do %> - 服务异常日志 -<% end %> diff --git a/app/views/admin/exception_logs/destroy.js.erb b/app/views/admin/exception_logs/destroy.js.erb deleted file mode 100644 index 8878a9ec14..0000000000 --- a/app/views/admin/exception_logs/destroy.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$("#exception_log_<%= params[:id] %>").remove(); -App.notice("删除成功。") \ No newline at end of file diff --git a/app/views/admin/exception_logs/index.html.erb b/app/views/admin/exception_logs/index.html.erb deleted file mode 100644 index c779a5dd50..0000000000 --- a/app/views/admin/exception_logs/index.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -<%= render 'base' %> -
- - <%= link_to "清空所有记录", clean_admin_exception_logs_path, class: "btn btn-small btn-danger", data: { confirm: "确定要删除本页的所有异常记录么?" }, method: "post" %> - -
- -
- - - - - - - - <% @exception_logs.each do |item| %> - "> - - - - - - <% end %> -
#<%= t("activerecord.attributes.exception_log.title") %>时间
<%= item.id %><%= link_to item.title, admin_exception_log_path(item.id) %><%= l(item.created_at, format: :long) %> - <%= link_to "", admin_exception_log_path(item.id), method: :delete, data: { remote: true, confirm: "是否确定要删除?" }, class: "fa fa-trash" %> -
- <%= will_paginate @exception_logs %> -
diff --git a/app/views/admin/exception_logs/show.html.erb b/app/views/admin/exception_logs/show.html.erb deleted file mode 100644 index f9eeced4d5..0000000000 --- a/app/views/admin/exception_logs/show.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= render 'base' %> -
- <%= link_to '返回', admin_exception_logs_path, class: "btn btn-small" %> -
- -
-
<%= @exception_log.body %>
-
\ No newline at end of file diff --git a/app/views/admin/home/index.html.erb b/app/views/admin/home/index.html.erb index d03ce609b5..fb463c37e5 100644 --- a/app/views/admin/home/index.html.erb +++ b/app/views/admin/home/index.html.erb @@ -9,6 +9,7 @@ 三方应用 异步任务... 数据库状态... + <%= t("admin.menu.exception_logs") %>... diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 011ab4cd85..2bd4c9c45b 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -33,7 +33,6 @@ li << link_to(t("admin.menu.site_nodes"),admin_site_nodes_path ) if Setting.has_module?(:site) li << link_to(t("admin.menu.sites"),admin_sites_path ) if Setting.has_module?(:site) li << link_to(t("admin.menu.locations"),admin_locations_path ) - li << link_to(t("admin.menu.exception_logs"),admin_exception_logs_path ) end %> <%= render "shared/usernav" %> diff --git a/config/initializers/exception-track.rb b/config/initializers/exception-track.rb new file mode 100644 index 0000000000..2d0cf0813f --- /dev/null +++ b/config/initializers/exception-track.rb @@ -0,0 +1,16 @@ +require 'exception_notification/sidekiq' + +ExceptionTrack.configure do + # self.environments = %i(production) +end + +ExceptionNotification.configure do |config| + config.ignored_exceptions += %w( + ActionView::TemplateError + ActionController::InvalidAuthenticityToken + ActionController::BadRequest + ActionView::MissingTemplate + ActionController::UrlGenerationError + ActionController::UnknownFormat + ) +end diff --git a/config/initializers/exception_notification.rb b/config/initializers/exception_notification.rb deleted file mode 100644 index 34c74a68e3..0000000000 --- a/config/initializers/exception_notification.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'exception_notification/rails' -require 'exception_notification/sidekiq' -require 'exception_notifier/database_notifier' - -ExceptionNotification.configure do |config| - config.ignored_exceptions += %w(ActionView::TemplateError - ActionController::InvalidAuthenticityToken - ActionController::BadRequest - ActionView::MissingTemplate - ActionController::UrlGenerationError - ActionController::UnknownFormat) - config.add_notifier :database, {} -end diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 15a8fe20b3..c1336216d2 100644 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -26,4 +26,4 @@ users: trust_user_can_modify_wiki: "Allow user to modify Wiki" topic_list: "Topic List" - check_photo: "View Photo" \ No newline at end of file + check_photo: "View Photo" diff --git a/config/locales/admin.zh-CN.yml b/config/locales/admin.zh-CN.yml index 5e9451da4d..f27c0b55d8 100644 --- a/config/locales/admin.zh-CN.yml +++ b/config/locales/admin.zh-CN.yml @@ -27,4 +27,4 @@ trust_user_can_modify_wiki: "信任用户将可以修改 Wiki" hr_user_can_create_topic: "招聘人员角色可以忽略新手限制直接发帖" topic_list: "话题列表" - check_photo: "瀏覽圖片" \ No newline at end of file + check_photo: "瀏覽圖片" diff --git a/config/locales/en.yml b/config/locales/en.yml index c1fc26d41e..5a243e3197 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -95,9 +95,6 @@ en: url: "URL" desc: "Description" site_node_id: "Category" - exception_log: - title: Abstract - body: Details errors: models: user: "User" diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index aa3119e8cd..820700ca5f 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -88,9 +88,6 @@ url: 地址 desc: 简单介绍 site_node_id: 分类 - exception_log: - title: 摘要 - body: 详细内容 device: platform: 类型 token: Token diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index f15ef45ab0..007ebbc9c8 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -74,9 +74,6 @@ url: 地址 desc: 簡單介紹 site_node_id: 分類 - exception_log: - title: 摘要 - body: 詳細內容 errors: models: user: 用戶 diff --git a/config/routes.rb b/config/routes.rb index ff83dbd77d..96e8c4f1bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,11 +129,6 @@ end end resources :locations - resources :exception_logs do - collection do - post :clean - end - end resources :applications resources :stats end @@ -199,6 +194,7 @@ authenticate :user, ->(u) { u.admin? } do mount Sidekiq::Web, at: '/sidekiq' mount PgHero::Engine, at: "pghero" + mount ExceptionTrack::Engine, at: "/exception-track" end mount JasmineRails::Engine, at: '/specs' if defined?(JasmineRails) diff --git a/db/migrate/20170217050010_create_exception_track_logs.rb b/db/migrate/20170217050010_create_exception_track_logs.rb new file mode 100644 index 0000000000..c772b824e4 --- /dev/null +++ b/db/migrate/20170217050010_create_exception_track_logs.rb @@ -0,0 +1,13 @@ +# This migration comes from exception_track (originally 20170217023900) +class CreateExceptionTrackLogs < ActiveRecord::Migration[5.0] + def change + create_table :exception_tracks do |t| + t.string :title + t.text :body + + t.timestamps + end + + drop_table :exception_logs + end +end diff --git a/db/schema.rb b/db/schema.rb index e1a568050c..a6d03c701c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170204090209) do +ActiveRecord::Schema.define(version: 20170217050010) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -61,11 +61,11 @@ t.index ["user_id"], name: "index_devices_on_user_id", using: :btree end - create_table "exception_logs", force: :cascade do |t| - t.string "title", null: false - t.text "body", null: false - t.datetime "created_at" - t.datetime "updated_at" + create_table "exception_tracks", force: :cascade do |t| + t.string "title" + t.text "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "locations", force: :cascade do |t| diff --git a/lib/exception_notifier/database_notifier.rb b/lib/exception_notifier/database_notifier.rb deleted file mode 100644 index 814fe20ad4..0000000000 --- a/lib/exception_notifier/database_notifier.rb +++ /dev/null @@ -1,41 +0,0 @@ -# 异常通知 -module ExceptionNotifier - class DatabaseNotifier - def initialize(_options) - # do something with the options... - end - - def call(exception, _options = {}) - # send the notification - @title = exception.message - messages = [] - messages << exception.inspect - messages << "\n" - messages << "--------------------------------------------------" - messages << headers_for_env(_options[:env]) - messages << "--------------------------------------------------" - unless exception.backtrace.blank? - messages << "\n" - messages << exception.backtrace - end - - if Rails.env.production? - ExceptionLog.create(title: @title, body: messages.join("\n")) - end - end - - def headers_for_env(env) - return '' if env.blank? - - headers = [] - headers << "Method: #{env['REQUEST_METHOD']}" - headers << "URL: #{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}" - headers << "User-Agent: #{env['HTTP_USER_AGENT']}" - headers << "Language: #{env['HTTP_ACCEPT_LANGUAGE']}" - headers << "Server: #{Socket.gethostname}" - headers << "Process: #{$$}" - - headers.join("\n") - end - end -end