class Zlogger::Client::LogDevice

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/zlogger/client.rb, line 61
def initialize(client)
  @client = client
end

Public Instance Methods

close() click to toggle source
# File lib/zlogger/client.rb, line 69
def close()
  client.queue << self
end
run_socket_loop() click to toggle source
# File lib/zlogger/client.rb, line 78
def run_socket_loop
  begin
    socket = client.context.socket :PUB
    socket.connect("tcp://#{client.connect_address}:#{client.port}")
    loop do
      object = client.queue.pop
      break if object == self
      message = ZMQ::Message.new
      message.addstr(client.name)
      message.addstr(object.to_s)
      socket.send_message(message)
    end
    socket.close
  rescue StandardError => e
    puts "Logging socket thread error: #{e}"
  end
end
run_socket_thread() click to toggle source

it is not threadsafe to access ZMQ sockets, so we only write to the logging socket from a single thread.

# File lib/zlogger/client.rb, line 74
def run_socket_thread
  @thread ||= Thread.new { run_socket_loop }
end
write(message) click to toggle source
# File lib/zlogger/client.rb, line 65
def write(message)
  client.queue << message
end