Skip to content

Commit

Permalink
Merge pull request #344 from hmalphettes/master
Browse files Browse the repository at this point in the history
Remove the underscore dependency
  • Loading branch information
nomiddlename committed Jan 6, 2016
2 parents 033e52a + 6746e2e commit 1164cc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
15 changes: 10 additions & 5 deletions lib/appenders/logstashUDP.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";
var layouts = require('../layouts')
, dgram = require('dgram')
, util = require('util')
, _ = require('underscore');
, util = require('util');

function logstashUDP (config, layout) {
var udp = dgram.createSocket('udp4');
Expand All @@ -27,14 +26,20 @@ function logstashUDP (config, layout) {
Every other field is valid and fine.
*/

if (loggingEvent.data.length > 1) {
var secondEvData = loggingEvent.data[1];
for (var k in secondEvData) {
config.fields[k] = secondEvData[k];
}
}
config.fields.level = loggingEvent.level.levelStr;

var logObject = {
"@version" : "1",
"@timestamp" : (new Date(loggingEvent.startTime)).toISOString(),
"type" : config.logType ? config.logType : config.category,
"message" : layout(loggingEvent),
"fields" : _.extend(config.fields,
loggingEvent.data.length > 1 ? loggingEvent.data[1] : {},
{'level':loggingEvent.level.levelStr})
"fields" : config.fields
};
sendLog(udp, config.host, config.port, logObject);
};
Expand Down
8 changes: 4 additions & 4 deletions lib/connect-logger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
var levels = require("./levels");
var _ = require('underscore');
var DEFAULT_FORMAT = ':remote-addr - -' +
' ":method :url HTTP/:http-version"' +
' :status :content-length ":referrer"' +
Expand Down Expand Up @@ -164,9 +163,10 @@ function assemble_tokens(req, res, custom_tokens) {
*/

function format(str, tokens) {
return _.reduce(tokens, function(current_string, token) {
return current_string.replace(token.token, token.replacement);
}, str);
for (var i = 0; i < tokens.length; i++) {
str = str.replace(tokens[i].token, tokens[i].replacement);
}
return str;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
"dependencies": {
"async": "~0.2.0",
"readable-stream": "~1.0.2",
"semver": "~4.3.3",
"underscore": "1.8.2"
"semver": "~4.3.3"
},
"devDependencies": {
"sandboxed-module": "0.1.3",
"underscore": "1.2.1",
"vows": "0.7.0"
},
"browser": {
Expand Down

0 comments on commit 1164cc7

Please sign in to comment.