Class: Kramdown::PlantUml::LogWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-plantuml/log_wrapper.rb

Overview

Logs stuff

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ LogWrapper

Returns a new instance of LogWrapper.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 10

def initialize(logger)
  raise ArgumentError, 'logger cannot be nil' if logger.nil?
  raise ArgumentError, 'logger must respond to #debug' unless logger.respond_to? :debug
  raise ArgumentError, 'logger must respond to #info' unless logger.respond_to? :info
  raise ArgumentError, 'logger must respond to #warn' unless logger.respond_to? :warn
  raise ArgumentError, 'logger must respond to #error' unless logger.respond_to? :error

  @logger = logger
end

Class Method Details

.initObject



54
55
56
57
58
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 54

def init
  inner = JekyllProvider.jekyll ? JekyllProvider.jekyll.logger : nil
  inner ||= ConsoleLogger.new(level)
  new inner
end

.levelObject



60
61
62
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 60

def level
  @level ||= level_from_env
end

Instance Method Details

#debug(message) ⇒ Object



20
21
22
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 20

def debug(message)
  write :debug, message
end

#debug?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 45

def debug?
  self.class.level == :debug
end

#debug_multiline(multiline_string) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 24

def debug_multiline(multiline_string)
  return if multiline_string.nil? || multiline_string.empty?

  lines = multiline_string.lines
  lines.each do |line|
    write :debug, line.rstrip
  end
end

#error(message) ⇒ Object



41
42
43
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 41

def error(message)
  write :error, message
end

#info(message) ⇒ Object



33
34
35
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 33

def info(message)
  write :info, message
end

#levelObject



49
50
51
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 49

def level
  @level ||= level_from_logger || self.class.env
end

#warn(message) ⇒ Object



37
38
39
# File 'lib/kramdown-plantuml/log_wrapper.rb', line 37

def warn(message)
  write :warn, message
end