Skip to content

Commit

Permalink
Merge pull request #2307 from jekyll/obey-stevenson
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed May 6, 2014
2 parents 72bb9b3 + 5d827ac commit 0d85592
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 28 deletions.
6 changes: 3 additions & 3 deletions lib/jekyll/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def process(options)
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']
Expand Down Expand Up @@ -70,8 +70,8 @@ def watch(site, options)
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")
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/commands/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def deprecated_relative_permalinks(site)
if page.uses_relative_permalinks
Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" +
" permalinks which will be deprecated in" +
" Jekyll v1.2 and beyond."
" Jekyll v2.0.0 and beyond."
contains_deprecated_pages = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.process(args, options = {})
end
end

puts "New jekyll site installed in #{new_blog_path}."
Jekyll.logger.info "New jekyll site installed in #{new_blog_path}."
end

def self.create_blank_site(path)
Expand Down
3 changes: 1 addition & 2 deletions lib/jekyll/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Configuration < Hash
'future' => true, # remove and make true just default
'unpublished' => false,

'relative_permalinks' => true, # backwards-compatibility with < 1.0
# will be set to false once 2.0 hits
'relative_permalinks' => false,

'markdown' => 'kramdown',
'highlighter' => 'pygments',
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/convertible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def read_yaml(base, name, opts = {})
self.data = SafeYAML.load($1)
end
rescue SyntaxError => e
puts "YAML Exception reading #{File.join(base, name)}: #{e.message}"
Jekyll.logger.warn "YAML Exception reading #{File.join(base, name)}: #{e.message}"
rescue Exception => e
puts "Error reading file #{File.join(base, name)}: #{e.message}"
Jekyll.logger.warn "Error reading file #{File.join(base, name)}: #{e.message}"
end

self.data ||= {}
Expand Down
2 changes: 0 additions & 2 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,11 @@ def aggregate_post_info(post)

def relative_permalinks_deprecation_method
if config['relative_permalinks'] && has_relative_page?
$stderr.puts # Places newline after "Generating..."
Jekyll.logger.warn "Deprecation:", "Starting in 2.0, permalinks for pages" +
" in subfolders must be relative to the" +
" site source directory, not the parent" +
" directory. Check http://jekyllrb.com/docs/upgrading/"+
" for more info."
$stderr.print Jekyll.logger.formatted_topic("") + "..." # for "done."
end
end

Expand Down
33 changes: 23 additions & 10 deletions lib/jekyll/stevenson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,7 +25,7 @@ def initialize(level = INFO)
#
# 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
Expand All @@ -33,7 +35,7 @@ def debug(topic, message = nil)
#
# 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
Expand All @@ -43,7 +45,7 @@ def info(topic, message = nil)
#
# 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
Expand All @@ -53,7 +55,7 @@ def warn(topic, message = nil)
#
# 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
Expand Down Expand Up @@ -85,5 +87,16 @@ def message(topic, message)
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
10 changes: 10 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ def capture_stdout
ensure
$stdout = $old_stdout
end

def capture_stderr
$old_stderr = $stderr
$stderr = StringIO.new
yield
$stderr.rewind
return $stderr.string
ensure
$stderr = $old_stderr
end
end
2 changes: 1 addition & 1 deletion test/source/+/foo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title : Page inside +
permalink: plus+in+url
permalink: /+/plus+in+url
---
Line 1
{{ page.title }}
4 changes: 2 additions & 2 deletions test/test_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/test_convertible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestConvertible < Test::Unit::TestCase

should "not parse if there is syntax error in front-matter" do
name = 'broken_front_matter2.erb'
out = capture_stdout do
out = capture_stderr do
ret = @convertible.read_yaml(@base, name)
assert_equal({}, ret)
end
Expand All @@ -30,15 +30,15 @@ class TestConvertible < Test::Unit::TestCase
end

should "not allow ruby objects in yaml" do
out = capture_stdout do
out = capture_stderr do
@convertible.read_yaml(@base, 'exploit_front_matter.erb')
end
assert_no_match /undefined class\/module DoesNotExist/, out
end

should "not parse if there is encoding error in file" do
name = 'broken_front_matter3.erb'
out = capture_stdout do
out = capture_stderr do
ret = @convertible.read_yaml(@base, name, :encoding => 'utf-8')
assert_equal({}, ret)
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_new_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def site_template

should 'display a success message' do
output = capture_stdout { Jekyll::Commands::New.process(@args) }
success_message = "New jekyll site installed in #{@full_path}.\n"
success_message = "New jekyll site installed in #{@full_path}. \n"
assert_equal success_message, output
end

Expand Down

0 comments on commit 0d85592

Please sign in to comment.