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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
var tap = require('tap')
var log = require('../')
var result = []
var logEvents = []
var logInfoEvents = []
var logPrefixEvents = []
var util = require('util')
var resultExpect =
[ '\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[7msill\u001b[0m \u001b[0m\u001b[35msilly prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[34m\u001b[40mverb\u001b[0m \u001b[0m\u001b[35mverbose prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[32minfo\u001b[0m \u001b[0m\u001b[35minfo prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[32m\u001b[40mhttp\u001b[0m \u001b[0m\u001b[35mhttp prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[30m\u001b[43mWARN\u001b[0m \u001b[0m\u001b[35mwarn prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35merror prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[32minfo\u001b[0m \u001b[0m\u001b[35minfo prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[32m\u001b[40mhttp\u001b[0m \u001b[0m\u001b[35mhttp prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[30m\u001b[43mWARN\u001b[0m \u001b[0m\u001b[35mwarn prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35merror prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m This is a longer\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m message, with some details\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m and maybe a stack.\n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u001b[31m\u001b[40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m \n',
'\u001b[0m\u001b[37m\u001b[40mnpm\u001b[0m \u001b[0m\u0007noise\u001b[0m\u001b[35m\u001b[0m LOUD NOISES\n',
'\u001b[0m' ]
var logPrefixEventsExpect =
[ { id: 2,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 9,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 16,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] } ]
// should be the same.
var logInfoEventsExpect = logPrefixEventsExpect
var logEventsExpect =
[ { id: 0,
level: 'silly',
prefix: 'silly prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 1,
level: 'verbose',
prefix: 'verbose prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 2,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 3,
level: 'http',
prefix: 'http prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 4,
level: 'warn',
prefix: 'warn prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 5,
level: 'error',
prefix: 'error prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 6,
level: 'silent',
prefix: 'silent prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 7,
level: 'silly',
prefix: 'silly prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 8,
level: 'verbose',
prefix: 'verbose prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 9,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 10,
level: 'http',
prefix: 'http prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 11,
level: 'warn',
prefix: 'warn prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 12,
level: 'error',
prefix: 'error prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 13,
level: 'silent',
prefix: 'silent prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 14,
level: 'silly',
prefix: 'silly prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 15,
level: 'verbose',
prefix: 'verbose prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 16,
level: 'info',
prefix: 'info prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 17,
level: 'http',
prefix: 'http prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 18,
level: 'warn',
prefix: 'warn prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 19,
level: 'error',
prefix: 'error prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 20,
level: 'silent',
prefix: 'silent prefix',
message: 'x = {"foo":{"bar":"baz"}}',
messageRaw: [ 'x = %j', { foo: { bar: 'baz' } } ] },
{ id: 21,
level: 'error',
prefix: '404',
message: 'This is a longer\nmessage, with some details\nand maybe a stack.\n',
messageRaw: [ 'This is a longer\nmessage, with some details\nand maybe a stack.\n' ] },
{ id: 22,
level: 'noise',
prefix: false,
message: 'LOUD NOISES',
messageRaw: [ 'LOUD NOISES' ] } ]
var Stream = require('stream').Stream
var s = new Stream()
s.write = function (m) {
result.push(m)
}
s.writable = true
s.isTTY = true
s.end = function () {}
log.stream = s
log.heading = 'npm'
tap.test('basic', function (t) {
log.on('log', logEvents.push.bind(logEvents))
log.on('log.info', logInfoEvents.push.bind(logInfoEvents))
log.on('info prefix', logPrefixEvents.push.bind(logPrefixEvents))
console.error('log.level=silly')
log.level = 'silly'
log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}})
log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}})
log.info('info prefix', 'x = %j', {foo:{bar:'baz'}})
log.http('http prefix', 'x = %j', {foo:{bar:'baz'}})
log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}})
log.error('error prefix', 'x = %j', {foo:{bar:'baz'}})
log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}})
console.error('log.level=silent')
log.level = 'silent'
log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}})
log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}})
log.info('info prefix', 'x = %j', {foo:{bar:'baz'}})
log.http('http prefix', 'x = %j', {foo:{bar:'baz'}})
log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}})
log.error('error prefix', 'x = %j', {foo:{bar:'baz'}})
log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}})
console.error('log.level=info')
log.level = 'info'
log.silly('silly prefix', 'x = %j', {foo:{bar:'baz'}})
log.verbose('verbose prefix', 'x = %j', {foo:{bar:'baz'}})
log.info('info prefix', 'x = %j', {foo:{bar:'baz'}})
log.http('http prefix', 'x = %j', {foo:{bar:'baz'}})
log.warn('warn prefix', 'x = %j', {foo:{bar:'baz'}})
log.error('error prefix', 'x = %j', {foo:{bar:'baz'}})
log.silent('silent prefix', 'x = %j', {foo:{bar:'baz'}})
log.error('404', 'This is a longer\n'+
'message, with some details\n'+
'and maybe a stack.\n')
log.addLevel('noise', 10000, {beep: true})
log.noise(false, 'LOUD NOISES')
t.deepEqual(result.join('').trim(), resultExpect.join('').trim(), 'result')
t.deepEqual(log.record, logEventsExpect, 'record')
t.deepEqual(logEvents, logEventsExpect, 'logEvents')
t.deepEqual(logInfoEvents, logInfoEventsExpect, 'logInfoEvents')
t.deepEqual(logPrefixEvents, logPrefixEventsExpect, 'logPrefixEvents')
t.end()
})
|