Skip to content

Commit

Permalink
Adding custom pretty print function test.
Browse files Browse the repository at this point in the history
  • Loading branch information
pose committed Jan 25, 2015
1 parent 3872dfb commit 64ed8e0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/custom-pretty-print-test.js
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);

0 comments on commit 64ed8e0

Please sign in to comment.