Class: Logplex::Emitter

Inherits:
Object
  • Object
show all
Defined in:
lib/logplex/emitter.rb

Overview

A logging emitter. Best to create this with Token#emitter

Instance Method Summary collapse

Constructor Details

#initialize(address, token) ⇒ Emitter

Public: Create an emitter with the given target address and token.



11
12
13
14
15
16
# File 'lib/logplex/emitter.rb', line 11

def initialize(address, token)
  @address = address
  @token = token

  connect
end

Instance Method Details

#emit(procid, message) ⇒ Object

Public: Emit an event.

procid - the process id emitting this message. A string, like “web.1” message - the message to emit in this event.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/logplex/emitter.rb', line 22

def emit(procid, message)
  #   FRAME: LENGTH PAYLOAD
  #   LENGTH: decimal value of the length of the payload
  payload = serialize_syslogish(13, Time.now.strftime("%Y-%m-%dT%H:%M:%S%z"),
                                Socket.gethostname, @token, procid, 
                                # 'message id' is meaningless to us
                                "-", 
                                # This extra "- " is due to a bug in logplex.
                                "- #{message}")
  event = "#{payload.size} #{payload}"
  @socket.syswrite(event)
end