Module: Legion::Logging::Hooks

Defined in:
lib/legion/logging/hooks.rb

Class Method Summary collapse

Class Method Details

.clear_hooks!Object



41
42
43
44
45
# File 'lib/legion/logging/hooks.rb', line 41

def clear_hooks!
  @fatal_hooks = []
  @error_hooks = []
  @warn_hooks = []
end

.disable_hooks!Object



33
34
35
# File 'lib/legion/logging/hooks.rb', line 33

def disable_hooks!
  @enabled = false
end

.enable_hooks!Object



29
30
31
# File 'lib/legion/logging/hooks.rb', line 29

def enable_hooks!
  @enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/legion/logging/hooks.rb', line 37

def enabled?
  @enabled || false
end

.fire(level, message, event) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/legion/logging/hooks.rb', line 19

def fire(level, message, event)
  return unless @enabled

  hooks_for(level).each do |hook|
    hook.call(message, event)
  rescue StandardError => e
    warn("Legion::Logging::Hooks#fire callback failed: #{e.message}")
  end
end

.on_error(&block) ⇒ Object



11
12
13
# File 'lib/legion/logging/hooks.rb', line 11

def on_error(&block)
  error_hooks << block
end

.on_fatal(&block) ⇒ Object



7
8
9
# File 'lib/legion/logging/hooks.rb', line 7

def on_fatal(&block)
  fatal_hooks << block
end

.on_warn(&block) ⇒ Object



15
16
17
# File 'lib/legion/logging/hooks.rb', line 15

def on_warn(&block)
  warn_hooks << block
end