commit
6ce345be59
|
@ -23,7 +23,8 @@ module Jekyll
|
||||||
# Build your jekyll site
|
# Build your jekyll site
|
||||||
# Continuously watch if `watch` is set to true in the config.
|
# Continuously watch if `watch` is set to true in the config.
|
||||||
def process(options)
|
def process(options)
|
||||||
Jekyll.logger.log_level = :error if options['quiet']
|
# Adjust verbosity quickly
|
||||||
|
Jekyll.logger.adjust_verbosity(options)
|
||||||
|
|
||||||
options = configuration_from_options(options)
|
options = configuration_from_options(options)
|
||||||
site = Jekyll::Site.new(options)
|
site = Jekyll::Site.new(options)
|
||||||
|
|
|
@ -54,6 +54,7 @@ module Jekyll
|
||||||
'timezone' => nil, # use the local timezone
|
'timezone' => nil, # use the local timezone
|
||||||
|
|
||||||
'quiet' => false,
|
'quiet' => false,
|
||||||
|
'verbose' => false,
|
||||||
'defaults' => [],
|
'defaults' => [],
|
||||||
|
|
||||||
'rdiscount' => {
|
'rdiscount' => {
|
||||||
|
@ -90,18 +91,28 @@ module Jekyll
|
||||||
reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
|
reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_config_value_with_override(config_key, override)
|
||||||
|
override[config_key] || self[config_key] || DEFAULTS[config_key]
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Directory of the Jekyll source folder
|
# Public: Directory of the Jekyll source folder
|
||||||
#
|
#
|
||||||
# override - the command-line options hash
|
# override - the command-line options hash
|
||||||
#
|
#
|
||||||
# Returns the path to the Jekyll source directory
|
# Returns the path to the Jekyll source directory
|
||||||
def source(override)
|
def source(override)
|
||||||
override['source'] || self['source'] || DEFAULTS['source']
|
get_config_value_with_override('source', override)
|
||||||
end
|
end
|
||||||
|
|
||||||
def quiet?(override = {})
|
def quiet(override = {})
|
||||||
override['quiet'] || self['quiet'] || DEFAULTS['quiet']
|
get_config_value_with_override('quiet', override)
|
||||||
end
|
end
|
||||||
|
alias_method :quiet?, :quiet
|
||||||
|
|
||||||
|
def verbose(override = {})
|
||||||
|
get_config_value_with_override('verbose', override)
|
||||||
|
end
|
||||||
|
alias_method :verbose?, :verbose
|
||||||
|
|
||||||
def safe_load_file(filename)
|
def safe_load_file(filename)
|
||||||
case File.extname(filename)
|
case File.extname(filename)
|
||||||
|
@ -121,8 +132,8 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns an Array of config files
|
# Returns an Array of config files
|
||||||
def config_files(override)
|
def config_files(override)
|
||||||
# Be quiet quickly.
|
# Adjust verbosity quickly
|
||||||
Jekyll.logger.log_level = :error if quiet?(override)
|
Jekyll.logger.adjust_verbosity(:quiet => quiet?(override), :verbose => verbose?(override))
|
||||||
|
|
||||||
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
||||||
config_files = override.delete('config')
|
config_files = override.delete('config')
|
||||||
|
|
|
@ -30,6 +30,16 @@ module Jekyll
|
||||||
writer.level = LOG_LEVELS.fetch(level)
|
writer.level = LOG_LEVELS.fetch(level)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def adjust_verbosity(options = {})
|
||||||
|
# Quiet always wins.
|
||||||
|
if options[:quiet]
|
||||||
|
self.log_level = :error
|
||||||
|
elsif options[:verbose]
|
||||||
|
self.log_level = :debug
|
||||||
|
end
|
||||||
|
debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Print a debug message
|
# Public: Print a debug message
|
||||||
#
|
#
|
||||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
|
|
|
@ -18,6 +18,42 @@ class TestLogAdapter < JekyllUnitTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#adjust_verbosity" do
|
||||||
|
should "set the writers logging level to error when quiet" do
|
||||||
|
subject = Jekyll::LogAdapter.new(LoggerDouble.new)
|
||||||
|
subject.adjust_verbosity(:quiet => true)
|
||||||
|
assert_equal Jekyll::LogAdapter::LOG_LEVELS[:error], subject.writer.level
|
||||||
|
end
|
||||||
|
|
||||||
|
should "set the writers logging level to debug when verbose" do
|
||||||
|
subject = Jekyll::LogAdapter.new(LoggerDouble.new)
|
||||||
|
subject.adjust_verbosity(:verbose => true)
|
||||||
|
assert_equal Jekyll::LogAdapter::LOG_LEVELS[:debug], subject.writer.level
|
||||||
|
end
|
||||||
|
|
||||||
|
should "set the writers logging level to error when quiet and verbose are both set" do
|
||||||
|
subject = Jekyll::LogAdapter.new(LoggerDouble.new)
|
||||||
|
subject.adjust_verbosity(:quiet => true, :verbose => true)
|
||||||
|
assert_equal Jekyll::LogAdapter::LOG_LEVELS[:error], subject.writer.level
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not change the writer's logging level when neither verbose or quiet" do
|
||||||
|
subject = Jekyll::LogAdapter.new(LoggerDouble.new)
|
||||||
|
original_level = subject.writer.level
|
||||||
|
refute_equal Jekyll::LogAdapter::LOG_LEVELS[:error], subject.writer.level
|
||||||
|
refute_equal Jekyll::LogAdapter::LOG_LEVELS[:debug], subject.writer.level
|
||||||
|
subject.adjust_verbosity(:quiet => false, :verbose => false)
|
||||||
|
assert_equal original_level, subject.writer.level
|
||||||
|
end
|
||||||
|
|
||||||
|
should "call #debug on writer return true" do
|
||||||
|
writer = LoggerDouble.new
|
||||||
|
logger = Jekyll::LogAdapter.new(writer)
|
||||||
|
allow(writer).to receive(:debug).and_return(true)
|
||||||
|
assert logger.adjust_verbosity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "#debug" do
|
context "#debug" do
|
||||||
should "call #debug on writer return true" do
|
should "call #debug on writer return true" do
|
||||||
writer = LoggerDouble.new
|
writer = LoggerDouble.new
|
||||||
|
|
Loading…
Reference in New Issue