2015-06-10 10:27:27 +00:00
|
|
|
require "logger"
|
2016-09-01 09:15:22 +00:00
|
|
|
require "rainbow"
|
2016-09-01 09:02:19 +00:00
|
|
|
|
2015-06-10 10:27:27 +00:00
|
|
|
module GitHubChangelogGenerator
|
|
|
|
module Helper
|
|
|
|
# @return true if the currently running program is a unit test
|
|
|
|
def self.test?
|
2016-02-23 10:25:55 +00:00
|
|
|
defined? SpecHelper
|
2015-06-10 10:27:27 +00:00
|
|
|
end
|
|
|
|
|
2016-02-23 10:25:55 +00:00
|
|
|
@log ||= if test?
|
|
|
|
Logger.new(nil) # don't show any logs when running tests
|
|
|
|
else
|
|
|
|
Logger.new(STDOUT)
|
|
|
|
end
|
2015-06-10 10:27:27 +00:00
|
|
|
@log.formatter = proc do |severity, _datetime, _progname, msg|
|
|
|
|
string = "#{msg}\n"
|
2016-09-01 09:02:19 +00:00
|
|
|
case severity
|
2016-09-01 09:15:22 +00:00
|
|
|
when "DEBUG" then Rainbow(string).magenta
|
|
|
|
when "INFO" then Rainbow(string).white
|
|
|
|
when "WARN" then Rainbow(string).yellow
|
|
|
|
when "ERROR" then Rainbow(string).red
|
|
|
|
when "FATAL" then Rainbow(string).red.bright
|
2016-09-01 09:02:19 +00:00
|
|
|
else string
|
2015-06-10 10:27:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Logging happens using this method
|
|
|
|
class << self
|
|
|
|
attr_reader :log
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|