loggregator_emitter 0.0.4.pre → 0.0.5.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/loggregator_emitter/emit.rb +18 -4
- data/loggregator_emitter.gemspec +1 -1
- data/spec/loggregator_emitter/emit_spec.rb +31 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -13,14 +13,29 @@ module LoggregatorEmitter
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def emit(app_id, message)
|
16
|
-
|
17
|
-
|
16
|
+
lm = create_log_message(app_id, message, LogMessage::MessageType::OUT)
|
17
|
+
send_message(lm)
|
18
|
+
end
|
19
|
+
|
20
|
+
def emit_error(app_id, message)
|
21
|
+
lm = create_log_message(app_id, message, LogMessage::MessageType::ERR)
|
22
|
+
send_message(lm)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def create_log_message(app_id, message, type)
|
18
27
|
lm = LogMessage.new()
|
19
28
|
lm.timestamp = Time.now.to_i
|
20
29
|
lm.message = message
|
21
30
|
lm.app_id = app_id
|
22
31
|
lm.source_type = @source_type
|
23
|
-
lm.message_type =
|
32
|
+
lm.message_type = type
|
33
|
+
lm
|
34
|
+
end
|
35
|
+
|
36
|
+
def send_message(lm)
|
37
|
+
s = UDPSocket.new
|
38
|
+
s.do_not_reverse_lookup = true
|
24
39
|
|
25
40
|
result = lm.encode.buf
|
26
41
|
result.unpack("C*")
|
@@ -28,7 +43,6 @@ module LoggregatorEmitter
|
|
28
43
|
s.sendmsg_nonblock(result, 0, @sockaddr_in)
|
29
44
|
end
|
30
45
|
|
31
|
-
private
|
32
46
|
def valid_source_type?(source_type)
|
33
47
|
LogMessage::SourceType.constants.each do |name|
|
34
48
|
if LogMessage::SourceType.const_get(name) == source_type
|
data/loggregator_emitter.gemspec
CHANGED
@@ -22,7 +22,7 @@ describe LoggregatorEmitter do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe '
|
25
|
+
describe 'Sending To STDOUT' do
|
26
26
|
before(:each) do
|
27
27
|
@emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
|
28
28
|
end
|
@@ -43,6 +43,36 @@ describe LoggregatorEmitter do
|
|
43
43
|
expect(message.message).to eq 'Hello there!'
|
44
44
|
expect(message.app_id).to eq "my_app_id"
|
45
45
|
expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
|
46
|
+
expect(message.message_type).to eq LogMessage::MessageType::OUT
|
47
|
+
|
48
|
+
|
49
|
+
message = messages[1]
|
50
|
+
expect(message.message).to eq 'Hello again!'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'Sending To STDOUT' do
|
55
|
+
before(:each) do
|
56
|
+
@emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'successfully writes protobuffer to a socket' do
|
60
|
+
server = FakeLoggregatorServer.new(12345)
|
61
|
+
server.start
|
62
|
+
|
63
|
+
@emitter.emit_error("my_app_id", 'Hello there!')
|
64
|
+
@emitter.emit_error("my_app_id", 'Hello again!')
|
65
|
+
|
66
|
+
server.stop(2)
|
67
|
+
|
68
|
+
messages = server.messages
|
69
|
+
|
70
|
+
expect(messages.length).to eq 2
|
71
|
+
message = messages[0]
|
72
|
+
expect(message.message).to eq 'Hello there!'
|
73
|
+
expect(message.app_id).to eq "my_app_id"
|
74
|
+
expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
|
75
|
+
expect(message.message_type).to eq LogMessage::MessageType::ERR
|
46
76
|
|
47
77
|
message = messages[1]
|
48
78
|
expect(message.message).to eq 'Hello again!'
|