Class: CrashLog::Payload
- Inherits:
-
Object
- Object
- CrashLog::Payload
- Includes:
- Logging
- Defined in:
- lib/crash_log/payload.rb
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#backtrace_filters ⇒ Object
readonly
Returns the value of attribute backtrace_filters.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#exception_object ⇒ Object
readonly
Returns the value of attribute exception_object.
Class Method Summary collapse
Instance Method Summary collapse
- #add_context(data) ⇒ Object
- #add_data(data) ⇒ Object
- #add_environment_data(data) ⇒ Object
- #add_session_data(data) ⇒ Object
- #body ⇒ Object
- #deliver ⇒ Object
-
#deliver! ⇒ Object
Delivers this payload to CrashLog.
-
#initialize(event_data, config) ⇒ Payload
constructor
A new instance of Payload.
-
#notifier ⇒ Object
Various meta data about this notifier gem.
- #reporter ⇒ Object
-
#timestamp ⇒ Object
The canonical time this exception occurred.
Methods included from Logging
Constructor Details
#initialize(event_data, config) ⇒ Payload
Returns a new instance of Payload.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/crash_log/payload.rb', line 25 def initialize(event_data, config) @config = config || {} @event_data = event_data @context = {} @environment = {} @data = {} @backtrace_filters = config[:backtrace_filters] || [] # Actually serialize the exception/event hash for transport @event = serialize_event(event_data) add_environment_data(:system => SystemInformation.to_hash) add_context(:stage => config.stage) end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
52 53 54 |
# File 'lib/crash_log/payload.rb', line 52 def backtrace @backtrace end |
#backtrace_filters ⇒ Object (readonly)
Returns the value of attribute backtrace_filters.
23 24 25 |
# File 'lib/crash_log/payload.rb', line 23 def backtrace_filters @backtrace_filters end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/crash_log/payload.rb', line 23 def config @config end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
52 53 54 |
# File 'lib/crash_log/payload.rb', line 52 def context @context end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
23 24 25 |
# File 'lib/crash_log/payload.rb', line 23 def data @data end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
52 53 54 |
# File 'lib/crash_log/payload.rb', line 52 def environment @environment end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
52 53 54 |
# File 'lib/crash_log/payload.rb', line 52 def event @event end |
#exception_object ⇒ Object (readonly)
Returns the value of attribute exception_object.
52 53 54 |
# File 'lib/crash_log/payload.rb', line 52 def exception_object @exception_object end |
Class Method Details
.build(exception, config) {|payload| ... } ⇒ Object
7 8 9 10 11 |
# File 'lib/crash_log/payload.rb', line 7 def self.build(exception, config, &block) payload = new(exception, config) yield(payload) if block_given? payload end |
Instance Method Details
#add_context(data) ⇒ Object
58 59 60 |
# File 'lib/crash_log/payload.rb', line 58 def add_context(data) (@context ||= {}).merge!(data) if data.is_a?(Hash) end |
#add_data(data) ⇒ Object
62 63 64 |
# File 'lib/crash_log/payload.rb', line 62 def add_data(data) (@data ||= {}).merge!(data) if data.is_a?(Hash) end |
#add_environment_data(data) ⇒ Object
70 71 72 |
# File 'lib/crash_log/payload.rb', line 70 def add_environment_data(data) @environment.merge!(data) if data.respond_to?(:keys) end |
#add_session_data(data) ⇒ Object
66 67 68 |
# File 'lib/crash_log/payload.rb', line 66 def add_session_data(data) (@data[:session] ||= {}).merge!(data) if data.is_a?(Hash) end |
#body ⇒ Object
54 55 56 |
# File 'lib/crash_log/payload.rb', line 54 def body renderer.render end |
#deliver ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/crash_log/payload.rb', line 40 def deliver error("Not configured, please run CrashLog.configure") && return unless reporter if reporter.notify(self.body) reporter.result end end |
#deliver! ⇒ Object
Delivers this payload to CrashLog
Captures any exceptions and logs them.
16 17 18 19 20 21 |
# File 'lib/crash_log/payload.rb', line 16 def deliver! deliver rescue Exception => e error('Failed to deliver notification to CrashLog collector') log_exception(e) end |
#notifier ⇒ Object
Various meta data about this notifier gem
86 87 88 89 90 91 92 |
# File 'lib/crash_log/payload.rb', line 86 def notifier { :name => "crashlog", :version => CrashLog::VERSION, :language => 'Ruby' } end |
#reporter ⇒ Object
48 49 50 |
# File 'lib/crash_log/payload.rb', line 48 def reporter CrashLog.reporter end |
#timestamp ⇒ Object
The canonical time this exception occurred.
Other notifiers leave this to the collector to set, we however take time more seriously and use this figure internally to detect processing time irregularities.
Returns UNIX UTC timestamp integer.
81 82 83 |
# File 'lib/crash_log/payload.rb', line 81 def Time.now.utc.to_i end |