'use strict';
var bunyan = require('bunyan');
var config = require('config');
var LogglyLogger = require('./loggly_logger');

var streams = [];
var logLevel = config.has('Hoist.debug') && config.get('Hoist.debug') ? 'debug' : 'info';

if (typeof describe === 'undefined') {
  streams.push({
    name: 'console',
    level: logLevel,
    stream: process.stdout
  });
}
if (config.has('Hoist.loggly')) {
  streams.push({
    type: 'raw',
    stream: new LogglyLogger()
  });
}
var appName = 'no application name set';
if (config.has('Hoist.application.name')) {
  appName = config.get('Hoist.application.name');
}
var logger = bunyan.createLogger({
  name: appName,
  streams: streams
});
logger.alert = function () {

};
logger.keen = function () {

};
if (config.has('Hoist.raygun.enabled') && config.get('Hoist.raygun.enabled')) {
  var raygun = require('raygun');
  var raygunClient = new raygun.Client().init({
    apiKey: config.get('Hoist.raygun.apiKey')
  });
  logger.alert = function (err, applicationId) {
    raygunClient.send(err, {
      hoistApplication: appName,
      applicationId: applicationId
    });
  };
}
if (config.has('Hoist.keenio.projectId') && config.has('Hoist.keenio.writeKey')) {
  var Keen = require('keen.io');
  var keenClient = Keen.configure({
    projectId: config.get('Hoist.keenio.projectId'),
    writeKey: config.get('Hoist.keenio.writeKey')
  });
  logger.keen = function (eventName, eventDetails) {
    keenClient.addEvent(eventName, eventDetails, function (err, res) {
      if (err) {
        logger.error(err);
      }
      logger.info({
        res: res,
        err: err
      }, 'logged to keen');
    });
  };
}

module.exports = logger;

@@ -1008,47 +1008,73 @@
 onId
-) %7B%0A    raygunClient.send(err, %7B%0A      
+,customData) %7B%0A    customData = customData %7C%7C %7B%7D;%0A    customData.
 hois
@@ -1089,25 +1089,33 @@
 tion
-: 
+=
 appName
-,
+;
 %0A    
-  
+customData.
 appl
@@ -1123,17 +1123,18 @@
 cationId
-:
+ =
  applica
@@ -1139,22 +1139,55 @@
 cationId
+;
 %0A    
-%7D
+raygunClient.send(err, customData
 );%0A  %7D;%0A

allow custom data in alert: