GELF appender can add custom fields
This commit is contained in:
parent
2e7f6e5a66
commit
be754f0c0e
@ -48,8 +48,32 @@ function gelfAppender (layout, host, port, hostname, facility) {
|
||||
if (client) client.close();
|
||||
});
|
||||
|
||||
/**
|
||||
* Add custom fields (start with underscore )
|
||||
* - if the first object passed to the logger contains 'GELF' field, add copy the underscore fields to the message
|
||||
* @param loggingEvent
|
||||
* @param msg
|
||||
*/
|
||||
function addCustomFields(loggingEvent, msg){
|
||||
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
|
||||
var keys = Object.keys(firstData);
|
||||
for (var i in keys){
|
||||
var key = keys[i];
|
||||
// skip _id field for graylog2, skip keys not starts with UNDERSCORE
|
||||
if (!key.match(/^_/) || key === "_id") continue;
|
||||
msg[key] = firstData[key];
|
||||
}
|
||||
loggingEvent.data.shift(); // remove the first object
|
||||
//console.log('=== msg ===');
|
||||
//console.log(msg);
|
||||
}
|
||||
|
||||
function preparePacket(loggingEvent) {
|
||||
var msg = {};
|
||||
addCustomFields(loggingEvent, msg);
|
||||
msg.full_message = layout(loggingEvent);
|
||||
msg.short_message = msg.full_message;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user