Skip to content

Commit

Permalink
[breaking] Change the method signature to a filter function to be c…
Browse files Browse the repository at this point in the history
…onsistent with `rewriter` and log functions.
  • Loading branch information
indexzero committed Oct 29, 2015
1 parent 2d9519b commit 0d955d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/winston/logger.js
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/log-filter-test.js
Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand Down

0 comments on commit 0d955d3

Please sign in to comment.