From 8cd836880f5bde0a8dac229ba474fc1f47d643ad Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 29 Oct 2015 00:35:44 -0700 Subject: [PATCH] [breaking] Change the method signature to a `filter` function to be consistent with `rewriter` and log functions. --- README.md | 4 ++-- lib/winston/logger.js | 2 +- test/log-filter-test.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a932eaf54..f7cdd71ed 100644 --- a/README.md +++ b/README.md @@ -671,14 +671,14 @@ Both filters and rewriters are simple Arrays of functions which can be provided ``` js var logger = new winston.Logger({ rewriters: [function (level, msg, meta) { /* etc etc */ }] - filters: [function (msg, meta, level) { /* etc etc */ }] + filters: [function (level, msg, meta) { /* etc etc */ }] }) ``` Like any Array they can also be modified at runtime with no adverse side-effects to the `winston` internals. ``` js -logger.filters.push(function(msg, meta, level) { +logger.filters.push(function(level, msg, meta) { return meta.production ? maskCardNumbers(msg) : msg; diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 49984f6eb..8fc71bed1 100755 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -141,7 +141,7 @@ Logger.prototype.log = function (level) { }); this.filters.forEach(function(filter) { - var filtered = filter(msg, meta, level, self); + var filtered = filter(level, msg, meta, self); if (typeof filtered === 'string') msg = filtered; else { diff --git a/test/log-filter-test.js b/test/log-filter-test.js index 5684c10bf..32d7babb9 100644 --- a/test/log-filter-test.js +++ b/test/log-filter-test.js @@ -49,7 +49,7 @@ vows.describe('winston/logger/filter').addBatch({ ]}), "the filters.push() method, adding a filter only for the message": { topic: function (logger) { - logger.filters.push(function (msg) { + logger.filters.push(function (level, msg) { return maskCardNumbers(msg); }); @@ -76,7 +76,7 @@ vows.describe('winston/logger/filter').addBatch({ }), "the filters.push() method adding a filter for the message and metadata": { topic: function (logger) { - logger.filters.push(function (msg, meta) { + logger.filters.push(function (level, msg, meta) { return maskSecrets(msg, meta); });