class Stackify::AgentClient
Public Class Methods
new()
click to toggle source
# File lib/stackify/agent_client.rb, line 4 def initialize Stackify.internal_log :info, '[AgentClient]: initialize()' @@errors_governor = Stackify::ErrorsGovernor.new case Stackify.configuration.transport when Stackify::UNIX_SOCKET @@sender = Stackify::UnixSocketSender.new when Stackify::AGENT_HTTP @@sender = Stackify::AgentHTTPSender.new end end
Public Instance Methods
get_epoch(msg)
click to toggle source
# File lib/stackify/agent_client.rb, line 42 def get_epoch msg msg['EpochMs'] end
has_error(msg)
click to toggle source
# File lib/stackify/agent_client.rb, line 38 def has_error msg !msg['Ex'].nil? end
log(level, msg, call_trace, task)
click to toggle source
# File lib/stackify/agent_client.rb, line 15 def log level, msg, call_trace, task if acceptable?(level, msg) && Stackify.working? worker = Stackify::AddMsgWorker.new worker.async_perform ScheduleDelay.new, task end end
log_exception(level= :error, ex, task)
click to toggle source
# File lib/stackify/agent_client.rb, line 22 def log_exception level= :error, ex, task if ex.is_a?(Stackify::StackifiedError) if acceptable?(level, ex.message) && Stackify.working? if @@errors_governor.can_send? ex worker = Stackify::AddMsgWorker.new worker.async_perform ScheduleDelay.new, task else Stackify.internal_log :warn, "AgentClient: logging of exception with message \"#{ex.message}\" is skipped - flood_limit is exceeded" end end else Stackify.log_internal_error 'AgentClient: log_exception should get StackifiedError object' end end
log_exception_task(level, ex, trans_id=nil, log_uuid=nil)
click to toggle source
# File lib/stackify/agent_client.rb, line 69 def log_exception_task level, ex, trans_id=nil, log_uuid=nil Stackify::ScheduleTask.new ({limit: 1}) do Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], trans_id, log_uuid, ex).to_h end end
log_message_task(level, msg, call_trace, trans_id=nil, log_uuid=nil)
click to toggle source
# File lib/stackify/agent_client.rb, line 50 def log_message_task level, msg, call_trace, trans_id=nil, log_uuid=nil Stackify::ScheduleTask.new ({limit: 1}) do 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], trans_id, log_uuid, ex).to_h else Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0], trans_id, log_uuid).to_h end end end
send_logs(msgs, attempts = 3)
click to toggle source
# File lib/stackify/agent_client.rb, line 46 def send_logs msgs, attempts = 3 @@sender.send_logs msgs, attempts end
Private Instance Methods
acceptable?(level, msg)
click to toggle source
# File lib/stackify/agent_client.rb, line 77 def acceptable? level, msg Stackify.is_valid? && is_correct_log_level?(level) && is_not_internal_log_message?(msg) end
is_correct_log_level?(level)
click to toggle source
# File lib/stackify/agent_client.rb, line 86 def is_correct_log_level? level config_level = Logger.const_get Stackify.configuration.log_level.to_s.upcase current_level = Logger.const_get level.to_s.upcase current_level >= config_level end
is_not_internal_log_message?(msg)
click to toggle source
# File lib/stackify/agent_client.rb, line 82 def is_not_internal_log_message? msg msg.try(:index, ::Stackify::INTERNAL_LOG_PREFIX).nil? end
ruby_exception?(klass)
click to toggle source
# File lib/stackify/agent_client.rb, line 92 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