Class: ExceptionNotifier::GraylogNotifier
- Inherits:
-
Object
- Object
- ExceptionNotifier::GraylogNotifier
- Defined in:
- lib/exception_notifier/graylog_notifier.rb
Instance Method Summary collapse
- #call(err, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ GraylogNotifier
constructor
A new instance of GraylogNotifier.
Constructor Details
#initialize(options = {}) ⇒ GraylogNotifier
Returns a new instance of GraylogNotifier.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/exception_notifier/graylog_notifier.rb', line 5 def initialize( = {}) standard_args = { :hostname => "localhost", :port => 12201, :local_app_name => Socket::gethostname, :facility => 'gelf_exceptions', :max_chunk_size => 'LAN', :level => 3 } @args = standard_args.merge() @notifier = GELF::Notifier.new(@args[:hostname], @args[:port], @args[:max_chunk_size]) end |
Instance Method Details
#call(err, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/exception_notifier/graylog_notifier.rb', line 19 def call(err, ={}) env = [:env] begin opts = { :short_message => err., :facility => @args[:facility], :level => @args[:level], :host => @args[:local_app_name], :app_name=>@args[:app_name] } if err.backtrace && err.backtrace.size > 0 bc = ActiveSupport::BacktraceCleaner.new bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } bc.add_silencer { |line| line =~ /mongrel|rvm\/gems|rubygems/ } _backtrace = bc.clean(err.backtrace)||[] if _backtrace.size>0 opts = opts.merge ({ :full_message => _backtrace.join("\n"), :file => _backtrace[0].split(":")[0], :line => _backtrace[0].split(":")[1], }) end end unless env.nil? request = ActionDispatch::Request.new(env) request_items = {:url => request.original_url, :http_method => request.method, :ip_address => request.remote_ip, :parameters => request.filtered_parameters, :timestamp => Time.current} opts[:request] = request_items opts[:session] = request.session opts[:cookies] = request. # opts[:environment] = request.filtered_env end @notifier.notify!(opts) rescue Exception => i_err puts "Graylog2 Exception logger. Could not send message: " + i_err. end end |