Sha256: 5069b274718cba64d85241dc479f1b4d6f32caec3c1ada517d20cd34ca09d4cf

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

"use strict";
var layouts = require('../layouts')
, dgram = require('dgram')
, util = require('util');

function logstashUDP (config, layout) {
  var udp = dgram.createSocket('udp4');
  var type = config.logType ? config.logType : config.category;
  layout = layout || layouts.colouredLayout;
  if(!config.fields) {
    config.fields = {};
  }
  return function(loggingEvent) {
    var logMessage = layout(loggingEvent);
    var fields = {};
    for(var i in config.fields) {
      fields[i] = config.fields[i];
    }
    fields['level'] = loggingEvent.level.levelStr;
    var logObject = {
      '@timestamp': (new Date(loggingEvent.startTime)).toISOString(),
      type: type,
      message: logMessage,
      fields: fields
    };
    sendLog(udp, config.host, config.port, logObject);
  };
}

function sendLog(udp, host, port, logObject) {
  var buffer = new Buffer(JSON.stringify(logObject));
  udp.send(buffer, 0, buffer.length, port, host, function(err, bytes) {
    if(err) {
      console.error(
        "log4js.logstashUDP - %s:%p Error: %s", host, port, util.inspect(err)
      );
    }
  });
}

function configure(config) {
  var layout;
  if (config.layout) {
    layout = layouts.layout(config.layout.type, config.layout);
  }
  return logstashUDP(config, layout);
}

exports.appender = logstashUDP;
exports.configure = configure;

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/log4js/lib/appenders/logstashUDP.js