Class: DevSystem::LogPanel

Inherits:
Liza::Panel show all
Defined in:
lib/dev_system/sub/log/log_panel.rb

Instance Attribute Summary

Attributes inherited from Liza::Panel

#key

Instance Method Summary collapse

Methods inherited from Liza::Panel

box, #box, color, #controller, controller, division, #division, #initialize, #push, #short, #started, subsystem, #subsystem, token

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

This class inherits a constructor from Liza::Panel

Instance Method Details

#call(env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dev_system/sub/log/log_panel.rb', line 3

def call env
  env[:instance] ||= env[:unit_class] != env[:unit]
  env[:method_name] ||= method_name_for env

  # The unit determines the smallest log level it wants to log
  # Therefore, a message of lower log level will not be logged
  return if env[:message_log_level] < env[:unit_log_level]

  handlers.values.each do |handler|
    handler.call env
  rescue Exception => e
    log "#{e.class} #{e.message.inspect} on #{e.backtrace[0]}".yellow
  end
end

#handler(*keys) ⇒ Object



18
19
20
21
22
# File 'lib/dev_system/sub/log/log_panel.rb', line 18

def handler *keys
  Array(keys).each do |k|
    handlers[k] ||= Liza.const("#{k}_log")
  end
end

#handlersObject



24
25
26
# File 'lib/dev_system/sub/log/log_panel.rb', line 24

def handlers
  @handlers ||= {}
end

#method_name_for(env) ⇒ Object

NOTE: improve logs performance and readability



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dev_system/sub/log/log_panel.rb', line 30

def method_name_for env
  env[:caller].each do |s|
    t = s.match(/`(.*)'/)[1]

    next if t.include? " in <class:"
    return t.split(" ").last if t.include? " in "

    next if t == "log"
    next if t == "each"
    next if t == "map"
    next if t == "with_index"
    next if t == "instance_exec"
    next if t.start_with? "_"
    return t
  end

  raise "there's something wrong with kaller"
end