Class: Volt::VoltLogger

Inherits:
Logger show all
Defined in:
lib/volt/extra_core/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(current = {}) ⇒ VoltLogger

Returns a new instance of VoltLogger.



24
25
26
27
28
# File 'lib/volt/extra_core/logger.rb', line 24

def initialize(current={})
  super(STDOUT)
  @current = current
  @formatter = Volt::VoltLoggerFormatter.new
end

Instance Method Details

#argsObject



53
54
55
# File 'lib/volt/extra_core/logger.rb', line 53

def args
  @current[:args]
end

#class_nameObject



57
58
59
# File 'lib/volt/extra_core/logger.rb', line 57

def class_name
  colorize(@current[:class_name].to_s, :light_blue)
end

#log_dispatch(class_name, method_name, run_time, args, error) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/volt/extra_core/logger.rb', line 30

def log_dispatch(class_name, method_name, run_time, args, error)
  @current = {
    args: args,
    class_name: class_name,
    method_name: method_name,
    run_time: run_time
  }

  level = error ? Logger::ERROR : Logger::INFO
  text = TaskLogger.task_dispatch_message(self, args)


  if error
    text += "\n" + colorize(error.to_s, :red)
    if error.is_a?(Exception) && !error.is_a?(VoltUserError)
      text += "\n" + colorize(error.backtrace.join("\n"), :red)
    end
  end

  log(level, text)

end

#log_with_color(msg, color) ⇒ Object



69
70
71
# File 'lib/volt/extra_core/logger.rb', line 69

def log_with_color(msg, color)
  Volt.logger.info(colorize(msg, color))
end

#method_nameObject



61
62
63
# File 'lib/volt/extra_core/logger.rb', line 61

def method_name
  colorize(@current[:method_name].to_s, :green)
end

#run_timeObject



65
66
67
# File 'lib/volt/extra_core/logger.rb', line 65

def run_time
  colorize(@current[:run_time].to_s + 'ms', :green)
end