Class: Cabin::Outputs::IO
- Inherits:
-
Object
- Object
- Cabin::Outputs::IO
- Defined in:
- lib/cabin/outputs/io.rb
Overview
Wrap IO objects with a reasonable log output.
If the IO instance is attached to a TTY, the output will try to be a bit more human-friendly in this format:
{json data}
If the IO instance is not attached to a TTY, the output will be the JSON representation of the event:
{ "timestamp": ..., "message": message, ... }
Instance Method Summary collapse
- #<<(event) ⇒ Object
-
#initialize(io) ⇒ IO
constructor
A new instance of IO.
Constructor Details
#initialize(io) ⇒ IO
Returns a new instance of IO.
17 18 19 |
# File 'lib/cabin/outputs/io.rb', line 17 def initialize(io) @io = io end |
Instance Method Details
#<<(event) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cabin/outputs/io.rb', line 23 def <<(event) if @io.tty? data = event.clone # delete things from the 'data' portion that's not really data. data.delete(:message) data.delete(:timestamp) = "#{event[:message]} #{data.to_json}" @io.puts() @io.flush if @io.tty? else @io.puts(event.to_json) end end |