github-changelog-generator/lib/github_changelog_generator/helper.rb

38 lines
910 B
Ruby
Raw Permalink Normal View History

2016-09-22 17:16:29 +00:00
# frozen_string_literal: true
require "logger"
require "rainbow"
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
end
2016-09-27 20:08:18 +00:00
# :nocov:
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
@log.formatter = proc do |severity, _datetime, _progname, msg|
string = "#{msg}\n"
case severity
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
else string
end
end
2016-09-27 20:08:18 +00:00
# :nocov:
# Logging happens using this method
class << self
attr_reader :log
end
end
end