Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/stackify-api-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Stackify
autoload :LogsSender, 'stackify/logs_sender'
autoload :LoggerProxy, 'stackify/logger_proxy'
autoload :StackifiedError, 'stackify/error'
autoload :StringException, 'stackify/error'
autoload :ErrorsGovernor, 'stackify/errors_governor'
autoload :Metrics, 'stackify/metrics/metrics'

Expand Down
6 changes: 5 additions & 1 deletion lib/stackify/error.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Stackify

class StringException < StandardError
def class
'StringException'.freeze
end
end
class StackifiedError < StandardError

CONTEXT_PROPERTIES = { 'user' => 'current_user'}
Expand Down
28 changes: 24 additions & 4 deletions lib/stackify/logger_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ def is_appropriate_env?

def log_message_task level, msg, call_trace
Stackify::ScheduleTask.new ({limit: 1}) do
e = Exception.new(msg)
e.set_backtrace(call_trace)
ex = StackifiedError.new(e, binding())
Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
if %w(error fatal).include?(level)
ex = if ruby_exception?(msg) && msg.class != Class
msg.set_backtrace(call_trace)
msg
else
e = StringException.new(msg)
e.set_backtrace(call_trace)
e
end
ex = StackifiedError.new(ex, binding())
Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
else
Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0]).to_h
end
end
end

Expand All @@ -70,6 +80,16 @@ def log_exception_task level, ex
Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
end
end

def ruby_exception? klass
klass = klass.class == Class ? klass : klass.class
klasses = [klass]
while klass != Object do
klasses << klass.superclass
klass = klass.superclass
end
klasses.include?(Exception)
end
end

end