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



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

def args
  @current[:args]
end

#class_nameObject



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

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

#error(msg) ⇒ Object



74
75
76
77
# File 'lib/volt/extra_core/logger.rb', line 74

def error(msg)
  msg ||= yield
  super(colorize(msg, :red))
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
52
# 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)
      backtrace = error.try(:backtrace)
      if backtrace
        text += "\n" + colorize(error.backtrace.join("\n"), :red)
      end
    end
  end

  log(level, text)
end

#log_with_color(msg, color) ⇒ Object



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

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

#method_nameObject



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

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

#run_timeObject



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

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