tailwind-widgets 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +113 -0
  3. package/bin.js +6 -0
  4. package/bingo-logger.js +211 -0
  5. package/browser.js +358 -0
  6. package/docs/api.md +1352 -0
  7. package/docs/asynchronous.md +102 -0
  8. package/docs/benchmarks.md +58 -0
  9. package/docs/browser.md +199 -0
  10. package/docs/bundling.md +34 -0
  11. package/docs/child-loggers.md +95 -0
  12. package/docs/ecosystem.md +74 -0
  13. package/docs/help.md +305 -0
  14. package/docs/lts.md +62 -0
  15. package/docs/pretty.md +101 -0
  16. package/docs/redaction.md +135 -0
  17. package/docs/transports.md +792 -0
  18. package/docs/web.md +257 -0
  19. package/file.js +12 -0
  20. package/lib/caller.js +30 -0
  21. package/lib/deprecations.js +10 -0
  22. package/lib/levels.js +193 -0
  23. package/lib/meta.js +5 -0
  24. package/lib/multistream.js +156 -0
  25. package/lib/parse.js +14 -0
  26. package/lib/proto.js +216 -0
  27. package/lib/redaction.js +118 -0
  28. package/lib/symbols.js +70 -0
  29. package/lib/time.js +11 -0
  30. package/lib/tools.js +563 -0
  31. package/lib/transport-stream.js +47 -0
  32. package/lib/transport.js +157 -0
  33. package/lib/worker-pipeline.js +40 -0
  34. package/lib/worker.js +54 -0
  35. package/package.json +131 -0
  36. package/test/basic.test.js +719 -0
  37. package/test/broken-pipe.test.js +42 -0
  38. package/test/browser-levels.test.js +218 -0
  39. package/test/browser-serializers.test.js +354 -0
  40. package/test/browser-timestamp.test.js +88 -0
  41. package/test/browser-transmit.test.js +349 -0
  42. package/test/browser.test.js +547 -0
  43. package/test/complex-objects.test.js +34 -0
  44. package/test/crlf.test.js +32 -0
  45. package/test/custom-levels.test.js +294 -0
  46. package/test/error.test.js +374 -0
  47. package/test/escaping.test.js +91 -0
  48. package/test/esm/esm.mjs +12 -0
  49. package/test/esm/index.test.js +34 -0
  50. package/test/esm/named-exports.mjs +28 -0
  51. package/test/exit.test.js +85 -0
  52. package/test/final.test.js +237 -0
  53. package/test/fixtures/broken-pipe/basic.js +9 -0
  54. package/test/fixtures/broken-pipe/destination.js +10 -0
  55. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  56. package/test/fixtures/console-transport.js +13 -0
  57. package/test/fixtures/default-exit.js +8 -0
  58. package/test/fixtures/destination-exit.js +8 -0
  59. package/test/fixtures/eval/index.js +29 -0
  60. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  61. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  62. package/test/fixtures/eval/node_modules/file1.js +5 -0
  63. package/test/fixtures/eval/node_modules/file10.js +5 -0
  64. package/test/fixtures/eval/node_modules/file11.js +5 -0
  65. package/test/fixtures/eval/node_modules/file12.js +5 -0
  66. package/test/fixtures/eval/node_modules/file13.js +5 -0
  67. package/test/fixtures/eval/node_modules/file14.js +11 -0
  68. package/test/fixtures/eval/node_modules/file15.js +10 -0
  69. package/test/fixtures/eval/node_modules/file2.js +5 -0
  70. package/test/fixtures/eval/node_modules/file3.js +5 -0
  71. package/test/fixtures/eval/node_modules/file4.js +5 -0
  72. package/test/fixtures/eval/node_modules/file5.js +5 -0
  73. package/test/fixtures/eval/node_modules/file6.js +5 -0
  74. package/test/fixtures/eval/node_modules/file7.js +5 -0
  75. package/test/fixtures/eval/node_modules/file8.js +5 -0
  76. package/test/fixtures/eval/node_modules/file9.js +5 -0
  77. package/test/fixtures/eval/node_modules/test.list +3 -0
  78. package/test/fixtures/pretty/basic.js +6 -0
  79. package/test/fixtures/pretty/child-with-serializer.js +17 -0
  80. package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
  81. package/test/fixtures/pretty/child.js +8 -0
  82. package/test/fixtures/pretty/custom-time-label.js +9 -0
  83. package/test/fixtures/pretty/custom-time.js +9 -0
  84. package/test/fixtures/pretty/dateformat.js +10 -0
  85. package/test/fixtures/pretty/error-props.js +9 -0
  86. package/test/fixtures/pretty/error.js +7 -0
  87. package/test/fixtures/pretty/final-no-log-before.js +8 -0
  88. package/test/fixtures/pretty/final-return.js +7 -0
  89. package/test/fixtures/pretty/final.js +9 -0
  90. package/test/fixtures/pretty/formatters.js +13 -0
  91. package/test/fixtures/pretty/level-first.js +6 -0
  92. package/test/fixtures/pretty/no-time.js +9 -0
  93. package/test/fixtures/pretty/null-prototype.js +8 -0
  94. package/test/fixtures/pretty/obj-msg-prop.js +6 -0
  95. package/test/fixtures/pretty/pretty-factory.js +6 -0
  96. package/test/fixtures/pretty/redact.js +9 -0
  97. package/test/fixtures/pretty/serializers.js +17 -0
  98. package/test/fixtures/pretty/skipped-output.js +13 -0
  99. package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -0
  100. package/test/fixtures/stdout-hack-protection.js +11 -0
  101. package/test/fixtures/syncfalse-child.js +6 -0
  102. package/test/fixtures/syncfalse-exit.js +9 -0
  103. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  104. package/test/fixtures/syncfalse.js +6 -0
  105. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  106. package/test/fixtures/to-file-transport.js +13 -0
  107. package/test/fixtures/to-file-transport.mjs +8 -0
  108. package/test/fixtures/transport/index.js +12 -0
  109. package/test/fixtures/transport/package.json +5 -0
  110. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  111. package/test/fixtures/transport-exit-immediately.js +11 -0
  112. package/test/fixtures/transport-exit-on-ready.js +12 -0
  113. package/test/fixtures/transport-main.js +9 -0
  114. package/test/fixtures/transport-many-lines.js +29 -0
  115. package/test/fixtures/transport-string-stdout.js +9 -0
  116. package/test/fixtures/transport-transform.js +21 -0
  117. package/test/fixtures/transport-worker.js +13 -0
  118. package/test/fixtures/transport-wrong-export-type.js +3 -0
  119. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  120. package/test/fixtures/ts/to-file-transport.es2017.cjs +12 -0
  121. package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
  122. package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
  123. package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
  124. package/test/fixtures/ts/to-file-transport.ts +11 -0
  125. package/test/fixtures/ts/transpile.cjs +40 -0
  126. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  127. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  128. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  129. package/test/fixtures/ts/transport-main.ts +8 -0
  130. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  131. package/test/fixtures/ts/transport-worker.ts +14 -0
  132. package/test/formatters.test.js +355 -0
  133. package/test/helper.d.ts +4 -0
  134. package/test/helper.js +128 -0
  135. package/test/hooks.test.js +97 -0
  136. package/test/http.test.js +242 -0
  137. package/test/is-level-enabled.test.js +43 -0
  138. package/test/jest/basic.spec.js +10 -0
  139. package/test/levels.test.js +528 -0
  140. package/test/metadata.test.js +106 -0
  141. package/test/mixin-merge-strategy.test.js +55 -0
  142. package/test/mixin.test.js +162 -0
  143. package/test/multistream.test.js +589 -0
  144. package/test/pretty.test.js +392 -0
  145. package/test/redact.test.js +828 -0
  146. package/test/serializers.test.js +253 -0
  147. package/test/stdout-protection.test.js +19 -0
  148. package/test/syncfalse.test.js +118 -0
  149. package/test/timestamp.test.js +121 -0
  150. package/test/transport/big.test.js +41 -0
  151. package/test/transport/bundlers-support.test.js +97 -0
  152. package/test/transport/caller.test.js +23 -0
  153. package/test/transport/core.test.js +546 -0
  154. package/test/transport/core.test.ts +236 -0
  155. package/test/transport/core.transpiled.test.ts +116 -0
  156. package/test/transport/module-link.test.js +239 -0
  157. package/test/transport/pipeline.test.js +36 -0
  158. package/test/transport/syncfalse.test.js +31 -0
  159. package/test/transport/targets.test.js +28 -0
  160. package/test/types/pino-import.test-d.ts +29 -0
  161. package/test/types/pino-multistream.test-d.ts +26 -0
  162. package/test/types/pino-top-export.test-d.ts +37 -0
  163. package/test/types/pino-transport.test-d.ts +122 -0
  164. package/test/types/pino-type-only.test-d.ts +16 -0
  165. package/test/types/pino.test-d.ts +341 -0
  166. package/test/types/pino.ts +42 -0
