Class: Asciidoctor::MemoryLogger
- Inherits:
-
Logger
- Object
- Logger
- Asciidoctor::MemoryLogger
- Defined in:
- lib/asciidoctor/logging.rb
Constant Summary collapse
- SEVERITY_SYMBOL_BY_VALUE =
(Severity.constants false).map {|c| [(Severity.const_get c), c] }.to_h
Instance Attribute Summary collapse
- #messages ⇒ Object readonly
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil) ⇒ Object
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ MemoryLogger
constructor
A new instance of MemoryLogger.
- #max_severity ⇒ Object
Constructor Details
#initialize ⇒ MemoryLogger
Returns a new instance of MemoryLogger.
42 43 44 45 46 |
# File 'lib/asciidoctor/logging.rb', line 42 def initialize super nil self.level = WARN @messages = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
40 41 42 |
# File 'lib/asciidoctor/logging.rb', line 40 def @messages end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/asciidoctor/logging.rb', line 48 def add severity, = nil, progname = nil ||= block_given? ? yield : progname @messages << { severity: SEVERITY_SYMBOL_BY_VALUE[severity || UNKNOWN], message: } true end |
#clear ⇒ Object
54 55 56 |
# File 'lib/asciidoctor/logging.rb', line 54 def clear @messages.clear end |
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/asciidoctor/logging.rb', line 58 def empty? @messages.empty? end |
#max_severity ⇒ Object
62 63 64 |
# File 'lib/asciidoctor/logging.rb', line 62 def max_severity empty? ? nil : @messages.map {|m| Severity.const_get m[:severity] }.max end |