forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_log_emitter.rb
48 lines (42 loc) · 1.32 KB
/
app_log_emitter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'fluent_emitter'
module VCAP
class AppLogEmitter
class << self
attr_accessor :emitter, :logger, :fluent_emitter
def emit(app_id, message)
fluent_emitter.emit(app_id, message) if fluent_emitter
emitter.emit(app_id, message, generate_tags(app_id)) if emitter
rescue => e
logger.error('app_event_emitter.emit.failed', app_id: app_id, message: message, error: e)
end
def emit_error(app_id, message)
fluent_emitter.emit(app_id, message) if fluent_emitter
emitter.emit_error(app_id, message, generate_tags(app_id)) if emitter
rescue => e
logger.error('app_event_emitter.emit_error.failed', app_id: app_id, message: message, error: e)
end
private
def generate_tags(app_id)
app, space, org = VCAP::CloudController::AppFetcher.new.fetch(app_id)
if app.nil?
return {
app_id: app_id,
app_name: '',
space_id: '',
space_name: '',
organization_id: '',
organization_name: ''
}
end
{
app_id: app.guid,
app_name: app.name,
space_id: space.guid,
space_name: space.name,
organization_id: org.guid,
organization_name: org.name
}
end
end
end
end