exception_알림 설정

5937 단어 WebSVNgit.RubyRails
슈퍼 설치exception_notifier
    gem 방식 1:
       sudo gem sources -a http://gemcutter.org 
       gem install super_exception_notifier

    gem 방식 2:
  mkdir -p ~/src
  cd ~/src
  git clone git://github.com/pboling/exception_notification.git
  cd exception_notification
  gem build exception_notification.gemspec
  sudo gem install super_exception_notification-2.0.0.gem # (Or whatever version gets built)

plugin git 방식:
  ./script/plugin install git://github.com/pboling/exception_notification.git

plugin svn 방식:
   ./script/plugin install http://super-exception-notifier.googlecode.com/svn/trunk/super_exception_notifier

application controller 에 가입
     

  class ApplicationController < ActionController::Base
    include ExceptionNotifiable
    ...
  end

설정 예외notifier
   파일 추가 exceptionnotifier. rb 에서 config / initializers / exceptionnotifier.rb
   exception_notifier.rb :
ExceptionNotifier.configure_exception_notifier do |config|
  # If left empty web hooks will not be engaged
  config[:web_hooks]                = []
  config[:app_name]                 = "[Project Name]"
  # NOTE: THERE IS A BUG IN RAILS 2.3.3 which forces us to NOT use anything but a simple email address string for the sender address.
  # https://rails.lighthouseapp.com/projects/8994/tickets/2340
  # config[:sender_address]           = %("#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} Error" <[email protected]>)
  config[:sender_address]           = %("Project Name" <[email protected]_name.com>)
  config[:exception_recipients] = %w([email protected])
  # Customize the subject line
  #config[:subject_prepend]          = "[#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} ERROR] "
  config[:subject_prepend]          = "[ProjectName ERROR] "
  config[:subject_append]           = " :("
  # Include which sections of the exception email?
  config[:sections]                 = %w(request session environment backtrace)
  # Only use this gem to render, never email
  #defaults to false - meaning by default it sends email.  Setting true will cause it to only render the error pages, and NOT email.
  config[:skip_local_notification]   = true
  # Example:
  #config[:view_path]               = 'app/views/error'
  config[:view_path]                = nil
  # Error Notification will be sent if the HTTP response code for the error matches one of the following error codes
  config[:notify_error_codes]   = %W( 405 500 503 )
  # Error Notification will be sent if the error class matches one of the following error error classes
  config[:notify_error_classes] = %W( )
  # What should we do for errors not listed?
  config[:notify_other_errors]  = true
  # If you set this SEN will
  config[:git_repo_path]            = nil
  config[:template_root]            = "#{File.dirname(__FILE__)}/../views"
end

ActionMailer 설정
   
   설정 파일 config / config. yml 을 추가 할 수 있 습 니 다.
 
public:
  smtp_server: 'mail.xxxx.com'
  smtp_port: 25
  smtp_domain: 'www.xxxx.com'
  smtp_user_name: '[email protected]'
  smtp_passwd: ""
  smtp_authentication: 'login'
test:
  smtp_server: 'mail.xxxx.com'
  smtp_port: 25
  smtp_domain: 'www.xxxx.com'
  smtp_user_name: '[email protected]'
  smtp_passwd: ""
  smtp_authentication: 'login'
development:
  smtp_server: 'mail.xxxx.com'
  smtp_port: 25
  smtp_domain: 'mail.xxxx.com'
  smtp_user_name: '[email protected]'
  smtp_passwd: ""
  smtp_authentication: 'login'
production:
  smtp_server: 'mail.xxxx.com'
  smtp_port: 25
  smtp_domain: 'mail.xxxx.com'
  smtp_user_name: ''
  smtp_passwd: ''
  smtp_authentication: ''

파일 추가 20mailer_config.rb
 
PUBLIC_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")['public']
PRIVATE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV]
CONFIG = PUBLIC_CONFIG.merge(PRIVATE_CONFIG || Hash.new)

ActionMailer::Base.smtp_settings = {
  :address  => CONFIG['smtp_server'],
  :port  => CONFIG['smtp_port'],
  :domain  => CONFIG['smtp_domain'],
  :user_name  => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_user_name']),
  :password  => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_passwd']),
  :authentication  => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_authentication'])
}

ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true

gem 방식 이 config / environment. rb 에 gem 를 추가 하려 면
    config.gem 'super_exception_notifier', :version => '~> 2.0.0', :lib => "exception_notifier"

로 컬 테스트 를 하려 면 다음 세 가지 일 을 해 야 합 니 다.
    1. 서 비 스 는 production 모드 로 시작 해 야 합 니 다.
      2.config/initializers/exception_notifier. rb 에서 config [: skip local notification]   = false
    3. application controller 에 local 추가addresses.clear

좋은 웹페이지 즐겨찾기