Merge pull request #1149 from mojombo/jekyll-logger
Use Jekyll.logger instead of Jekyll::Stevenson to log things
This commit is contained in:
commit
21c153a8df
|
@ -87,4 +87,8 @@ module Jekyll
|
||||||
def self.set_timezone(timezone)
|
def self.set_timezone(timezone)
|
||||||
ENV['TZ'] = timezone
|
ENV['TZ'] = timezone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.logger
|
||||||
|
@logger ||= Stevenson.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,9 +18,9 @@ module Jekyll
|
||||||
site.process
|
site.process
|
||||||
rescue Jekyll::FatalException => e
|
rescue Jekyll::FatalException => e
|
||||||
puts
|
puts
|
||||||
Jekyll::Stevenson.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
Jekyll.logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
|
||||||
Jekyll::Stevenson.error "", "------------------------------------"
|
Jekyll.logger.error "", "------------------------------------"
|
||||||
Jekyll::Stevenson.error "", e.message
|
Jekyll.logger.error "", e.message
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,9 +17,9 @@ module Jekyll
|
||||||
def self.build(site, options)
|
def self.build(site, options)
|
||||||
source = options['source']
|
source = options['source']
|
||||||
destination = options['destination']
|
destination = options['destination']
|
||||||
Jekyll::Stevenson.info "Source:", source
|
Jekyll.logger.info "Source:", source
|
||||||
Jekyll::Stevenson.info "Destination:", destination
|
Jekyll.logger.info "Destination:", destination
|
||||||
print Jekyll::Stevenson.formatted_topic "Generating..."
|
print Jekyll.logger.formatted_topic "Generating..."
|
||||||
self.process_site(site)
|
self.process_site(site)
|
||||||
puts "done."
|
puts "done."
|
||||||
end
|
end
|
||||||
|
@ -36,14 +36,14 @@ module Jekyll
|
||||||
source = options['source']
|
source = options['source']
|
||||||
destination = options['destination']
|
destination = options['destination']
|
||||||
|
|
||||||
Jekyll::Stevenson.info "Auto-regeneration:", "enabled"
|
Jekyll.logger.info "Auto-regeneration:", "enabled"
|
||||||
|
|
||||||
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
||||||
dw.interval = 1
|
dw.interval = 1
|
||||||
|
|
||||||
dw.add_observer do |*args|
|
dw.add_observer do |*args|
|
||||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print Jekyll::Stevenson.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
|
print Jekyll.logger.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
|
||||||
self.process_site(site)
|
self.process_site(site)
|
||||||
puts "...done."
|
puts "...done."
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Jekyll
|
||||||
site.read
|
site.read
|
||||||
|
|
||||||
unless deprecated_relative_permalinks(site)
|
unless deprecated_relative_permalinks(site)
|
||||||
Jekyll::Stevenson.info "Your test results", "are in. Everything looks fine."
|
Jekyll.logger.info "Your test results", "are in. Everything looks fine."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ module Jekyll
|
||||||
contains_deprecated_pages = false
|
contains_deprecated_pages = false
|
||||||
site.pages.each do |page|
|
site.pages.each do |page|
|
||||||
if page.uses_relative_permalinks
|
if page.uses_relative_permalinks
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "'#{page.path}' uses relative" +
|
Jekyll.logger.warn "Deprecation:", "'#{page.path}' uses relative" +
|
||||||
" permalinks which will be deprecated in" +
|
" permalinks which will be deprecated in" +
|
||||||
" Jekyll v1.1 and beyond."
|
" Jekyll v1.1 and beyond."
|
||||||
contains_deprecated_pages = true
|
contains_deprecated_pages = true
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Jekyll
|
||||||
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
new_blog_path = File.expand_path(args.join(" "), Dir.pwd)
|
||||||
FileUtils.mkdir_p new_blog_path
|
FileUtils.mkdir_p new_blog_path
|
||||||
if preserve_source_location?(new_blog_path, options)
|
if preserve_source_location?(new_blog_path, options)
|
||||||
Jekyll::Stevenson.error "Conflict:", "#{new_blog_path} exists and is not empty."
|
Jekyll.logger.error "Conflict:", "#{new_blog_path} exists and is not empty."
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ module Jekyll
|
||||||
def read_config_file(file)
|
def read_config_file(file)
|
||||||
next_config = YAML.safe_load_file(file)
|
next_config = YAML.safe_load_file(file)
|
||||||
raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash)
|
raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash)
|
||||||
Jekyll::Stevenson.info "Configuration file:", file
|
Jekyll.logger.info "Configuration file:", file
|
||||||
next_config
|
next_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -135,9 +135,9 @@ module Jekyll
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
# Errno:ENOENT = file not found
|
# Errno:ENOENT = file not found
|
||||||
Jekyll::Stevenson.warn "Configuration file:", "none"
|
Jekyll.logger.warn "Configuration file:", "none"
|
||||||
rescue => err
|
rescue => err
|
||||||
Jekyll::Stevenson.warn "WARNING:", "Error reading configuration. " +
|
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
||||||
"Using defaults (and options)."
|
"Using defaults (and options)."
|
||||||
$stderr.puts "#{err}"
|
$stderr.puts "#{err}"
|
||||||
end
|
end
|
||||||
|
@ -162,7 +162,7 @@ module Jekyll
|
||||||
config = clone
|
config = clone
|
||||||
# Provide backwards-compatibility
|
# Provide backwards-compatibility
|
||||||
if config.has_key?('auto') || config.has_key?('watch')
|
if config.has_key?('auto') || config.has_key?('watch')
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "Auto-regeneration can no longer" +
|
Jekyll.logger.warn "Deprecation:", "Auto-regeneration can no longer" +
|
||||||
" be set from your configuration file(s). Use the"+
|
" be set from your configuration file(s). Use the"+
|
||||||
" --watch/-w command-line option instead."
|
" --watch/-w command-line option instead."
|
||||||
config.delete('auto')
|
config.delete('auto')
|
||||||
|
@ -170,14 +170,14 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.has_key? 'server'
|
if config.has_key? 'server'
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "The 'server' configuration option" +
|
Jekyll.logger.warn "Deprecation:", "The 'server' configuration option" +
|
||||||
" is no longer accepted. Use the 'jekyll serve'" +
|
" is no longer accepted. Use the 'jekyll serve'" +
|
||||||
" subcommand to serve your site with WEBrick."
|
" subcommand to serve your site with WEBrick."
|
||||||
config.delete('server')
|
config.delete('server')
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.has_key? 'server_port'
|
if config.has_key? 'server_port'
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "The 'server_port' configuration option" +
|
Jekyll.logger.warn "Deprecation:", "The 'server_port' configuration option" +
|
||||||
" has been renamed to 'port'. Please update your config" +
|
" has been renamed to 'port'. Please update your config" +
|
||||||
" file accordingly."
|
" file accordingly."
|
||||||
# copy but don't overwrite:
|
# copy but don't overwrite:
|
||||||
|
@ -186,7 +186,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.has_key?('exclude') && config['exclude'].is_a?(String)
|
if config.has_key?('exclude') && config['exclude'].is_a?(String)
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "The 'exclude' configuration option" +
|
Jekyll.logger.warn "Deprecation:", "The 'exclude' configuration option" +
|
||||||
" must now be specified as an array, but you specified" +
|
" must now be specified as an array, but you specified" +
|
||||||
" a string. For now, we've treated the string you provided" +
|
" a string. For now, we've treated the string you provided" +
|
||||||
" as a list of comma-separated values."
|
" as a list of comma-separated values."
|
||||||
|
@ -194,7 +194,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
if config.has_key?('include') && config['include'].is_a?(String)
|
if config.has_key?('include') && config['include'].is_a?(String)
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "The 'include' configuration option" +
|
Jekyll.logger.warn "Deprecation:", "The 'include' configuration option" +
|
||||||
" must now be specified as an array, but you specified" +
|
" must now be specified as an array, but you specified" +
|
||||||
" a string. For now, we've treated the string you provided" +
|
" a string. For now, we've treated the string you provided" +
|
||||||
" as a list of comma-separated values."
|
" as a list of comma-separated values."
|
||||||
|
|
|
@ -76,7 +76,7 @@ module Jekyll
|
||||||
def render_liquid(content, payload, info)
|
def render_liquid(content, payload, info)
|
||||||
Liquid::Template.parse(content).render!(payload, info)
|
Liquid::Template.parse(content).render!(payload, info)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Jekyll::Stevenson.error "Liquid Exception:", "#{e.message} in #{payload[:file]}"
|
Jekyll.logger.error "Liquid Exception:", "#{e.message} in #{payload[:file]}"
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,14 @@ module Jekyll
|
||||||
|
|
||||||
def self.no_subcommand(args)
|
def self.no_subcommand(args)
|
||||||
if args.size > 0 && args.first =~ /^--/ && !%w[--help --version].include?(args.first)
|
if args.size > 0 && args.first =~ /^--/ && !%w[--help --version].include?(args.first)
|
||||||
Jekyll::Stevenson.error "Deprecation:", "Jekyll now uses subcommands instead of just \
|
Jekyll.logger.error "Deprecation:", "Jekyll now uses subcommands instead of just \
|
||||||
switches. Run `jekyll help' to find out more."
|
switches. Run `jekyll help' to find out more."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.deprecation_message(args, deprecated_argument, message)
|
def self.deprecation_message(args, deprecated_argument, message)
|
||||||
if args.include?(deprecated_argument)
|
if args.include?(deprecated_argument)
|
||||||
Jekyll::Stevenson.error "Deprecation:", message
|
Jekyll.logger.error "Deprecation:", message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -156,7 +156,7 @@ module Jekyll
|
||||||
when String
|
when String
|
||||||
Time.parse(input)
|
Time.parse(input)
|
||||||
else
|
else
|
||||||
Jekyll::Stevenson.error "Invalid Date:", "'#{input}' is not a valid datetime."
|
Jekyll.logger.error "Invalid Date:", "'#{input}' is not a valid datetime."
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,7 @@ module Jekyll
|
||||||
|
|
||||||
def display(output)
|
def display(output)
|
||||||
$stdout.print("\n")
|
$stdout.print("\n")
|
||||||
$stdout.print(Jekyll::Stevenson.formatted_topic(output))
|
$stdout.print(Jekyll.logger.formatted_topic(output))
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -421,12 +421,12 @@ module Jekyll
|
||||||
def relative_permalinks_deprecation_method
|
def relative_permalinks_deprecation_method
|
||||||
if config['relative_permalinks'] && !@deprecated_relative_permalinks
|
if config['relative_permalinks'] && !@deprecated_relative_permalinks
|
||||||
$stderr.puts # Places newline after "Generating..."
|
$stderr.puts # Places newline after "Generating..."
|
||||||
Jekyll::Stevenson.warn "Deprecation:", "Starting in 1.1, permalinks for pages" +
|
Jekyll.logger.warn "Deprecation:", "Starting in 1.1, permalinks for pages" +
|
||||||
" in subfolders must be relative to the" +
|
" in subfolders must be relative to the" +
|
||||||
" site source directory, not the parent" +
|
" site source directory, not the parent" +
|
||||||
" directory. Check http://jekyllrb.com/docs/upgrading/"+
|
" directory. Check http://jekyllrb.com/docs/upgrading/"+
|
||||||
" for more info."
|
" for more info."
|
||||||
$stderr.print Jekyll::Stevenson.formatted_topic("") + "..." # for "done."
|
$stderr.print Jekyll.logger.formatted_topic("") + "..." # for "done."
|
||||||
@deprecated_relative_permalinks = true
|
@deprecated_relative_permalinks = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,29 @@
|
||||||
require 'logger'
|
|
||||||
|
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class Stevenson
|
class Stevenson
|
||||||
|
attr_accessor :log_level
|
||||||
|
|
||||||
|
DEBUG = 0
|
||||||
|
INFO = 1
|
||||||
|
WARN = 2
|
||||||
|
ERRROR = 3
|
||||||
|
|
||||||
|
# Public: Create a new instance of Stevenson, Jekyll's logger
|
||||||
|
#
|
||||||
|
# level - (optional, integer) the log level
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def initialize(level = INFO)
|
||||||
|
@log_level = level
|
||||||
|
end
|
||||||
|
|
||||||
# Public: Print a jekyll message to stdout
|
# Public: Print a jekyll message to stdout
|
||||||
#
|
#
|
||||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
# message - the message detail
|
# message - the message detail
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def self.info(topic, message)
|
def info(topic, message)
|
||||||
$stdout.puts message(topic, message)
|
$stdout.puts(message(topic, message)) if log_level <= INFO
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Print a jekyll message to stderr
|
# Public: Print a jekyll message to stderr
|
||||||
|
@ -18,8 +32,8 @@ module Jekyll
|
||||||
# message - the message detail
|
# message - the message detail
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def self.warn(topic, message)
|
def warn(topic, message)
|
||||||
$stderr.puts message(topic, message).yellow
|
$stderr.puts(message(topic, message).yellow) if log_level <= WARN
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Print a jekyll error message to stderr
|
# Public: Print a jekyll error message to stderr
|
||||||
|
@ -28,8 +42,8 @@ module Jekyll
|
||||||
# message - the message detail
|
# message - the message detail
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# Returns nothing
|
||||||
def self.error(topic, message)
|
def error(topic, message)
|
||||||
$stderr.puts message(topic, message).red
|
$stderr.puts(message(topic, message).red) if log_level <= ERROR
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Build a Jekyll topic method
|
# Public: Build a Jekyll topic method
|
||||||
|
@ -38,7 +52,7 @@ module Jekyll
|
||||||
# message - the message detail
|
# message - the message detail
|
||||||
#
|
#
|
||||||
# Returns the formatted message
|
# Returns the formatted message
|
||||||
def self.message(topic, message)
|
def message(topic, message)
|
||||||
formatted_topic(topic) + message.gsub(/\s+/, ' ')
|
formatted_topic(topic) + message.gsub(/\s+/, ' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +61,7 @@ module Jekyll
|
||||||
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
||||||
#
|
#
|
||||||
# Returns the formatted topic statement
|
# Returns the formatted topic statement
|
||||||
def self.formatted_topic(topic)
|
def formatted_topic(topic)
|
||||||
"#{topic} ".rjust(20)
|
"#{topic} ".rjust(20)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue