class Chook::Server::Log::LogFileWithStream

Using an instance of this as the Logger target sends logfile writes to all registered streams as well as the file

Constants

LOGSTREAM_DATA_PFX

ServerSent Events data lines always start with this

Public Instance Methods

write(str) click to toggle source
Calls superclass method
# File lib/chook/server/log.rb, line 81
def write(str)
  super # writes out to the file
  flush
  # send to any active streams
  Chook::Server::Log.log_streams.keys.each do |active_stream|
    # ignore streams closed at the client end,
    # they get removed when a new stream starts
    # see the route: get '/subscribe_to_log_stream'
    next if active_stream.closed?

    # send new data to the stream
    active_stream << "#{LOGSTREAM_DATA_PFX}#{str}\n\n"
  end
end