Class: Asciidoctor::MemoryLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/asciidoctor/logging.rb

Constant Summary collapse

SEVERITY_LABELS =
{}.tap {|accum| (Severity.constants false).each {|c| accum[Severity.const_get c, false] = c } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryLogger

Returns a new instance of MemoryLogger.



42
43
44
45
# File 'lib/asciidoctor/logging.rb', line 42

def initialize
  self.level = WARN
  @messages = []
end

Instance Attribute Details

#messagesObject (readonly)



40
41
42
# File 'lib/asciidoctor/logging.rb', line 40

def messages
  @messages
end

Instance Method Details

#add(severity, message = nil, progname = nil) ⇒ Object



47
48
49
50
51
# File 'lib/asciidoctor/logging.rb', line 47

def add severity, message = nil, progname = nil
  message = block_given? ? yield : progname unless message
  @messages << { severity: SEVERITY_LABELS[severity || UNKNOWN], message: message }
  true
end

#clearObject



53
54
55
# File 'lib/asciidoctor/logging.rb', line 53

def clear
  @messages.clear
end

#empty?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/asciidoctor/logging.rb', line 57

def empty?
  @messages.empty?
end

#max_severityObject



61
62
63
# File 'lib/asciidoctor/logging.rb', line 61

def max_severity
  empty? ? nil : @messages.map {|m| Severity.const_get m[:severity], false }.max
end