Stevenson now uses symbols instead of integers to set log level

This commit is contained in:
Parker Moore 2014-05-06 13:03:56 -04:00
parent 63e959e4e1
commit 2aa8908948
3 changed files with 28 additions and 15 deletions

View File

@ -25,7 +25,7 @@ module Jekyll
options = configuration_from_options(options)
site = Jekyll::Site.new(options)
Jekyll.logger.log_level = Jekyll::Stevenson::ERROR if options['quiet']
Jekyll.logger.log_level = :error if options['quiet']
build(site, options)
watch(site, options) if options['watch']
@ -70,8 +70,8 @@ module Jekyll
Jekyll.logger.info "Auto-regeneration:", "enabled"
listener = Listen.to(
source,
:ignore => ignored,
source,
:ignore => ignored,
:force_polling => options['force_polling']
) do |modified, added, removed|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")

View File

@ -2,17 +2,19 @@ module Jekyll
class Stevenson
attr_accessor :log_level
DEBUG = 0
INFO = 1
WARN = 2
ERROR = 3
LOG_LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3
}
# Public: Create a new instance of Stevenson, Jekyll's logger
#
# level - (optional, integer) the log level
# level - (optional, symbol) the log level
#
# Returns nothing
def initialize(level = INFO)
def initialize(level = :info)
@log_level = level
end
@ -23,7 +25,7 @@ module Jekyll
#
# Returns nothing
def debug(topic, message = nil)
$stdout.puts(message(topic, message)) if log_level <= DEBUG
$stdout.puts(message(topic, message)) if should_log(:debug)
end
# Public: Print a jekyll message to stdout
@ -33,7 +35,7 @@ module Jekyll
#
# Returns nothing
def info(topic, message = nil)
$stdout.puts(message(topic, message)) if log_level <= INFO
$stdout.puts(message(topic, message)) if should_log(:info)
end
# Public: Print a jekyll message to stderr
@ -43,7 +45,7 @@ module Jekyll
#
# Returns nothing
def warn(topic, message = nil)
$stderr.puts(message(topic, message).yellow) if log_level <= WARN
$stderr.puts(message(topic, message).yellow) if should_log(:warn)
end
# Public: Print a jekyll error message to stderr
@ -53,7 +55,7 @@ module Jekyll
#
# Returns nothing
def error(topic, message = nil)
$stderr.puts(message(topic, message).red) if log_level <= ERROR
$stderr.puts(message(topic, message).red) if should_log(:error)
end
# Public: Print a Jekyll error message to stderr and immediately abort the process
@ -85,5 +87,16 @@ module Jekyll
def formatted_topic(topic)
"#{topic} ".rjust(20)
end
# Public: Determine whether the current log level warrants logging at the
# proposed level.
#
# level_of_message - the log level of the message (symbol)
#
# Returns true if the log level of the message is greater than or equal to
# this logger's log level.
def should_log(level_of_message)
LOG_LEVELS.fetch(log_level) <= LOG_LEVELS.fetch(level_of_message)
end
end
end

View File

@ -166,9 +166,9 @@ class TestConfiguration < Test::Unit::TestCase
end
should "successfully load a TOML file" do
Jekyll.logger.log_level = Jekyll::Stevenson::WARN
Jekyll.logger.log_level = :warn
assert_equal Jekyll::Configuration::DEFAULTS.merge({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }), Jekyll.configuration({ "config" => [@paths[:toml]] })
Jekyll.logger.log_level = Jekyll::Stevenson::INFO
Jekyll.logger.log_level = :info
end
should "load multiple config files" do