diff --git a/app/models/runtime/event.rb b/app/models/runtime/event.rb index 701c70db13f..7f32964b8a7 100644 --- a/app/models/runtime/event.rb +++ b/app/models/runtime/event.rb @@ -51,7 +51,7 @@ def after_save super if Config.config.get(:log_audit_events) logger = Steno.logger('cc.model.event') - logger.info "Audit event: #{type} enacted by #{actor_type} #{actor_username || actor_name} on #{actee_type} #{actee_name}" + logger.info Presenters::V3::EventPresenter.new(self).body.to_json end end diff --git a/app/presenters/v3/event_presenter.rb b/app/presenters/v3/event_presenter.rb index 8a65846a12a..77ad0d48d7b 100644 --- a/app/presenters/v3/event_presenter.rb +++ b/app/presenters/v3/event_presenter.rb @@ -3,6 +3,10 @@ module VCAP::CloudController::Presenters::V3 class EventPresenter < BasePresenter def to_hash + body.merge!({ links: build_links }) + end + + def body { guid: event.guid, created_at: event.timestamp, @@ -13,7 +17,6 @@ def to_hash data: event.data || {}, space: space, organization: org, - links: build_links } end diff --git a/spec/unit/models/runtime/event_spec.rb b/spec/unit/models/runtime/event_spec.rb index d20c97ede50..3c44e2025dd 100644 --- a/spec/unit/models/runtime/event_spec.rb +++ b/spec/unit/models/runtime/event_spec.rb @@ -110,11 +110,16 @@ module VCAP::CloudController actee: 'nimoy', actee_type: 'vulcan', actee_name: 'Mr. Spock', - space_guid: space.guid + space: space + } - e = Event.new(required_attrs) - expect(fake_logger).to receive(:info).with('Audit event: audit.test enacted by pork chop on vulcan Mr. Spock') - e.save + event = Event.new(required_attrs) + allow(fake_logger).to receive(:info) + + event.save + + expect(fake_logger).to have_received(:info).with(/audit.test/) + expect(fake_logger).to have_received(:info).with(/#{event.guid}/) end end