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 |
# File 'lib/asciidoctor/logging.rb', line 42 def initialize 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
47 48 49 50 51 |
# File 'lib/asciidoctor/logging.rb', line 47 def add severity, = nil, progname = nil ||= block_given? ? yield : progname @messages << { severity: SEVERITY_SYMBOL_BY_VALUE[severity || UNKNOWN], message: } true end |
#clear ⇒ Object
53 54 55 |
# File 'lib/asciidoctor/logging.rb', line 53 def clear @messages.clear end |
#empty? ⇒ Boolean
57 58 59 |
# File 'lib/asciidoctor/logging.rb', line 57 def empty? @messages.empty? end |
#max_severity ⇒ Object
61 62 63 |
# File 'lib/asciidoctor/logging.rb', line 61 def max_severity empty? ? nil : @messages.map {|m| Severity.const_get m[:severity] }.max end |