Class: Chook::Server::Log::LogFileWithStream
- Inherits:
-
File
- Object
- File
- Chook::Server::Log::LogFileWithStream
- Defined in:
- lib/chook/server/log.rb
Overview
Using an instance of this as the Logger target sends logfile writes to all registered streams as well as the file
Constant Summary collapse
- LOGSTREAM_DATA_PFX =
ServerSent Events data lines always start with this
'data:'.freeze
Instance Method Summary collapse
Instance Method Details
#write(str) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 |