Merge pull request #294 from Skiggz/gelf-fix

Remove GELF flag when capturing custom fields
This commit is contained in:
Gareth Jones 2015-05-13 07:54:33 +10:00
commit c76fe098ae
2 changed files with 3 additions and 0 deletions

View File

@ -85,6 +85,8 @@ function gelfAppender (layout, host, port, hostname, facility) {
var firstData = data[0]; var firstData = data[0];
if (!firstData.GELF) return; // identify with GELF field defined if (!firstData.GELF) return; // identify with GELF field defined
// Remove the GELF key, some gelf supported logging systems drop the message with it
delete firstData.GELF;
Object.keys(firstData).forEach(function(key) { Object.keys(firstData).forEach(function(key) {
// skip _id field for graylog2, skip keys not starts with UNDERSCORE // skip _id field for graylog2, skip keys not starts with UNDERSCORE
if (key.match(/^_/) || key !== "_id") { if (key.match(/^_/) || key !== "_id") {

View File

@ -244,6 +244,7 @@ vows.describe('log4js gelfAppender').addBatch({
}, },
'should pick up the options': function(message) { 'should pick up the options': function(message) {
assert.equal(message.host, 'cheese'); assert.equal(message.host, 'cheese');
assert.isUndefined(message.GELF); // make sure flag was removed
assert.equal(message._facility, 'nonsense'); assert.equal(message._facility, 'nonsense');
assert.equal(message._every1, 'Hello every one'); // the default value assert.equal(message._every1, 'Hello every one'); // the default value
assert.equal(message._every2, 'Overwritten!'); // the overwritten value assert.equal(message._every2, 'Overwritten!'); // the overwritten value