Class: Stackify::AgentClient
Instance Method Summary collapse
- #get_epoch(msg) ⇒ Object
- #has_error(msg) ⇒ Object
-
#initialize ⇒ AgentClient
constructor
A new instance of AgentClient.
- #log(level, msg, call_trace, task) ⇒ Object
- #log_exception(level = :error, ex, task) ⇒ Object
- #log_exception_task(level, ex, trans_id = nil, log_uuid = nil) ⇒ Object
- #log_message_task(level, msg, call_trace, trans_id = nil, log_uuid = nil) ⇒ Object
- #send_logs(msgs, attempts = 3) ⇒ Object
Constructor Details
#initialize ⇒ AgentClient
Returns a new instance of AgentClient.
4 5 6 7 8 9 10 11 12 13 |
# 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 |
Instance Method Details
#get_epoch(msg) ⇒ Object
42 43 44 |
# File 'lib/stackify/agent_client.rb', line 42 def get_epoch msg msg['EpochMs'] end |
#has_error(msg) ⇒ Object
38 39 40 |
# File 'lib/stackify/agent_client.rb', line 38 def has_error msg !msg['Ex'].nil? end |
#log(level, msg, call_trace, task) ⇒ Object
15 16 17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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.) && 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.}\" 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) ⇒ Object
69 70 71 72 73 |
# 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., caller[0], trans_id, log_uuid, ex).to_h end end |
#log_message_task(level, msg, call_trace, trans_id = nil, log_uuid = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/stackify/agent_client.rb', line 50 def 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., 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) ⇒ Object
46 47 48 |
# File 'lib/stackify/agent_client.rb', line 46 def send_logs msgs, attempts = 3 @@sender.send_logs msgs, attempts end |