Class: MotionSupport::NetworkLogger

Inherits:
Object
  • Object
show all
Defined in:
motion/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 2000) ⇒ NetworkLogger

Returns a new instance of NetworkLogger.



24
25
26
27
28
29
30
31
32
# File 'motion/logger.rb', line 24

def initialize(host = "localhost", port = 2000)
  readStream = Pointer.new(:object)
  writeStream = Pointer.new(:object)
  CFStreamCreatePairWithSocketToHost(nil, host, port, readStream, writeStream)
  @output_stream = writeStream[0]
  @output_stream.setDelegate(self)
  @output_stream.scheduleInRunLoop(NSRunLoop.currentRunLoop, forMode:NSDefaultRunLoopMode)
  @output_stream.open
end

Instance Method Details

#log(*args) ⇒ Object



34
35
36
37
38
39
# File 'motion/logger.rb', line 34

def log(*args)
  args.each do |string|
    data = NSData.alloc.initWithData("#{string}\n".dataUsingEncoding(NSASCIIStringEncoding))
    @output_stream.write(data.bytes, maxLength:data.length)
  end
end