class Nightwatch::ExceptionManager
Public Class Methods
absolute_path(file)
click to toggle source
# File lib/nightwatch/monitor.rb, line 11 def self.absolute_path(file) File.absolute_path(file).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) end
new()
click to toggle source
# File lib/nightwatch/monitor.rb, line 18 def initialize @exceptions = {} @config = Configuration.instance end
Public Instance Methods
add_exception(exception)
click to toggle source
# File lib/nightwatch/monitor.rb, line 23 def add_exception(exception) Configuration.instance.filters.each do |filter| exception = filter.apply(exception) break if !exception end if exception @exceptions[exception.object_id] = [exception, stack(exception), Time.now.to_i] end end
commit!()
click to toggle source
# File lib/nightwatch/monitor.rb, line 34 def commit! host = Socket.gethostname env = Hash[ENV.to_a] @exceptions.each do |id, info| exception, stack, ticks = info klass = exception.class.name record = { class: klass, message: exception.to_s, script: @@script, argv: @@argv, pid: $$, env: env, config: RbConfig::CONFIG, host: host, stack: stack, timestamp: ticks } @config.logger.log(record) end end
Private Instance Methods
stack(exception)
click to toggle source
# File lib/nightwatch/monitor.rb, line 61 def stack(exception) stack = [] if exception.respond_to? :backtrace_locations exception.backtrace_locations.each do |location| stack << { label: location.label, path: self.class.absolute_path(location.absolute_path), line: location.lineno } end else exception.backtrace.each do |location| location.match(/^(.+?):(\d+)(|:in `(.+)')$/) stack << { label: $4, path: self.class.absolute_path($1), line: $2.to_i } end end stack end