Class: Stackify::LoggerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify/logger_client.rb

Constant Summary collapse

PERIOD =
1

Instance Method Summary collapse

Constructor Details

#initializeLoggerClient

Returns a new instance of LoggerClient.



5
6
7
# File 'lib/stackify/logger_client.rb', line 5

def initialize
  @@errors_governor = Stackify::ErrorsGovernor.new
end

Instance Method Details

#log(level, msg) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/stackify/logger_client.rb', line 9

def log level, msg
  Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
    if acceptable? level, msg && Stackify.working?
      worker = Stackify::AddMsgWorker.new
      task = log_message_task level, msg
      worker.async_perform PERIOD, task
    end
  end
end

#log_exception(level = :error, ex) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stackify/logger_client.rb', line 19

def log_exception level= :error, ex
  if ex.is_a?(Stackify::StackifiedError)
    Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
      if acceptable? level, ex.message && Stackify.working?
        if @@errors_governor.can_send? ex
          worker = Stackify::AddMsgWorker.new
          task = log_exception_task level, ex
          worker.async_perform PERIOD, task
        else
          Stackify.internal_log :warn,
          "LoggerClient: logging of exception with message \"#{ex.message}\" is skipped - flood_limit is exceeded"
        end
      end
    end
  else
    Stackify.log_internal_error 'LoggerClient: log_exception should get StackifiedError object'
  end
end