/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['appenders/gelf.js']) {
  _$jscoverage['appenders/gelf.js'] = [];
  _$jscoverage['appenders/gelf.js'][1] = 0;
  _$jscoverage['appenders/gelf.js'][2] = 0;
  _$jscoverage['appenders/gelf.js'][3] = 0;
  _$jscoverage['appenders/gelf.js'][4] = 0;
  _$jscoverage['appenders/gelf.js'][5] = 0;
  _$jscoverage['appenders/gelf.js'][6] = 0;
  _$jscoverage['appenders/gelf.js'][7] = 0;
  _$jscoverage['appenders/gelf.js'][9] = 0;
  _$jscoverage['appenders/gelf.js'][10] = 0;
  _$jscoverage['appenders/gelf.js'][11] = 0;
  _$jscoverage['appenders/gelf.js'][12] = 0;
  _$jscoverage['appenders/gelf.js'][13] = 0;
  _$jscoverage['appenders/gelf.js'][14] = 0;
  _$jscoverage['appenders/gelf.js'][15] = 0;
  _$jscoverage['appenders/gelf.js'][16] = 0;
  _$jscoverage['appenders/gelf.js'][17] = 0;
  _$jscoverage['appenders/gelf.js'][19] = 0;
  _$jscoverage['appenders/gelf.js'][20] = 0;
  _$jscoverage['appenders/gelf.js'][21] = 0;
  _$jscoverage['appenders/gelf.js'][22] = 0;
  _$jscoverage['appenders/gelf.js'][23] = 0;
  _$jscoverage['appenders/gelf.js'][24] = 0;
  _$jscoverage['appenders/gelf.js'][25] = 0;
  _$jscoverage['appenders/gelf.js'][26] = 0;
  _$jscoverage['appenders/gelf.js'][37] = 0;
  _$jscoverage['appenders/gelf.js'][38] = 0;
  _$jscoverage['appenders/gelf.js'][39] = 0;
  _$jscoverage['appenders/gelf.js'][40] = 0;
  _$jscoverage['appenders/gelf.js'][41] = 0;
  _$jscoverage['appenders/gelf.js'][42] = 0;
  _$jscoverage['appenders/gelf.js'][43] = 0;
  _$jscoverage['appenders/gelf.js'][44] = 0;
  _$jscoverage['appenders/gelf.js'][45] = 0;
  _$jscoverage['appenders/gelf.js'][48] = 0;
  _$jscoverage['appenders/gelf.js'][49] = 0;
  _$jscoverage['appenders/gelf.js'][50] = 0;
  _$jscoverage['appenders/gelf.js'][51] = 0;
  _$jscoverage['appenders/gelf.js'][52] = 0;
  _$jscoverage['appenders/gelf.js'][54] = 0;
  _$jscoverage['appenders/gelf.js'][56] = 0;
  _$jscoverage['appenders/gelf.js'][58] = 0;
  _$jscoverage['appenders/gelf.js'][59] = 0;
  _$jscoverage['appenders/gelf.js'][69] = 0;
  _$jscoverage['appenders/gelf.js'][72] = 0;
  _$jscoverage['appenders/gelf.js'][74] = 0;
  _$jscoverage['appenders/gelf.js'][75] = 0;
  _$jscoverage['appenders/gelf.js'][80] = 0;
  _$jscoverage['appenders/gelf.js'][81] = 0;
  _$jscoverage['appenders/gelf.js'][82] = 0;
  _$jscoverage['appenders/gelf.js'][84] = 0;
  _$jscoverage['appenders/gelf.js'][85] = 0;
  _$jscoverage['appenders/gelf.js'][87] = 0;
  _$jscoverage['appenders/gelf.js'][88] = 0;
  _$jscoverage['appenders/gelf.js'][93] = 0;
  _$jscoverage['appenders/gelf.js'][96] = 0;
  _$jscoverage['appenders/gelf.js'][97] = 0;
  _$jscoverage['appenders/gelf.js'][98] = 0;
  _$jscoverage['appenders/gelf.js'][99] = 0;
  _$jscoverage['appenders/gelf.js'][100] = 0;
  _$jscoverage['appenders/gelf.js'][102] = 0;
  _$jscoverage['appenders/gelf.js'][103] = 0;
  _$jscoverage['appenders/gelf.js'][104] = 0;
  _$jscoverage['appenders/gelf.js'][105] = 0;
  _$jscoverage['appenders/gelf.js'][106] = 0;
  _$jscoverage['appenders/gelf.js'][107] = 0;
  _$jscoverage['appenders/gelf.js'][110] = 0;
  _$jscoverage['appenders/gelf.js'][111] = 0;
  _$jscoverage['appenders/gelf.js'][112] = 0;
  _$jscoverage['appenders/gelf.js'][116] = 0;
  _$jscoverage['appenders/gelf.js'][117] = 0;
  _$jscoverage['appenders/gelf.js'][118] = 0;
  _$jscoverage['appenders/gelf.js'][119] = 0;
  _$jscoverage['appenders/gelf.js'][120] = 0;
  _$jscoverage['appenders/gelf.js'][122] = 0;
  _$jscoverage['appenders/gelf.js'][123] = 0;
  _$jscoverage['appenders/gelf.js'][125] = 0;
  _$jscoverage['appenders/gelf.js'][132] = 0;
  _$jscoverage['appenders/gelf.js'][133] = 0;
  _$jscoverage['appenders/gelf.js'][134] = 0;
  _$jscoverage['appenders/gelf.js'][135] = 0;
  _$jscoverage['appenders/gelf.js'][137] = 0;
  _$jscoverage['appenders/gelf.js'][140] = 0;
  _$jscoverage['appenders/gelf.js'][141] = 0;
}
_$jscoverage['appenders/gelf.js'][1]++;
"use strict";
_$jscoverage['appenders/gelf.js'][2]++;
var zlib = require("zlib");
_$jscoverage['appenders/gelf.js'][3]++;
var layouts = require("../layouts");
_$jscoverage['appenders/gelf.js'][4]++;
var levels = require("../levels");
_$jscoverage['appenders/gelf.js'][5]++;
var dgram = require("dgram");
_$jscoverage['appenders/gelf.js'][6]++;
var util = require("util");
_$jscoverage['appenders/gelf.js'][7]++;
var debug = require("../debug")("GELF Appender");
_$jscoverage['appenders/gelf.js'][9]++;
var LOG_EMERG = 0;
_$jscoverage['appenders/gelf.js'][10]++;
var LOG_ALERT = 1;
_$jscoverage['appenders/gelf.js'][11]++;
var LOG_CRIT = 2;
_$jscoverage['appenders/gelf.js'][12]++;
var LOG_ERR = 3;
_$jscoverage['appenders/gelf.js'][13]++;
var LOG_ERROR = 3;
_$jscoverage['appenders/gelf.js'][14]++;
var LOG_WARNING = 4;
_$jscoverage['appenders/gelf.js'][15]++;
var LOG_NOTICE = 5;
_$jscoverage['appenders/gelf.js'][16]++;
var LOG_INFO = 6;
_$jscoverage['appenders/gelf.js'][17]++;
var LOG_DEBUG = 7;
_$jscoverage['appenders/gelf.js'][19]++;
var levelMapping = {};
_$jscoverage['appenders/gelf.js'][20]++;
levelMapping[levels.ALL] = LOG_DEBUG;
_$jscoverage['appenders/gelf.js'][21]++;
levelMapping[levels.TRACE] = LOG_DEBUG;
_$jscoverage['appenders/gelf.js'][22]++;
levelMapping[levels.DEBUG] = LOG_DEBUG;
_$jscoverage['appenders/gelf.js'][23]++;
levelMapping[levels.INFO] = LOG_INFO;
_$jscoverage['appenders/gelf.js'][24]++;
levelMapping[levels.WARN] = LOG_WARNING;
_$jscoverage['appenders/gelf.js'][25]++;
levelMapping[levels.ERROR] = LOG_ERR;
_$jscoverage['appenders/gelf.js'][26]++;
levelMapping[levels.FATAL] = LOG_CRIT;
_$jscoverage['appenders/gelf.js'][37]++;
function gelfAppender(layout, host, port, hostname, facility) {
  _$jscoverage['appenders/gelf.js'][38]++;
  var config, customFields;
  _$jscoverage['appenders/gelf.js'][39]++;
  if (typeof host === "object") {
    _$jscoverage['appenders/gelf.js'][40]++;
    config = host;
    _$jscoverage['appenders/gelf.js'][41]++;
    host = config.host;
    _$jscoverage['appenders/gelf.js'][42]++;
    port = config.port;
    _$jscoverage['appenders/gelf.js'][43]++;
    hostname = config.hostname;
    _$jscoverage['appenders/gelf.js'][44]++;
    facility = config.facility;
    _$jscoverage['appenders/gelf.js'][45]++;
    customFields = config.customFields;
  }
  _$jscoverage['appenders/gelf.js'][48]++;
  host = host || "localhost";
  _$jscoverage['appenders/gelf.js'][49]++;
  port = port || 12201;
  _$jscoverage['appenders/gelf.js'][50]++;
  hostname = hostname || require("os").hostname();
  _$jscoverage['appenders/gelf.js'][51]++;
  facility = facility || "nodejs-server";
  _$jscoverage['appenders/gelf.js'][52]++;
  layout = layout || layouts.messagePassThroughLayout;
  _$jscoverage['appenders/gelf.js'][54]++;
  var defaultCustomFields = customFields || {};
  _$jscoverage['appenders/gelf.js'][56]++;
  var client = dgram.createSocket("udp4");
  _$jscoverage['appenders/gelf.js'][58]++;
  process.on("exit", (function () {
  _$jscoverage['appenders/gelf.js'][59]++;
  if (client) {
    _$jscoverage['appenders/gelf.js'][59]++;
    client.close();
  }
}));
  _$jscoverage['appenders/gelf.js'][69]++;
  function addCustomFields(loggingEvent, msg) {
    _$jscoverage['appenders/gelf.js'][72]++;
    Object.keys(defaultCustomFields).forEach((function (key) {
  _$jscoverage['appenders/gelf.js'][74]++;
  if (key.match(/^_/) && key !== "_id") {
    _$jscoverage['appenders/gelf.js'][75]++;
    msg[key] = defaultCustomFields[key];
  }
}));
    _$jscoverage['appenders/gelf.js'][80]++;
    var data = loggingEvent.data;
    _$jscoverage['appenders/gelf.js'][81]++;
    if (! Array.isArray(data) || data.length === 0) {
      _$jscoverage['appenders/gelf.js'][81]++;
      return;
    }
    _$jscoverage['appenders/gelf.js'][82]++;
    var firstData = data[0];
    _$jscoverage['appenders/gelf.js'][84]++;
    if (! firstData.GELF) {
      _$jscoverage['appenders/gelf.js'][84]++;
      return;
    }
    _$jscoverage['appenders/gelf.js'][85]++;
    Object.keys(firstData).forEach((function (key) {
  _$jscoverage['appenders/gelf.js'][87]++;
  if (key.match(/^_/) || key !== "_id") {
    _$jscoverage['appenders/gelf.js'][88]++;
    msg[key] = firstData[key];
  }
}));
    _$jscoverage['appenders/gelf.js'][93]++;
    loggingEvent.data.shift();
}
  _$jscoverage['appenders/gelf.js'][96]++;
  function preparePacket(loggingEvent) {
    _$jscoverage['appenders/gelf.js'][97]++;
    var msg = {};
    _$jscoverage['appenders/gelf.js'][98]++;
    addCustomFields(loggingEvent, msg);
    _$jscoverage['appenders/gelf.js'][99]++;
    msg.full_message = layout(loggingEvent);
    _$jscoverage['appenders/gelf.js'][100]++;
    msg.short_message = msg.full_message;
    _$jscoverage['appenders/gelf.js'][102]++;
    msg.version = "1.0";
    _$jscoverage['appenders/gelf.js'][103]++;
    msg.timestamp = msg.timestamp || new Date().getTime() / 1000 >> 0;
    _$jscoverage['appenders/gelf.js'][104]++;
    msg.host = hostname;
    _$jscoverage['appenders/gelf.js'][105]++;
    msg.level = levelMapping[loggingEvent.level || levels.DEBUG];
    _$jscoverage['appenders/gelf.js'][106]++;
    msg.facility = facility;
    _$jscoverage['appenders/gelf.js'][107]++;
    return msg;
}
  _$jscoverage['appenders/gelf.js'][110]++;
  function sendPacket(packet) {
    _$jscoverage['appenders/gelf.js'][111]++;
    try {
      _$jscoverage['appenders/gelf.js'][112]++;
      client.send(packet, 0, packet.length, port, host);
    }
    catch (e) {
    }
}
  _$jscoverage['appenders/gelf.js'][116]++;
  return (function (loggingEvent) {
  _$jscoverage['appenders/gelf.js'][117]++;
  var message = preparePacket(loggingEvent);
  _$jscoverage['appenders/gelf.js'][118]++;
  zlib.gzip(new Buffer(JSON.stringify(message)), (function (err, packet) {
  _$jscoverage['appenders/gelf.js'][119]++;
  if (err) {
    _$jscoverage['appenders/gelf.js'][120]++;
    console.error(err.stack);
  }
  else {
    _$jscoverage['appenders/gelf.js'][122]++;
    if (packet.length > 8192) {
      _$jscoverage['appenders/gelf.js'][123]++;
      debug("Message packet length (" + packet.length + ") is larger than 8k. Not sending");
    }
    else {
      _$jscoverage['appenders/gelf.js'][125]++;
      sendPacket(packet);
    }
  }
}));
});
}
_$jscoverage['appenders/gelf.js'][132]++;
function configure(config) {
  _$jscoverage['appenders/gelf.js'][133]++;
  var layout;
  _$jscoverage['appenders/gelf.js'][134]++;
  if (config.layout) {
    _$jscoverage['appenders/gelf.js'][135]++;
    layout = layouts.layout(config.layout.type, config.layout);
  }
  _$jscoverage['appenders/gelf.js'][137]++;
  return gelfAppender(layout, config);
}
_$jscoverage['appenders/gelf.js'][140]++;
exports.appender = gelfAppender;
_$jscoverage['appenders/gelf.js'][141]++;
exports.configure = configure;
_$jscoverage['appenders/gelf.js'].source = ["\"use strict\";","var zlib = require('zlib');","var layouts = require('../layouts');","var levels = require('../levels');","var dgram = require('dgram');","var util = require('util');","var debug = require('../debug')('GELF Appender');","","var LOG_EMERG=0;    // system is unusable","var LOG_ALERT=1;    // action must be taken immediately","var LOG_CRIT=2;     // critical conditions","var LOG_ERR=3;      // error conditions","var LOG_ERROR=3;    // because people WILL typo","var LOG_WARNING=4;  // warning conditions","var LOG_NOTICE=5;   // normal, but significant, condition","var LOG_INFO=6;     // informational message","var LOG_DEBUG=7;    // debug-level message","","var levelMapping = {};","levelMapping[levels.ALL] = LOG_DEBUG;","levelMapping[levels.TRACE] = LOG_DEBUG;","levelMapping[levels.DEBUG] = LOG_DEBUG;","levelMapping[levels.INFO] = LOG_INFO;","levelMapping[levels.WARN] = LOG_WARNING;","levelMapping[levels.ERROR] = LOG_ERR;","levelMapping[levels.FATAL] = LOG_CRIT;","","/**"," * GELF appender that supports sending UDP packets to a GELF compatible server such as Graylog"," *"," * @param layout a function that takes a logevent and returns a string (defaults to none)."," * @param host - host to which to send logs (default:localhost)"," * @param port - port at which to send logs to (default:12201)"," * @param hostname - hostname of the current host (default:os hostname)"," * @param facility - facility to log to (default:nodejs-server)"," */","function gelfAppender (layout, host, port, hostname, facility) {","  var config, customFields;","  if (typeof(host) === 'object') {","    config = host;","    host = config.host;","    port = config.port;","    hostname = config.hostname;","    facility = config.facility;","    customFields = config.customFields;","  }","  ","  host = host || 'localhost';","  port = port || 12201;","  hostname = hostname || require('os').hostname();","  facility = facility || 'nodejs-server';","  layout = layout || layouts.messagePassThroughLayout;","","  var defaultCustomFields = customFields || {};","  ","  var client = dgram.createSocket(\"udp4\");","  ","  process.on('exit', function() {","    if (client) client.close();","  });","","  /**","   * Add custom fields (start with underscore ) ","   * - if the first object passed to the logger contains 'GELF' field, ","   *   copy the underscore fields to the message","   * @param loggingEvent","   * @param msg","   */","  function addCustomFields(loggingEvent, msg){","","    /* append defaultCustomFields firsts */","    Object.keys(defaultCustomFields).forEach(function(key) {","      // skip _id field for graylog2, skip keys not starts with UNDERSCORE","      if (key.match(/^_/) &amp;&amp; key !== \"_id\") { ","        msg[key] = defaultCustomFields[key];","      }","    });","","    /* append custom fields per message */","    var data = loggingEvent.data;","    if (!Array.isArray(data) || data.length === 0) return;","    var firstData = data[0];","    ","    if (!firstData.GELF) return; // identify with GELF field defined","    Object.keys(firstData).forEach(function(key) {","      // skip _id field for graylog2, skip keys not starts with UNDERSCORE","      if (key.match(/^_/) || key !== \"_id\") { ","        msg[key] = firstData[key];","      }","    });","    ","    /* the custom field object should be removed, so it will not be looged by the later appenders */","    loggingEvent.data.shift(); ","  }"," ","  function preparePacket(loggingEvent) {","    var msg = {};","    addCustomFields(loggingEvent, msg);","    msg.full_message = layout(loggingEvent);","    msg.short_message = msg.full_message;","    ","    msg.version=\"1.0\";","    msg.timestamp = msg.timestamp || new Date().getTime() / 1000 &gt;&gt; 0;","    msg.host = hostname;","    msg.level = levelMapping[loggingEvent.level || levels.DEBUG];","    msg.facility = facility;","    return msg;","  }","  ","  function sendPacket(packet) {","    try {","      client.send(packet, 0, packet.length, port, host);","    } catch(e) {}","  }","","  return function(loggingEvent) {","    var message = preparePacket(loggingEvent);","    zlib.gzip(new Buffer(JSON.stringify(message)), function(err, packet) {","      if (err) {","        console.error(err.stack);","      } else {","        if (packet.length &gt; 8192) {","          debug(\"Message packet length (\" + packet.length + \") is larger than 8k. Not sending\");","        } else {","          sendPacket(packet);","        }","      }","    });","  };","}","","function configure(config) {","  var layout;","  if (config.layout) {","    layout = layouts.layout(config.layout.type, config.layout);","  }","  return gelfAppender(layout, config);","}","","exports.appender = gelfAppender;","exports.configure = configure;"];
