Module: Dunlop::Loggable

Extended by:
ActiveSupport::Concern
Included in:
ExecutionBatch
Defined in:
app/services/dunlop/loggable.rb

Instance Method Summary collapse

Instance Method Details

#log_state_transitionObject



51
52
53
# File 'app/services/dunlop/loggable.rb', line 51

def log_state_transition
  log_entries.create(body: "transition to #{state}")
end

#loggerObject



47
48
49
# File 'app/services/dunlop/loggable.rb', line 47

def logger
  Dunlop::NestedLogger
end

#with_nested_logger(scope = nil, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/dunlop/loggable.rb', line 28

def with_nested_logger(scope=nil, options={})
  scope ||= caller[0][/`.*'/][1..-2]
  e = nil
  backtrace = nil
  Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do
    Dunlop::NestedLogger.scope(scope, options) do
      begin
        yield
      rescue => e
        backtrace = Dunlop::LogEntry.exception_to_backtrace(e)
        Dunlop::NestedLogger.error(e.message)
      end
    end
    log_yaml = Dunlop::NestedLogger.flush_as_yaml
    log_entries.create(body: log_yaml, backtrace: backtrace) if log_yaml.present?
  end
  raise e if e
end

#with_nested_logger_and_catch_failed(scope = nil, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/dunlop/loggable.rb', line 8

def with_nested_logger_and_catch_failed(scope=nil, options={})
  scope ||= caller[0][/`.*'/][1..-2]
  options[:exception_notifier] = true unless options.has_key?(:exception_notifier)
  backtrace = nil
  Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do
    Dunlop::NestedLogger.scope(scope, options) do
      begin
        yield
      rescue => e
        failed!
        ExceptionNotifier.notify_exception(e) if options[:exception_notifier]
        backtrace = Dunlop::LogEntry.exception_to_backtrace(e)
        Dunlop::NestedLogger.error(e.message)
      end
    end
    log_yaml = Dunlop::NestedLogger.flush_as_yaml
    log_entries.create(body: log_yaml, backtrace: backtrace) if log_yaml.present?
  end
end