Class: Jekyll::LogAdapter
- Inherits:
-
Object
- Object
- Jekyll::LogAdapter
- Defined in:
- lib/jekyll/log_adapter.rb
Constant Summary collapse
- LOG_LEVELS =
{ :debug => ::Logger::DEBUG, :info => ::Logger::INFO, :warn => ::Logger::WARN, :error => ::Logger::ERROR }
Instance Attribute Summary collapse
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
-
#abort_with(topic, message = nil) ⇒ Object
Public: Print a Jekyll error message and immediately abort the process.
-
#debug(topic, message = nil) ⇒ Object
Public: Print a jekyll debug message.
-
#error(topic, message = nil) ⇒ Object
Public: Print a jekyll error message.
-
#formatted_topic(topic) ⇒ Object
Internal: Format the topic.
-
#info(topic, message = nil) ⇒ Object
Public: Print a jekyll message.
-
#initialize(writer, level = :info) ⇒ LogAdapter
constructor
Public: Create a new instance of Jekyll’s log writer.
-
#log_level=(level) ⇒ Object
Public: Set the log level on the writer.
-
#message(topic, message) ⇒ Object
Internal: Build a Jekyll topic method.
-
#warn(topic, message = nil) ⇒ Object
Public: Print a jekyll message.
Constructor Details
#initialize(writer, level = :info) ⇒ LogAdapter
Public: Create a new instance of Jekyll’s log writer
writer - Logger compatible instance log_level - (optional, symbol) the log level
Returns nothing
18 19 20 21 |
# File 'lib/jekyll/log_adapter.rb', line 18 def initialize(writer, level = :info) @writer = writer self.log_level = level end |
Instance Attribute Details
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
3 4 5 |
# File 'lib/jekyll/log_adapter.rb', line 3 def writer @writer end |
Instance Method Details
#abort_with(topic, message = nil) ⇒ Object
Public: Print a Jekyll error message 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
78 79 80 81 |
# File 'lib/jekyll/log_adapter.rb', line 78 def abort_with(topic, = nil) error(topic, ) abort end |
#debug(topic, message = nil) ⇒ Object
Public: Print a jekyll debug message
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
38 39 40 |
# File 'lib/jekyll/log_adapter.rb', line 38 def debug(topic, = nil) writer.debug((topic, )) end |
#error(topic, message = nil) ⇒ Object
Public: Print a jekyll error message
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
68 69 70 |
# File 'lib/jekyll/log_adapter.rb', line 68 def error(topic, = nil) writer.error((topic, )) end |
#formatted_topic(topic) ⇒ Object
Internal: Format the topic
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc.
Returns the formatted topic statement
98 99 100 |
# File 'lib/jekyll/log_adapter.rb', line 98 def formatted_topic(topic) "#{topic} ".rjust(20) end |
#info(topic, message = nil) ⇒ Object
Public: Print a jekyll message
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
48 49 50 |
# File 'lib/jekyll/log_adapter.rb', line 48 def info(topic, = nil) writer.info((topic, )) end |
#log_level=(level) ⇒ Object
Public: Set the log level on the writer
level - (symbol) the log level
Returns nothing
28 29 30 |
# File 'lib/jekyll/log_adapter.rb', line 28 def log_level=(level) writer.level = LOG_LEVELS.fetch(level) end |
#message(topic, message) ⇒ Object
Internal: 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
89 90 91 |
# File 'lib/jekyll/log_adapter.rb', line 89 def (topic, ) formatted_topic(topic) + .to_s.gsub(/\s+/, ' ') end |
#warn(topic, message = nil) ⇒ Object
Public: Print a jekyll message
topic - the topic of the message, e.g. “Configuration file”, “Deprecation”, etc. message - the message detail
Returns nothing
58 59 60 |
# File 'lib/jekyll/log_adapter.rb', line 58 def warn(topic, = nil) writer.warn((topic, )) end |