Class: Jekyll::Stevenson

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/stevenson.rb

Constant Summary collapse

DEBUG =
0
INFO =
1
WARN =
2
ERROR =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = INFO) ⇒ Stevenson

Public: Create a new instance of Stevenson, Jekyll’s logger

level - (optional, integer) the log level

Returns nothing



15
16
17
# File 'lib/jekyll/stevenson.rb', line 15

def initialize(level = INFO)
  @log_level = level
end

Instance Attribute Details

#log_levelObject

Returns the value of attribute log_level.



3
4
5
# File 'lib/jekyll/stevenson.rb', line 3

def log_level
  @log_level
end

Instance Method Details

#abort_with(topic, message = nil) ⇒ Object

Public: Print a Jekyll error message to stderr and immediately abort the process

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail (can be omitted)

Returns nothing



65
66
67
68
# File 'lib/jekyll/stevenson.rb', line 65

def abort_with(topic, message = nil)
  error(topic, message)
  abort
end

#debug(topic, message = nil) ⇒ Object

Public: Print a jekyll debug message to stdout

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail

Returns nothing



25
26
27
# File 'lib/jekyll/stevenson.rb', line 25

def debug(topic, message = nil)
  $stdout.puts(message(topic, message)) if log_level <= DEBUG
end

#error(topic, message = nil) ⇒ Object

Public: Print a jekyll error message to stderr

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail

Returns nothing



55
56
57
# File 'lib/jekyll/stevenson.rb', line 55

def error(topic, message = nil)
  $stderr.puts(message(topic, message).red) if log_level <= ERROR
end

#formatted_topic(topic) ⇒ Object

Public: Format the topic

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc.

Returns the formatted topic statement



85
86
87
# File 'lib/jekyll/stevenson.rb', line 85

def formatted_topic(topic)
  "#{topic} ".rjust(20)
end

#info(topic, message = nil) ⇒ Object

Public: Print a jekyll message to stdout

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail

Returns nothing



35
36
37
# File 'lib/jekyll/stevenson.rb', line 35

def info(topic, message = nil)
  $stdout.puts(message(topic, message)) if log_level <= INFO
end

#message(topic, message) ⇒ Object

Public: Build a Jekyll topic method

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail

Returns the formatted message



76
77
78
# File 'lib/jekyll/stevenson.rb', line 76

def message(topic, message)
  formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ')
end

#warn(topic, message = nil) ⇒ Object

Public: Print a jekyll message to stderr

topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail

Returns nothing



45
46
47
# File 'lib/jekyll/stevenson.rb', line 45

def warn(topic, message = nil)
  $stderr.puts(message(topic, message).yellow) if log_level <= WARN
end