Class: LoggregatorEmitter::Emitter
- Inherits:
-
Object
- Object
- LoggregatorEmitter::Emitter
- Defined in:
- lib/loggregator_emitter/emit.rb
Constant Summary collapse
- UDP_SEND_ERROR =
StandardError.new("Error sending message via UDP")
- MAX_MESSAGE_BYTE_SIZE =
(9 * 1024) - 512
- TRUNCATED_STRING =
"TRUNCATED"
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #emit(app_id, message) ⇒ Object
- #emit_error(app_id, message) ⇒ Object
-
#initialize(loggregator_server, origin, source_type, source_instance = nil) ⇒ Emitter
constructor
A new instance of Emitter.
Constructor Details
#initialize(loggregator_server, origin, source_type, source_instance = nil) ⇒ Emitter
Returns a new instance of Emitter.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/loggregator_emitter/emit.rb', line 15 def initialize(loggregator_server, origin, source_type, source_instance = nil) @host, @port = loggregator_server.split(/:([^:]*$)/) raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" if !valid_hostname || !valid_port @host = ::Resolv.getaddresses(@host).last raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" unless @host raise ArgumentError, "Must provide a valid origin" unless origin raise ArgumentError, "Must provide valid source_type: #{source_type}" unless source_type raise ArgumentError, "source_type must be a 3-character string" unless source_type.is_a? String raise ArgumentError, "Custom Source String must be 3 characters" unless source_type.size == 3 @origin = origin @source_type = source_type @source_instance = source_instance && source_instance.to_s end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/loggregator_emitter/emit.rb', line 10 def host @host end |
Instance Method Details
#emit(app_id, message) ⇒ Object
33 34 35 |
# File 'lib/loggregator_emitter/emit.rb', line 33 def emit(app_id, ) (app_id, , LogMessage::MessageType::OUT) end |
#emit_error(app_id, message) ⇒ Object
37 38 39 |
# File 'lib/loggregator_emitter/emit.rb', line 37 def emit_error(app_id, ) (app_id, , LogMessage::MessageType::ERR) end |