Skip to content

Commit

Permalink
Improve debug output for drop-events filter
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Jul 30, 2019
1 parent c6bf243 commit 2870172
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/plugins/output-filter/dropEventsFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function testCondition (data, fieldName, condition) {
}

function logStatus (debug, a, b, c, d) {
if (debug === 'true') {
consoleLogger.log(JSON.stringify(['drop-filter-events plugin:', a, b, c]))
if (debug != false) {
consoleLogger.debug(`drop-events plugin: ${a} ${b} ${c} ${d}`.replace(/undefined/g, '-'))
}
}

Expand All @@ -26,23 +26,27 @@ function dropEventsFilter (context, config, eventEmitter, data, callback) {
var exclude = config.filters[config.keys[i]].exclude
if (config.filters[config.keys[i]].include) {
drop = (!testCondition(data, config.keys[i], include)) || drop
logStatus(debug, config.keys[i], 'include', drop)
logStatus(debug, config.keys[i], 'include', drop, config.filters[config.keys[i]].include)
}
if (config.filters[config.keys[i]].exclude) {
drop = testCondition(data, config.keys[i], exclude) || drop
logStatus(debug, config.keys[i], 'exclude', drop)
logStatus(debug, config.keys[i], 'exclude', drop, config.filters[config.keys[i]].exclude)
}
}
logStatus('filter result', drop)
logStatus(debug, 'filter result', drop)
if (drop) {
logStatus(debug, 'drop', data)
if (debug) {
logStatus(debug, 'drop', JSON.stringify(data))
}
return callback(new Error('drop filter'))
} else {
logStatus(debug, 'pass', data)
if (debug) {
logStatus(debug, 'pass', JSON.stringify(data))
}
return callback(null, data)
}
} catch (ex) {
logStatus(debug, ex)
logStatus(debug, 'exceptoion', ex)
// pass events in case of error
return callback(null, data)
}
Expand Down

0 comments on commit 2870172

Please sign in to comment.