Module: Logging
- Defined in:
- lib/canuby/util.rb
Overview
Canuby’s Logger
Class Method Summary collapse
Class Method Details
.log(severity, datetime, progname, msg) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/canuby/util.rb', line 49 def self.log(severity, datetime, progname, msg) date_format = "[#{datetime.strftime('%d-%m-%Y %H:%M:%S,%L')}]".magenta # color needs to be set before \n or it will leak into the console case severity when 'DEBUG' "#{date_format} #{severity} (#{progname}): #{msg}".cyan + "\n" when 'INFO' "#{date_format} #{severity.yellow} (#{progname}): #{msg}" + "\n" when 'WARN' "#{date_format} #{severity.red} (#{progname}): #{msg}" + "\n" when 'ERROR' "#{date_format} #{severity} (#{progname}): #{msg}".red + "\n" end end |
.logger ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/canuby/util.rb', line 64 def self.logger @logger = Logger.new($stdout) @logger.level = if ENV['CI'] == 'true' || ENV['Testing'] == 'true' Logger::WARN elsif ENV['DEBUG'] == 'true' Logger::DEBUG else Logger::INFO end @logger.formatter = proc do |severity, datetime, progname, msg| log(severity, datetime, progname, msg) end @logger end |