Class: Logplex::Emitter
- Inherits:
-
Object
- Object
- Logplex::Emitter
- Defined in:
- lib/logplex/emitter.rb
Overview
A logging emitter. Best to create this with Token#emitter
Instance Method Summary collapse
-
#emit(procid, message) ⇒ Object
Public: Emit an event.
-
#initialize(address, token) ⇒ Emitter
constructor
Public: Create an emitter with the given target address and token.
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, ) # 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. "- #{}") event = "#{payload.size} #{payload}" @socket.syswrite(event) end |