Class: Asciidoctor::MemoryLogger
- Inherits:
-
Logger
- Object
- Logger
- Asciidoctor::MemoryLogger
- 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
- #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 unless @messages << { severity: SEVERITY_LABELS[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], false }.max end |