@@ -0,0 +1,589 @@
1
+ 'use strict'
2
+
3
+ const writeStream = require('flush-write-stream')
4
+ const { readFileSync } = require('fs')
5
+ const test = require('tap').test
6
+ const bingo-logger = require('../')
7
+ const multistream = bingo-logger.multistream
8
+ const proxyquire = require('proxyquire')
9
+ const strip = require('strip-ansi')
10
+ const { file } = require('./helper')
11
+
12
+ test('sends to multiple streams using string levels', function (t) {
13
+ let messageCount = 0
14
+ const stream = writeStream(function (data, enc, cb) {
15
+ messageCount += 1
16
+ cb()
17
+ })
18
+ const streams = [
19
+ { stream: stream },
20
+ { level: 'debug', stream: stream },
21
+ { level: 'trace', stream: stream },
22
+ { level: 'fatal', stream: stream },
23
+ { level: 'silent', stream: stream }
24
+ ]
25
+ const log = bingo-logger({
26
+ level: 'trace'
27
+ }, multistream(streams))
28
+ log.info('info stream')
29
+ log.debug('debug stream')
30
+ log.fatal('fatal stream')
31
+ t.equal(messageCount, 9)
32
+ t.end()
33
+ })
34
+
35
+ test('sends to multiple streams using custom levels', function (t) {
36
+ let messageCount = 0
37
+ const stream = writeStream(function (data, enc, cb) {
38
+ messageCount += 1
39
+ cb()
40
+ })
41
+ const streams = [
42
+ { stream: stream },
43
+ { level: 'debug', stream: stream },
44
+ { level: 'trace', stream: stream },
45
+ { level: 'fatal', stream: stream },
46
+ { level: 'silent', stream: stream }
47
+ ]
48
+ const log = bingo-logger({
49
+ level: 'trace'
50
+ }, multistream(streams))
51
+ log.info('info stream')
52
+ log.debug('debug stream')
53
+ log.fatal('fatal stream')
54
+ t.equal(messageCount, 9)
55
+ t.end()
56
+ })
57
+
58
+ test('sends to multiple streams using optionally predefined levels', function (t) {
59
+ let messageCount = 0
60
+ const stream = writeStream(function (data, enc, cb) {
61
+ messageCount += 1
62
+ cb()
63
+ })
64
+ const opts = {
65
+ levels: {
66
+ silent: Infinity,
67
+ fatal: 60,
68
+ error: 50,
69
+ warn: 50,
70
+ info: 30,
71
+ debug: 20,
72
+ trace: 10
73
+ }
74
+ }
75
+ const streams = [
76
+ { stream: stream },
77
+ { level: 'trace', stream: stream },
78
+ { level: 'debug', stream: stream },
79
+ { level: 'info', stream: stream },
80
+ { level: 'warn', stream: stream },
81
+ { level: 'error', stream: stream },
82
+ { level: 'fatal', stream: stream },
83
+ { level: 'silent', stream: stream }
84
+ ]
85
+ const mstream = multistream(streams, opts)
86
+ const log = bingo-logger({
87
+ level: 'trace'
88
+ }, mstream)
89
+ log.trace('trace stream')
90
+ log.debug('debug stream')
91
+ log.info('info stream')
92
+ log.warn('warn stream')
93
+ log.error('error stream')
94
+ log.fatal('fatal stream')
95
+ log.silent('silent stream')
96
+ t.equal(messageCount, 24)
97
+ t.end()
98
+ })
99
+
100
+ test('sends to multiple streams using number levels', function (t) {
101
+ let messageCount = 0
102
+ const stream = writeStream(function (data, enc, cb) {
103
+ messageCount += 1
104
+ cb()
105
+ })
106
+ const streams = [
107
+ { stream: stream },
108
+ { level: 20, stream: stream },
109
+ { level: 60, stream: stream }
110
+ ]
111
+ const log = bingo-logger({
112
+ level: 'debug'
113
+ }, multistream(streams))
114
+ log.info('info stream')
115
+ log.debug('debug stream')
116
+ log.fatal('fatal stream')
117
+ t.equal(messageCount, 6)
118
+ t.end()
119
+ })
120
+
121
+ test('level include higher levels', function (t) {
122
+ let messageCount = 0
123
+ const stream = writeStream(function (data, enc, cb) {
124
+ messageCount += 1
125
+ cb()
126
+ })
127
+ const log = bingo-logger({}, multistream([{ level: 'info', stream: stream }]))
128
+ log.fatal('message')
129
+ t.equal(messageCount, 1)
130
+ t.end()
131
+ })
132
+
133
+ test('supports multiple arguments', function (t) {
134
+ const messages = []
135
+ const stream = writeStream(function (data, enc, cb) {
136
+ messages.push(JSON.parse(data))
137
+ if (messages.length === 2) {
138
+ const msg1 = messages[0]
139
+ t.equal(msg1.msg, 'foo bar baz foobar')
140
+
141
+ const msg2 = messages[1]
142
+ t.equal(msg2.msg, 'foo bar baz foobar barfoo foofoo')
143
+
144
+ t.end()
145
+ }
146
+ cb()
147
+ })
148
+ const log = bingo-logger({}, multistream({ stream }))
149
+ log.info('%s %s %s %s', 'foo', 'bar', 'baz', 'foobar') // apply not invoked
150
+ log.info('%s %s %s %s %s %s', 'foo', 'bar', 'baz', 'foobar', 'barfoo', 'foofoo') // apply invoked
151
+ })
152
+
153
+ test('supports children', function (t) {
154
+ const stream = writeStream(function (data, enc, cb) {
155
+ const input = JSON.parse(data)
156
+ t.equal(input.msg, 'child stream')
157
+ t.equal(input.child, 'one')
158
+ t.end()
159
+ cb()
160
+ })
161
+ const streams = [
162
+ { stream: stream }
163
+ ]
164
+ const log = bingo-logger({}, multistream(streams)).child({ child: 'one' })
165
+ log.info('child stream')
166
+ })
167
+
168
+ test('supports grandchildren', function (t) {
169
+ const messages = []
170
+ const stream = writeStream(function (data, enc, cb) {
171
+ messages.push(JSON.parse(data))
172
+ if (messages.length === 3) {
173
+ const msg1 = messages[0]
174
+ t.equal(msg1.msg, 'grandchild stream')
175
+ t.equal(msg1.child, 'one')
176
+ t.equal(msg1.grandchild, 'two')
177
+
178
+ const msg2 = messages[1]
179
+ t.equal(msg2.msg, 'grandchild stream')
180
+ t.equal(msg2.child, 'one')
181
+ t.equal(msg2.grandchild, 'two')
182
+
183
+ const msg3 = messages[2]
184
+ t.equal(msg3.msg, 'debug grandchild')
185
+ t.equal(msg3.child, 'one')
186
+ t.equal(msg3.grandchild, 'two')
187
+
188
+ t.end()
189
+ }
190
+ cb()
191
+ })
192
+ const streams = [
193
+ { stream: stream },
194
+ { level: 'debug', stream: stream }
195
+ ]
196
+ const log = bingo-logger({
197
+ level: 'debug'
198
+ }, multistream(streams)).child({ child: 'one' }).child({ grandchild: 'two' })
199
+ log.info('grandchild stream')
200
+ log.debug('debug grandchild')
201
+ })
202
+
203
+ test('supports custom levels', function (t) {
204
+ const stream = writeStream(function (data, enc, cb) {
205
+ t.equal(JSON.parse(data).msg, 'bar')
206
+ t.end()
207
+ })
208
+ const log = bingo-logger({
209
+ customLevels: {
210
+ foo: 35
211
+ }
212
+ }, multistream([{ level: 35, stream: stream }]))
213
+ log.foo('bar')
214
+ })
215
+
216
+ test('supports pretty print', function (t) {
217
+ t.plan(2)
218
+ const stream = writeStream(function (data, enc, cb) {
219
+ t.not(strip(data.toString()).match(/INFO.*: pretty print/), null)
220
+ cb()
221
+ })
222
+
223
+ const nested = proxyquire('pino-pretty/lib/utils', {
224
+ 'sonic-boom': function () {
225
+ t.pass('sonic created')
226
+ stream.flushSync = () => {}
227
+ stream.flush = () => {}
228
+ return stream
229
+ }
230
+ })
231
+ const pretty = proxyquire('pino-pretty', {
232
+ './lib/utils': nested
233
+ })
234
+
235
+ const log = bingo-logger({
236
+ level: 'debug',
237
+ name: 'helloName'
238
+ }, multistream([
239
+ { stream: pretty() }
240
+ ]))
241
+
242
+ log.info('pretty print')
243
+ })
244
+
245
+ test('children support custom levels', function (t) {
246
+ const stream = writeStream(function (data, enc, cb) {
247
+ t.equal(JSON.parse(data).msg, 'bar')
248
+ t.end()
249
+ })
250
+ const parent = bingo-logger({
251
+ customLevels: {
252
+ foo: 35
253
+ }
254
+ }, multistream([{ level: 35, stream: stream }]))
255
+ const child = parent.child({ child: 'yes' })
256
+ child.foo('bar')
257
+ })
258
+
259
+ test('levelVal ovverides level', function (t) {
260
+ let messageCount = 0
261
+ const stream = writeStream(function (data, enc, cb) {
262
+ messageCount += 1
263
+ cb()
264
+ })
265
+ const streams = [
266
+ { stream: stream },
267
+ { level: 'blabla', levelVal: 15, stream: stream },
268
+ { level: 60, stream: stream }
269
+ ]
270
+ const log = bingo-logger({
271
+ level: 'debug'
272
+ }, multistream(streams))
273
+ log.info('info stream')
274
+ log.debug('debug stream')
275
+ log.fatal('fatal stream')
276
+ t.equal(messageCount, 6)
277
+ t.end()
278
+ })
279
+
280
+ test('forwards metadata', function (t) {
281
+ t.plan(4)
282
+ const streams = [
283
+ {
284
+ stream: {
285
+ [Symbol.for('bingo-logger.metadata')]: true,
286
+ write (chunk) {
287
+ t.equal(log, this.lastLogger)
288
+ t.equal(30, this.lastLevel)
289
+ t.same({ hello: 'world' }, this.lastObj)
290
+ t.same('a msg', this.lastMsg)
291
+ }
292
+ }
293
+ }
294
+ ]
295
+
296
+ const log = bingo-logger({
297
+ level: 'debug'
298
+ }, multistream(streams))
299
+
300
+ log.info({ hello: 'world' }, 'a msg')
301
+ t.end()
302
+ })
303
+
304
+ test('forward name', function (t) {
305
+ t.plan(2)
306
+ const streams = [
307
+ {
308
+ stream: {
309
+ [Symbol.for('bingo-logger.metadata')]: true,
310
+ write (chunk) {
311
+ const line = JSON.parse(chunk)
312
+ t.equal(line.name, 'helloName')
313
+ t.equal(line.hello, 'world')
314
+ }
315
+ }
316
+ }
317
+ ]
318
+
319
+ const log = bingo-logger({
320
+ level: 'debug',
321
+ name: 'helloName'
322
+ }, multistream(streams))
323
+
324
+ log.info({ hello: 'world' }, 'a msg')
325
+ t.end()
326
+ })
327
+
328
+ test('forward name with child', function (t) {
329
+ t.plan(3)
330
+ const streams = [
331
+ {
332
+ stream: {
333
+ write (chunk) {
334
+ const line = JSON.parse(chunk)
335
+ t.equal(line.name, 'helloName')
336
+ t.equal(line.hello, 'world')
337
+ t.equal(line.component, 'aComponent')
338
+ }
339
+ }
340
+ }
341
+ ]
342
+
343
+ const log = bingo-logger({
344
+ level: 'debug',
345
+ name: 'helloName'
346
+ }, multistream(streams)).child({ component: 'aComponent' })
347
+
348
+ log.info({ hello: 'world' }, 'a msg')
349
+ t.end()
350
+ })
351
+
352
+ test('clone generates a new multistream with all stream at the same level', function (t) {
353
+ let messageCount = 0
354
+ const stream = writeStream(function (data, enc, cb) {
355
+ messageCount += 1
356
+ cb()
357
+ })
358
+ const streams = [
359
+ { stream: stream },
360
+ { level: 'debug', stream: stream },
361
+ { level: 'trace', stream: stream },
362
+ { level: 'fatal', stream: stream }
363
+ ]
364
+ const ms = multistream(streams)
365
+ const clone = ms.clone(30)
366
+
367
+ t.not(clone, ms)
368
+
369
+ clone.streams.forEach((s, i) => {
370
+ t.not(s, streams[i])
371
+ t.equal(s.stream, streams[i].stream)
372
+ t.equal(s.level, 30)
373
+ })
374
+
375
+ const log = bingo-logger({
376
+ level: 'trace'
377
+ }, clone)
378
+
379
+ log.info('info stream')
380
+ log.debug('debug message not counted')
381
+ log.fatal('fatal stream')
382
+ t.equal(messageCount, 8)
383
+
384
+ t.end()
385
+ })
386
+
387
+ test('one stream', function (t) {
388
+ let messageCount = 0
389
+ const stream = writeStream(function (data, enc, cb) {
390
+ messageCount += 1
391
+ cb()
392
+ })
393
+ const log = bingo-logger({
394
+ level: 'trace'
395
+ }, multistream({ stream, level: 'fatal' }))
396
+ log.info('info stream')
397
+ log.debug('debug stream')
398
+ log.fatal('fatal stream')
399
+ t.equal(messageCount, 1)
400
+ t.end()
401
+ })
402
+
403
+ test('dedupe', function (t) {
404
+ let messageCount = 0
405
+ const stream1 = writeStream(function (data, enc, cb) {
406
+ messageCount -= 1
407
+ cb()
408
+ })
409
+
410
+ const stream2 = writeStream(function (data, enc, cb) {
411
+ messageCount += 1
412
+ cb()
413
+ })
414
+
415
+ const streams = [
416
+ {
417
+ stream: stream1,
418
+ level: 'info'
419
+ },
420
+ {
421
+ stream: stream2,
422
+ level: 'fatal'
423
+ }
424
+ ]
425
+
426
+ const log = bingo-logger({
427
+ level: 'trace'
428
+ }, multistream(streams, { dedupe: true }))
429
+ log.info('info stream')
430
+ log.fatal('fatal stream')
431
+ log.fatal('fatal stream')
432
+ t.equal(messageCount, 1)
433
+ t.end()
434
+ })
435
+
436
+ test('dedupe when some streams has the same level', function (t) {
437
+ let messageCount = 0
438
+ const stream1 = writeStream(function (data, enc, cb) {
439
+ messageCount -= 1
440
+ cb()
441
+ })
442
+
443
+ const stream2 = writeStream(function (data, enc, cb) {
444
+ messageCount += 1
445
+ cb()
446
+ })
447
+
448
+ const stream3 = writeStream(function (data, enc, cb) {
449
+ messageCount += 1
450
+ cb()
451
+ })
452
+
453
+ const streams = [
454
+ {
455
+ stream: stream1,
456
+ level: 'info'
457
+ },
458
+ {
459
+ stream: stream2,
460
+ level: 'fatal'
461
+ },
462
+ {
463
+ stream: stream3,
464
+ level: 'fatal'
465
+ }
466
+ ]
467
+
468
+ const log = bingo-logger({
469
+ level: 'trace'
470
+ }, multistream(streams, { dedupe: true }))
471
+ log.info('info stream')
472
+ log.fatal('fatal streams')
473
+ log.fatal('fatal streams')
474
+ t.equal(messageCount, 3)
475
+ t.end()
476
+ })
477
+
478
+ test('no stream', function (t) {
479
+ const log = bingo-logger({
480
+ level: 'trace'
481
+ }, multistream())
482
+ log.info('info stream')
483
+ log.debug('debug stream')
484
+ log.fatal('fatal stream')
485
+ t.end()
486
+ })
487
+
488
+ test('one stream', function (t) {
489
+ let messageCount = 0
490
+ const stream = writeStream(function (data, enc, cb) {
491
+ messageCount += 1
492
+ cb()
493
+ })
494
+ const log = bingo-logger({
495
+ level: 'trace'
496
+ }, multistream(stream))
497
+ log.info('info stream')
498
+ log.debug('debug stream')
499
+ log.fatal('fatal stream')
500
+ t.equal(messageCount, 2)
501
+ t.end()
502
+ })
503
+
504
+ test('add a stream', function (t) {
505
+ let messageCount = 0
506
+ const stream = writeStream(function (data, enc, cb) {
507
+ messageCount += 1
508
+ cb()
509
+ })
510
+
511
+ const log = bingo-logger({
512
+ level: 'trace'
513
+ }, multistream().add(stream))
514
+ log.info('info stream')
515
+ log.debug('debug stream')
516
+ log.fatal('fatal stream')
517
+ t.equal(messageCount, 2)
518
+ t.end()
519
+ })
520
+
521
+ test('multistream.add throws if not a stream', function (t) {
522
+ try {
523
+ bingo-logger({
524
+ level: 'trace'
525
+ }, multistream().add({}))
526
+ } catch (_) {
527
+ t.end()
528
+ }
529
+ })
530
+
531
+ test('multistream throws if not a stream', function (t) {
532
+ try {
533
+ bingo-logger({
534
+ level: 'trace'
535
+ }, multistream({}))
536
+ } catch (_) {
537
+ t.end()
538
+ }
539
+ })
540
+
541
+ test('flushSync', function (t) {
542
+ const tmp = file()
543
+ const destination = bingo-logger.destination({ dest: tmp, sync: false, minLength: 4096 })
544
+ const log = bingo-logger({ level: 'info' }, multistream([{ level: 'info', stream: destination }]))
545
+ destination.on('ready', () => {
546
+ log.info('foo')
547
+ log.info('bar')
548
+ t.equal(readFileSync(tmp, { encoding: 'utf-8' }).split('\n').length - 1, 0)
549
+ bingo-logger.final(log, (err, finalLogger) => {
550
+ if (err) {
551
+ t.fail()
552
+ return t.end()
553
+ }
554
+ t.equal(readFileSync(tmp, { encoding: 'utf-8' }).split('\n').length - 1, 2)
555
+ finalLogger.info('biz')
556
+ t.equal(readFileSync(tmp, { encoding: 'utf-8' }).split('\n').length - 1, 3)
557
+ t.end()
558
+ })()
559
+ })
560
+ })
561
+
562
+ test('ends all streams', function (t) {
563
+ t.plan(7)
564
+ const stream = writeStream(function (data, enc, cb) {
565
+ t.pass('message')
566
+ cb()
567
+ })
568
+ stream.flushSync = function () {
569
+ t.pass('flushSync')
570
+ }
571
+ // stream2 has no flushSync
572
+ const stream2 = writeStream(function (data, enc, cb) {
573
+ t.pass('message2')
574
+ cb()
575
+ })
576
+ const streams = [
577
+ { stream: stream },
578
+ { level: 'debug', stream: stream },
579
+ { level: 'trace', stream: stream2 },
580
+ { level: 'fatal', stream: stream },
581
+ { level: 'silent', stream: stream }
582
+ ]
583
+ const multi = multistream(streams)
584
+ const log = bingo-logger({
585
+ level: 'trace'
586
+ }, multi)
587
+ log.info('info stream')
588
+ multi.end()
589
+ })