'use strict';
var EventBroker = require('broker');
var eventBroker = new EventBroker();
var _ = require('lodash');
var Model = require('hoist-model');
var logger = require('hoist-logger');
EventBroker.ModelResolver.set(Model);

function EventListener(subscription, connector, bucket) {
  this.subscription = subscription;
  this.connector = connector;
  this.bucket = bucket;
}

EventListener.prototype.listen = function () {
  _.forEach(this.subscription.endpoints, _.bind(this.createListeners, this));
};

EventListener.prototype.createListeners = function (endpoint) {
  var singularEndpointName = endpoint.replace(/\//, '').replace(/s$/, '').toLowerCase();
  var newEvent = this.connector.key + ':new:' + singularEndpointName;
  var modifiedEvent = this.connector.key + ':modified:' + singularEndpointName;
  var emitter = this.subscription.eventEmitter;
  var options = {
    applicationId: this.subscription.application,
    environment: this.subscription.environment
  };
  if (this.bucket) {
    options.bucketId = this.bucket._id;
  }
  emitter.on(newEvent, function (payload) {
    options.eventName = newEvent;
    options.payload = payload;
    var ev = new EventBroker.events.ApplicationEvent(options);
    logger.info(options, 'inside poller-event-listener newEvent');
    return eventBroker.send(ev).then(function () {
      return ev;
    });
  });
  emitter.on(modifiedEvent, function (payload) {
    options.eventName = modifiedEvent;
    options.payload = payload;
    var ev = new EventBroker.events.ApplicationEvent(options);
    logger.info(options, 'inside poller-event-listener modifiedEvent');
    return eventBroker.send(ev).then(function () {
      return ev;
    }).catch(function (err) {
      console.log('err', err);
    });
  });
};
module.exports = EventListener;
@@ -1073,32 +1073,110 @@
 ion (payload) %7B%0A
+    logger.info(modifiedEvent, 'poller-event-listener newEvent-before send');%0A
     options.even
@@ -1189,24 +1189,24 @@
 = newEvent;%0A
-
     options.
@@ -1346,24 +1346,36 @@
 ner newEvent
+-before send
 ');%0A    retu
@@ -1493,24 +1493,95 @@
 (payload) %7B%0A
+    logger.info(modifiedEvent, 'poller-event-listener modifiedEvent');%0A
     options.
@@ -1693,32 +1693,32 @@
 Event(options);%0A
-
     logger.info(
@@ -1761,32 +1761,44 @@
 er modifiedEvent
+-before send
 ');%0A    return e

add logs