Class: Loog::Buffer

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

Overview

Accumulator of everything. This class may be used for testing, when it’s necessary to accumulate all log messages in one place and then “assert” the presence of certain strings inside them.

Instance Method Summary collapse

Constructor Details

#initialize(formatter: Loog::SHORT) ⇒ Buffer

Returns a new instance of Buffer.



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/loog.rb', line 95

def initialize(formatter: Loog::SHORT)
  super(
    $stdout,
    level: Logger::DEBUG,
    formatter: proc do |severity, time, target, msg|
      @lines.push(formatter.call(severity, time, target, msg))
      ''
    end
  )
  @lines = []
end

Instance Method Details

#to_sObject



107
108
109
# File 'lib/loog.rb', line 107

def to_s
  @lines.join
end