Example #1
0
function hipchatAppender(config) {

	var notifier = hipchat.make(config.hipchat_room, config.hipchat_token);

  // @lint W074 This function's cyclomatic complexity is too high. (10)
  return function(loggingEvent){

    var notifierFn;

    notifier.setRoom(config.hipchat_room);
    notifier.setRoom(config.hipchat_room);
    notifier.setFrom(config.hipchat_from || '');
    notifier.setNotify(config.hipchat_notify || false);

    if(config.hipchat_host) {
      notifier.setHost(config.hipchat_host);
    }

    switch (loggingEvent.level.toString()) {
      case "TRACE":
      case "DEBUG":
        notifierFn = "info";
        break;
      case "WARN":
        notifierFn = "warning";
        break;
      case "ERROR":
      case "FATAL":
        notifierFn = "failure";
        break;
      default:
        notifierFn = "success";
    }

    // @TODO, re-work in timezoneOffset ?
    var layoutMessage = config.layout(loggingEvent);

    // dispatch hipchat api request, do not return anything
    //  [overide hipchatNotifierResponseCallback]
    notifier[notifierFn](layoutMessage, config.hipchat_response_callback ||
      hipchatNotifierResponseCallback);
  };
}
Example #2
0
function hipchatAppender(config, layout) {
  const notifier = hipchat.make(config.hipchat_room, config.hipchat_token);

  return (loggingEvent) => {
    let notifierFn;

    notifier.setRoom(config.hipchat_room);
    notifier.setFrom(config.hipchat_from || '');
    notifier.setNotify(config.hipchat_notify || false);

    if (config.hipchat_host) {
      notifier.setHost(config.hipchat_host);
    }

    switch (loggingEvent.level.toString()) {
      case 'TRACE':
      case 'DEBUG':
        notifierFn = 'info';
        break;
      case 'WARN':
        notifierFn = 'warning';
        break;
      case 'ERROR':
      case 'FATAL':
        notifierFn = 'failure';
        break;
      default:
        notifierFn = 'success';
    }

    // @TODO, re-work in timezoneOffset ?
    const layoutMessage = layout(loggingEvent);

    // dispatch hipchat api request, do not return anything
    // [overide hipchatNotifierResponseCallback]
    notifier[notifierFn](layoutMessage, config.hipchat_response_callback ||
      hipchatNotifierResponseCallback);
  };
}