class Omnibus::Logger::LiveStream
This is a magical wrapper around the logger that chunks data to not look like absolute shit.
Public Class Methods
new(log, level = :debug)
click to toggle source
Create a new LiveStream
logger.
@param [Logger] log
the logger object responsible for logging
@param [Symbol] level
the log level
# File lib/omnibus/logger.rb, line 171 def initialize(log, level = :debug) @log = log @level = level @buffer = "" end
Public Instance Methods
<<(data)
click to toggle source
The live stream operator must respond to <<.
@param [String] data
# File lib/omnibus/logger.rb, line 182 def <<(data) log_lines(data) end
inspect()
click to toggle source
The detailed string representation of this object.
@return [String]
# File lib/omnibus/logger.rb, line 200 def inspect "#<#{self.class.name} level: #{@level}>" end
to_s()
click to toggle source
The string representation of this object.
@return [String]
# File lib/omnibus/logger.rb, line 191 def to_s "#<#{self.class.name}>" end
Private Instance Methods
log_line(data)
click to toggle source
Log an individual line.
@param [String] data
# File lib/omnibus/logger.rb, line 232 def log_line(data) @log.public_send(@level, nil) { data } end
log_lines(data)
click to toggle source
Log the lines in the data, keeping the “rest” in the buffer.
@param [String] data
# File lib/omnibus/logger.rb, line 211 def log_lines(data) if (leftover = @buffer) @buffer = nil log_lines(leftover + data) else if (newline_index = data.index("\n")) line = data.slice!(0...newline_index) data.slice!(0) log_line(line) log_lines(data) else @buffer = data end end end