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(key) ⇒ Object



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

def handler key
  handlers[key] ||= Liza.const("#{key}_log")
end

#handlersObject



22
23
24
# File 'lib/dev_system/sub/log/log_panel.rb', line 22

def handlers
  @handlers ||= {}
end

#method_name_for(env) ⇒ Object

NOTE: improve logs performance and readability



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

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