-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from flatiron/improvements-for-274-custom-pre…
…tty-print Adding custom pretty print function test
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* custom-pretty-print-test.js: Test function as pretty print option. | ||
* | ||
* (C) 2015 Alberto Pose | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
var assert = require('assert'), | ||
vows = require('vows'), | ||
winston = require('../lib/winston'); | ||
|
||
/* Custom logging function */ | ||
function myPrettyPrint(obj) { | ||
return JSON.stringify(obj) | ||
.replace(/\{/g, '< wow ') | ||
.replace(/\:/g, ' such ') | ||
.replace(/\}/g, ' >'); | ||
} | ||
|
||
vows.describe('winston/transport/prettyPrint').addBatch({ | ||
"When pretty option is used": { | ||
"with memory transport": { | ||
topic: function () { | ||
var transport = new (winston.transports.Memory)({prettyPrint: myPrettyPrint}); | ||
return this.callback(null, transport); | ||
}, | ||
"should log using a function value": function (_, transport) { | ||
transport.log('info', 'hello', {foo: 'bar'}, function (_, logged) { | ||
assert.ok(logged); | ||
assert.equal(1, transport.writeOutput.length); | ||
|
||
var msg = transport.writeOutput[0]; | ||
assert.equal('info: hello < wow "foo" such "bar" >', msg); | ||
}); | ||
} | ||
} | ||
} | ||
}).export(module); |