class ColouredLogger::CLogger
Constants
- SEVERITY_TO_BACKGROUND_COLOR_MAP
- SEVERITY_TO_COLOR_MAP
Attributes
logger[R]
Public Class Methods
debug(method, message)
click to toggle source
low-level information for developers
# File lib/coloured_logger.rb, line 34 def self.debug(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.debug("#{formatted_method}: #{message}") end
error(method, message)
click to toggle source
# File lib/coloured_logger.rb, line 50 def self.error(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.error("#{formatted_method}: #{message}") end
fatal(method, message)
click to toggle source
# File lib/coloured_logger.rb, line 55 def self.fatal(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.fatal("#{formatted_method}: #{message}") end
info(method, message)
click to toggle source
generic (useful) information about system operation
# File lib/coloured_logger.rb, line 40 def self.info(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.info("#{formatted_method}: #{message}") end
log_time(method, start_time, task_name)
click to toggle source
Logs time taken to execute a task
# File lib/coloured_logger.rb, line 66 def self.log_time(method, start_time, task_name) end_time = Time.now formatted_method = CLogger.instance.formatted_method(method) time_taken = end_time - start_time formatted_time_taken = sprintf("[%.4f sec]", time_taken) CLogger.instance.logger.perf("#{formatted_method}: Time taken to #{task_name} - \033[35m#{formatted_time_taken}\033[0m") end
new()
click to toggle source
# File lib/coloured_logger.rb, line 15 def initialize @logger = Logger.new(STDOUT) # Logger.LEVEL = DEBUG - logs all levels, INFO - would not log debug level. @logger.level = Logger::DEBUG @logger.formatter = proc do |severity, time, progname, msg| formatted_severity = sprintf("%-5s",severity.to_s) formatted_time = sprintf("[%s]", time.strftime("%Y-%m-%d %H:%M:%S")) date_color ='1;34' severity_color = SEVERITY_TO_COLOR_MAP[severity] background_color = SEVERITY_TO_BACKGROUND_COLOR_MAP[severity] "\033[#{date_color}m#{formatted_time} \033[#{background_color};#{severity_color}m#{formatted_severity}\033[0m-- #{msg.to_s.strip}\n" end end
unknown(method, message)
click to toggle source
# File lib/coloured_logger.rb, line 60 def self.unknown(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.unknown("#{formatted_method}: #{message}") end
warn(method, message)
click to toggle source
# File lib/coloured_logger.rb, line 45 def self.warn(method, message) formatted_method = CLogger.instance.formatted_method(method) CLogger.instance.logger.warn("#{formatted_method}: #{message}") end
Public Instance Methods
formatted_method(method)
click to toggle source
# File lib/coloured_logger.rb, line 29 def formatted_method(method) sprintf("%-20s", method) end