Skip to content

Commit

Permalink
add filter for specific log key
Browse files Browse the repository at this point in the history
  • Loading branch information
aeh committed Feb 27, 2019
1 parent 106b254 commit 449ead3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/amqp-writable-stream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const config = require('./config');
const { Writable } = require('stream');
const stringify = require('json-stringify-safe');

Expand All @@ -12,6 +13,11 @@ module.exports = class AmqpWritableStream extends Writable {
channel.on('drain', () => this.emit('drain'));
}
write (chunk, encoding, callback) {
if (typeof chunk !== 'object') return true; // chunk should be an object, return true to keep going.
if (config.requiredLogKey) { // check to see if the required log key is in this chunk
const logs = Array.isArray(chunk.value) ? chunk.value : chunk.value.logs;
if (!logs.some(log => Object.keys(log).includes(config.requiredLogKey))) return true;
}
return this.channel.sendToQueue(this.queueName, Buffer.from(stringify(chunk)), callback);
}
};
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
db: parseConnection(process.env.DATABASE_URL),
tableName: process.env.DATABASE_TABLE_NAME,
logOffset: parseInt(process.env.LOG_OFFSET) || 0,
requiredLogKey: process.env.REQUIRED_LOG_KEY,
amqp: {
url: process.env.AMQP_URL,
queueName: process.env.AMQP_SEARCH_QUEUE
Expand Down

0 comments on commit 449ead3

Please sign in to comment.