Class: LogStash::Logging::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/logging/json.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ JSON

Returns a new instance of JSON.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/logstash/logging/json.rb', line 7

def initialize(io)
  raise ArgumentError, "Expected IO, got #{io.class.name}" unless io.is_a?(IO)

  @io = io
  @lock = Mutex.new
end

Instance Method Details

#<<(obj) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/logstash/logging/json.rb', line 14

def <<(obj)
  serialized = LogStash::Json.dump(obj)
  @lock.synchronize do
    @io.puts(serialized)
    @io.flush
  end
end