Class: Jekyll::LogAdapter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
22
# File 'lib/jekyll/log_adapter.rb', line 18

def initialize(writer, level = :info)
  @messages = []
  @writer = writer
  self.log_level = level
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages


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

def messages
  @messages
end

#writerObject (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


79
80
81
82
# File 'lib/jekyll/log_adapter.rb', line 79

def abort_with(topic, message = nil)
  error(topic, message)
  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


39
40
41
# File 'lib/jekyll/log_adapter.rb', line 39

def debug(topic, message = nil)
  writer.debug(message(topic, message))
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


69
70
71
# File 'lib/jekyll/log_adapter.rb', line 69

def error(topic, message = nil)
  writer.error(message(topic, message))
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


101
102
103
# File 'lib/jekyll/log_adapter.rb', line 101

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


49
50
51
# File 'lib/jekyll/log_adapter.rb', line 49

def info(topic, message = nil)
  writer.info(message(topic, message))
end

#log_level=(level) ⇒ Object

Public: Set the log level on the writer

level - (symbol) the log level

Returns nothing


29
30
31
# File 'lib/jekyll/log_adapter.rb', line 29

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


90
91
92
93
94
# File 'lib/jekyll/log_adapter.rb', line 90

def message(topic, message)
  msg = formatted_topic(topic) + message.to_s.gsub(/\s+/, ' ')
  messages << msg
  msg
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


59
60
61
# File 'lib/jekyll/log_adapter.rb', line 59

def warn(topic, message = nil)
  writer.warn(message(topic, message))
end