logger-levels-test.js
4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* log-rewriter-test.js: Tests for rewriting metadata in winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENSE
*
*/
var assert = require('assert'),
vows = require('vows'),
winston = require('../lib/winston'),
util = require('util'),
helpers = require('./helpers');
vows.describe('winston/logger/levels').addBatch({
"The winston logger": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.Console)()
]
}),
"the info() method": {
"when passed metadata": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message', {foo: 'bar'});
},
"should have metadata object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message');
assert.deepEqual(meta, {foo: 'bar'});
}
}
},
"when passed a string placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %s', 'my string');
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message my string');
},
},
"when passed a number placeholder": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %d', 123);
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message 123');
},
},
"when passed a json placholder and an empty object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %j', {number: 123}, {});
},
"should interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message {"number":123}');
},
},
"when passed a escaped percent sign": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %%', {number: 123});
},
"should not interpolate": function (transport, level, msg, meta) {
assert.strictEqual(msg, util.format('test message %%'));
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolation strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message %s, %s', 'first', 'second' ,{number: 123});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings and a meta object": {
topic: function (logger) {
logger.once('logging', this.callback);
logger.info('test message', 'first', 'second' , {number: 123});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed interpolations strings, meta object and a callback": {
topic: function (logger) {
var that = this;
logger.info('test message %s, %s', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should interpolate and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first, second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed multiple strings, a meta object and a callback": {
topic: function (logger) {
var that = this;
logger.info('test message', 'first', 'second' , {number: 123}, function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should join and have a meta object": function (transport, level, msg, meta) {
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
}
}
}
}).export(module);