class Volt::VoltLogger
Public Class Methods
new(current = {})
click to toggle source
Calls superclass method
Logger::new
# File lib/volt/extra_core/logger.rb, line 24 def initialize(current = {}) super(STDOUT) @current = current @formatter = Volt::VoltLoggerFormatter.new end
Public Instance Methods
args()
click to toggle source
# File lib/volt/extra_core/logger.rb, line 54 def args @current[:args] end
class_name()
click to toggle source
# File lib/volt/extra_core/logger.rb, line 58 def class_name colorize(@current[:class_name].to_s, :light_blue) end
error(msg) { || ... }
click to toggle source
Calls superclass method
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/volt/extra_core/logger.rb, line 70 def log_with_color(msg, color) Volt.logger.info(colorize(msg, color)) end
method_name()
click to toggle source
# File lib/volt/extra_core/logger.rb, line 62 def method_name colorize(@current[:method_name].to_s, :green) end
run_time()
click to toggle source
# File lib/volt/extra_core/logger.rb, line 66 def run_time colorize(@current[:run_time].to_s + 'ms', :green) end
Private Instance Methods
colorize(string, color)
click to toggle source
# File lib/volt/extra_core/logger.rb, line 81 def colorize(string, color) if STDOUT.tty? && string case color when :cyan "\e[1;34m" + string + "\e[0;37m" when :green "\e[0;32m" + string + "\e[0;37m" when :light_blue "\e[1;34m" + string + "\e[0;37m" when :purple "\e[1;35m" + string + "\e[0;37m" when :red "\e[1;31m" + string + "\e[0;37m" end else string.to_s end end