lucide-node 0.0.1-security → 1.0.0

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.

Potentially problematic release.


This version of lucide-node might be problematic. Click here for more details.

Files changed (200) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +8 -0
  3. package/.github/dependabot.yml +13 -0
  4. package/.github/workflows/bench.yml +61 -0
  5. package/.github/workflows/ci.yml +88 -0
  6. package/.github/workflows/lock-threads.yml +30 -0
  7. package/.github/workflows/target-main.yml +23 -0
  8. package/.nojekyll +0 -0
  9. package/.prettierignore +1 -0
  10. package/.taprc.yaml +8 -0
  11. package/CNAME +1 -0
  12. package/CONTRIBUTING.md +30 -0
  13. package/LICENSE +21 -0
  14. package/README.md +159 -3
  15. package/SECURITY.md +68 -0
  16. package/benchmarks/basic.bench.js +95 -0
  17. package/benchmarks/child-child.bench.js +52 -0
  18. package/benchmarks/child-creation.bench.js +73 -0
  19. package/benchmarks/child.bench.js +62 -0
  20. package/benchmarks/deep-object.bench.js +88 -0
  21. package/benchmarks/formatters.bench.js +50 -0
  22. package/benchmarks/internal/custom-levels.js +67 -0
  23. package/benchmarks/internal/just-pino-heavy.bench.js +76 -0
  24. package/benchmarks/internal/just-pino.bench.js +182 -0
  25. package/benchmarks/internal/parent-vs-child.bench.js +75 -0
  26. package/benchmarks/internal/redact.bench.js +86 -0
  27. package/benchmarks/long-string.bench.js +81 -0
  28. package/benchmarks/multi-arg.bench.js +193 -0
  29. package/benchmarks/multistream.js +98 -0
  30. package/benchmarks/object.bench.js +82 -0
  31. package/benchmarks/utils/generate-benchmark-doc.js +36 -0
  32. package/benchmarks/utils/runbench.js +138 -0
  33. package/benchmarks/utils/wrap-log-level.js +55 -0
  34. package/bin.js +6 -0
  35. package/browser.js +484 -0
  36. package/build/sync-version.js +10 -0
  37. package/docs/api.md +1487 -0
  38. package/docs/asynchronous.md +40 -0
  39. package/docs/benchmarks.md +55 -0
  40. package/docs/browser.md +227 -0
  41. package/docs/bundling.md +40 -0
  42. package/docs/child-loggers.md +95 -0
  43. package/docs/ecosystem.md +84 -0
  44. package/docs/help.md +345 -0
  45. package/docs/lts.md +64 -0
  46. package/docs/pretty.md +35 -0
  47. package/docs/redaction.md +135 -0
  48. package/docs/transports.md +1238 -0
  49. package/docs/web.md +269 -0
  50. package/docsify/sidebar.md +26 -0
  51. package/examples/basic.js +43 -0
  52. package/examples/transport.js +68 -0
  53. package/favicon-16x16.png +0 -0
  54. package/favicon-32x32.png +0 -0
  55. package/favicon.ico +0 -0
  56. package/file.js +12 -0
  57. package/inc-version.sh +42 -0
  58. package/index.html +55 -0
  59. package/lib/caller.js +30 -0
  60. package/lib/constants.js +28 -0
  61. package/lib/deprecations.js +8 -0
  62. package/lib/levels.js +241 -0
  63. package/lib/meta.js +3 -0
  64. package/lib/multistream.js +188 -0
  65. package/lib/proto.js +234 -0
  66. package/lib/redaction.js +118 -0
  67. package/lib/symbols.js +74 -0
  68. package/lib/time.js +11 -0
  69. package/lib/tools.js +394 -0
  70. package/lib/transport-stream.js +56 -0
  71. package/lib/transport.js +167 -0
  72. package/lib/worker.js +194 -0
  73. package/lib/writer.js +42 -0
  74. package/package.json +117 -3
  75. package/pino-banner.png +0 -0
  76. package/pino-logo-hire.png +0 -0
  77. package/pino-tree.png +0 -0
  78. package/pino.d.ts +889 -0
  79. package/pino.js +236 -0
  80. package/pretty-demo.png +0 -0
  81. package/test/basic.test.js +874 -0
  82. package/test/broken-pipe.test.js +57 -0
  83. package/test/browser-child.test.js +132 -0
  84. package/test/browser-disabled.test.js +87 -0
  85. package/test/browser-early-console-freeze.test.js +12 -0
  86. package/test/browser-levels.test.js +241 -0
  87. package/test/browser-serializers.test.js +352 -0
  88. package/test/browser-timestamp.test.js +88 -0
  89. package/test/browser-transmit.test.js +417 -0
  90. package/test/browser.test.js +659 -0
  91. package/test/complex-objects.test.js +34 -0
  92. package/test/crlf.test.js +32 -0
  93. package/test/custom-levels.test.js +253 -0
  94. package/test/error.test.js +398 -0
  95. package/test/errorKey.test.js +34 -0
  96. package/test/escaping.test.js +91 -0
  97. package/test/esm/esm.mjs +12 -0
  98. package/test/esm/index.test.js +34 -0
  99. package/test/esm/named-exports.mjs +27 -0
  100. package/test/exit.test.js +77 -0
  101. package/test/fixtures/broken-pipe/basic.js +9 -0
  102. package/test/fixtures/broken-pipe/destination.js +10 -0
  103. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  104. package/test/fixtures/console-transport.js +13 -0
  105. package/test/fixtures/default-exit.js +8 -0
  106. package/test/fixtures/destination-exit.js +8 -0
  107. package/test/fixtures/eval/index.js +13 -0
  108. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  109. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  110. package/test/fixtures/eval/node_modules/file1.js +5 -0
  111. package/test/fixtures/eval/node_modules/file10.js +5 -0
  112. package/test/fixtures/eval/node_modules/file11.js +5 -0
  113. package/test/fixtures/eval/node_modules/file12.js +5 -0
  114. package/test/fixtures/eval/node_modules/file13.js +5 -0
  115. package/test/fixtures/eval/node_modules/file14.js +11 -0
  116. package/test/fixtures/eval/node_modules/file2.js +5 -0
  117. package/test/fixtures/eval/node_modules/file3.js +5 -0
  118. package/test/fixtures/eval/node_modules/file4.js +5 -0
  119. package/test/fixtures/eval/node_modules/file5.js +5 -0
  120. package/test/fixtures/eval/node_modules/file6.js +5 -0
  121. package/test/fixtures/eval/node_modules/file7.js +5 -0
  122. package/test/fixtures/eval/node_modules/file8.js +5 -0
  123. package/test/fixtures/eval/node_modules/file9.js +5 -0
  124. package/test/fixtures/noop-transport.js +10 -0
  125. package/test/fixtures/pretty/null-prototype.js +8 -0
  126. package/test/fixtures/stdout-hack-protection.js +11 -0
  127. package/test/fixtures/syncfalse-child.js +6 -0
  128. package/test/fixtures/syncfalse-exit.js +9 -0
  129. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  130. package/test/fixtures/syncfalse.js +6 -0
  131. package/test/fixtures/syntax-error-esm.mjs +2 -0
  132. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  133. package/test/fixtures/to-file-transport.js +13 -0
  134. package/test/fixtures/to-file-transport.mjs +8 -0
  135. package/test/fixtures/transport/index.js +12 -0
  136. package/test/fixtures/transport/package.json +5 -0
  137. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  138. package/test/fixtures/transport-exit-immediately.js +11 -0
  139. package/test/fixtures/transport-exit-on-ready.js +12 -0
  140. package/test/fixtures/transport-main.js +9 -0
  141. package/test/fixtures/transport-many-lines.js +29 -0
  142. package/test/fixtures/transport-string-stdout.js +9 -0
  143. package/test/fixtures/transport-transform.js +21 -0
  144. package/test/fixtures/transport-uses-pino-config.js +33 -0
  145. package/test/fixtures/transport-with-on-exit.js +12 -0
  146. package/test/fixtures/transport-worker-data.js +19 -0
  147. package/test/fixtures/transport-worker.js +15 -0
  148. package/test/fixtures/transport-wrong-export-type.js +3 -0
  149. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  150. package/test/fixtures/ts/to-file-transport.ts +11 -0
  151. package/test/fixtures/ts/transpile.cjs +36 -0
  152. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  153. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  154. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  155. package/test/fixtures/ts/transport-main.ts +8 -0
  156. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  157. package/test/fixtures/ts/transport-worker.ts +14 -0
  158. package/test/formatters.test.js +355 -0
  159. package/test/helper.d.ts +4 -0
  160. package/test/helper.js +128 -0
  161. package/test/hooks.test.js +118 -0
  162. package/test/http.test.js +242 -0
  163. package/test/internals/version.test.js +15 -0
  164. package/test/is-level-enabled.test.js +185 -0
  165. package/test/jest/basic.spec.js +10 -0
  166. package/test/levels.test.js +772 -0
  167. package/test/metadata.test.js +106 -0
  168. package/test/mixin-merge-strategy.test.js +55 -0
  169. package/test/mixin.test.js +218 -0
  170. package/test/multistream.test.js +673 -0
  171. package/test/pkg/index.js +46 -0
  172. package/test/pkg/pkg.config.json +17 -0
  173. package/test/pkg/pkg.test.js +56 -0
  174. package/test/redact.test.js +847 -0
  175. package/test/serializers.test.js +253 -0
  176. package/test/stdout-protection.test.js +39 -0
  177. package/test/syncfalse.test.js +188 -0
  178. package/test/timestamp.test.js +121 -0
  179. package/test/transport/big.test.js +43 -0
  180. package/test/transport/bundlers-support.test.js +97 -0
  181. package/test/transport/caller.test.js +23 -0
  182. package/test/transport/core.test.js +644 -0
  183. package/test/transport/core.test.ts +236 -0
  184. package/test/transport/core.transpiled.test.ts +112 -0
  185. package/test/transport/module-link.test.js +239 -0
  186. package/test/transport/pipeline.test.js +135 -0
  187. package/test/transport/repl.test.js +14 -0
  188. package/test/transport/syncTrue.test.js +55 -0
  189. package/test/transport/syncfalse.test.js +68 -0
  190. package/test/transport/targets.test.js +44 -0
  191. package/test/transport/uses-pino-config.test.js +167 -0
  192. package/test/transport-stream.test.js +26 -0
  193. package/test/types/pino-import.test-d.ts +29 -0
  194. package/test/types/pino-multistream.test-d.ts +28 -0
  195. package/test/types/pino-top-export.test-d.ts +35 -0
  196. package/test/types/pino-transport.test-d.ts +145 -0
  197. package/test/types/pino-type-only.test-d.ts +64 -0
  198. package/test/types/pino.test-d.ts +468 -0
  199. package/test/types/pino.ts +78 -0
  200. package/tsconfig.json +14 -0
@@ -0,0 +1,673 @@
1
+ 'use strict'
2
+
3
+ const writeStream = require('flush-write-stream')
4
+ const { readFileSync } = require('node:fs')
5
+ const { join } = require('node:path')
6
+ const test = require('tap').test
7
+ const pino = require('../')
8
+ const multistream = pino.multistream
9
+ const proxyquire = require('proxyquire')
10
+ const strip = require('strip-ansi')
11
+ const { file, sink } = require('./helper')
12
+
13
+ test('sends to multiple streams using string levels', function (t) {
14
+ let messageCount = 0
15
+ const stream = writeStream(function (data, enc, cb) {
16
+ messageCount += 1
17
+ cb()
18
+ })
19
+ const streams = [
20
+ { stream },
21
+ { level: 'debug', stream },
22
+ { level: 'trace', stream },
23
+ { level: 'fatal', stream },
24
+ { level: 'silent', stream }
25
+ ]
26
+ const log = pino({
27
+ level: 'trace'
28
+ }, multistream(streams))
29
+ log.info('info stream')
30
+ log.debug('debug stream')
31
+ log.fatal('fatal stream')
32
+ t.equal(messageCount, 9)
33
+ t.end()
34
+ })
35
+
36
+ test('sends to multiple streams using custom levels', function (t) {
37
+ let messageCount = 0
38
+ const stream = writeStream(function (data, enc, cb) {
39
+ messageCount += 1
40
+ cb()
41
+ })
42
+ const streams = [
43
+ { stream },
44
+ { level: 'debug', stream },
45
+ { level: 'trace', stream },
46
+ { level: 'fatal', stream },
47
+ { level: 'silent', stream }
48
+ ]
49
+ const log = pino({
50
+ level: 'trace'
51
+ }, multistream(streams))
52
+ log.info('info stream')
53
+ log.debug('debug stream')
54
+ log.fatal('fatal stream')
55
+ t.equal(messageCount, 9)
56
+ t.end()
57
+ })
58
+
59
+ test('sends to multiple streams using optionally predefined levels', function (t) {
60
+ let messageCount = 0
61
+ const stream = writeStream(function (data, enc, cb) {
62
+ messageCount += 1
63
+ cb()
64
+ })
65
+ const opts = {
66
+ levels: {
67
+ silent: Infinity,
68
+ fatal: 60,
69
+ error: 50,
70
+ warn: 50,
71
+ info: 30,
72
+ debug: 20,
73
+ trace: 10
74
+ }
75
+ }
76
+ const streams = [
77
+ { stream },
78
+ { level: 'trace', stream },
79
+ { level: 'debug', stream },
80
+ { level: 'info', stream },
81
+ { level: 'warn', stream },
82
+ { level: 'error', stream },
83
+ { level: 'fatal', stream },
84
+ { level: 'silent', stream }
85
+ ]
86
+ const mstream = multistream(streams, opts)
87
+ const log = pino({
88
+ level: 'trace'
89
+ }, mstream)
90
+ log.trace('trace stream')
91
+ log.debug('debug stream')
92
+ log.info('info stream')
93
+ log.warn('warn stream')
94
+ log.error('error stream')
95
+ log.fatal('fatal stream')
96
+ log.silent('silent stream')
97
+ t.equal(messageCount, 24)
98
+ t.end()
99
+ })
100
+
101
+ test('sends to multiple streams using number levels', function (t) {
102
+ let messageCount = 0
103
+ const stream = writeStream(function (data, enc, cb) {
104
+ messageCount += 1
105
+ cb()
106
+ })
107
+ const streams = [
108
+ { stream },
109
+ { level: 20, stream },
110
+ { level: 60, stream }
111
+ ]
112
+ const log = pino({
113
+ level: 'debug'
114
+ }, multistream(streams))
115
+ log.info('info stream')
116
+ log.debug('debug stream')
117
+ log.fatal('fatal stream')
118
+ t.equal(messageCount, 6)
119
+ t.end()
120
+ })
121
+
122
+ test('level include higher levels', function (t) {
123
+ let messageCount = 0
124
+ const stream = writeStream(function (data, enc, cb) {
125
+ messageCount += 1
126
+ cb()
127
+ })
128
+ const log = pino({}, multistream([{ level: 'info', stream }]))
129
+ log.fatal('message')
130
+ t.equal(messageCount, 1)
131
+ t.end()
132
+ })
133
+
134
+ test('supports multiple arguments', function (t) {
135
+ const messages = []
136
+ const stream = writeStream(function (data, enc, cb) {
137
+ messages.push(JSON.parse(data))
138
+ if (messages.length === 2) {
139
+ const msg1 = messages[0]
140
+ t.equal(msg1.msg, 'foo bar baz foobar')
141
+
142
+ const msg2 = messages[1]
143
+ t.equal(msg2.msg, 'foo bar baz foobar barfoo foofoo')
144
+
145
+ t.end()
146
+ }
147
+ cb()
148
+ })
149
+ const log = pino({}, multistream({ stream }))
150
+ log.info('%s %s %s %s', 'foo', 'bar', 'baz', 'foobar') // apply not invoked
151
+ log.info('%s %s %s %s %s %s', 'foo', 'bar', 'baz', 'foobar', 'barfoo', 'foofoo') // apply invoked
152
+ })
153
+
154
+ test('supports children', function (t) {
155
+ const stream = writeStream(function (data, enc, cb) {
156
+ const input = JSON.parse(data)
157
+ t.equal(input.msg, 'child stream')
158
+ t.equal(input.child, 'one')
159
+ t.end()
160
+ cb()
161
+ })
162
+ const streams = [
163
+ { stream }
164
+ ]
165
+ const log = pino({}, multistream(streams)).child({ child: 'one' })
166
+ log.info('child stream')
167
+ })
168
+
169
+ test('supports grandchildren', function (t) {
170
+ const messages = []
171
+ const stream = writeStream(function (data, enc, cb) {
172
+ messages.push(JSON.parse(data))
173
+ if (messages.length === 3) {
174
+ const msg1 = messages[0]
175
+ t.equal(msg1.msg, 'grandchild stream')
176
+ t.equal(msg1.child, 'one')
177
+ t.equal(msg1.grandchild, 'two')
178
+
179
+ const msg2 = messages[1]
180
+ t.equal(msg2.msg, 'grandchild stream')
181
+ t.equal(msg2.child, 'one')
182
+ t.equal(msg2.grandchild, 'two')
183
+
184
+ const msg3 = messages[2]
185
+ t.equal(msg3.msg, 'debug grandchild')
186
+ t.equal(msg3.child, 'one')
187
+ t.equal(msg3.grandchild, 'two')
188
+
189
+ t.end()
190
+ }
191
+ cb()
192
+ })
193
+ const streams = [
194
+ { stream },
195
+ { level: 'debug', stream }
196
+ ]
197
+ const log = pino({
198
+ level: 'debug'
199
+ }, multistream(streams)).child({ child: 'one' }).child({ grandchild: 'two' })
200
+ log.info('grandchild stream')
201
+ log.debug('debug grandchild')
202
+ })
203
+
204
+ test('supports custom levels', function (t) {
205
+ const stream = writeStream(function (data, enc, cb) {
206
+ t.equal(JSON.parse(data).msg, 'bar')
207
+ t.end()
208
+ })
209
+ const log = pino({
210
+ customLevels: {
211
+ foo: 35
212
+ }
213
+ }, multistream([{ level: 35, stream }]))
214
+ log.foo('bar')
215
+ })
216
+
217
+ test('supports pretty print', function (t) {
218
+ t.plan(2)
219
+ const stream = writeStream(function (data, enc, cb) {
220
+ t.not(strip(data.toString()).match(/INFO.*: pretty print/), null)
221
+ cb()
222
+ })
223
+
224
+ const safeBoom = proxyquire('pino-pretty/lib/utils/build-safe-sonic-boom.js', {
225
+ 'sonic-boom': function () {
226
+ t.pass('sonic created')
227
+ stream.flushSync = () => {}
228
+ stream.flush = () => {}
229
+ return stream
230
+ }
231
+ })
232
+ const nested = proxyquire('pino-pretty/lib/utils/index.js', {
233
+ './build-safe-sonic-boom.js': safeBoom
234
+ })
235
+ const pretty = proxyquire('pino-pretty', {
236
+ './lib/utils/index.js': nested
237
+ })
238
+
239
+ const log = pino({
240
+ level: 'debug',
241
+ name: 'helloName'
242
+ }, multistream([
243
+ { stream: pretty() }
244
+ ]))
245
+
246
+ log.info('pretty print')
247
+ })
248
+
249
+ test('emit propagates events to each stream', function (t) {
250
+ t.plan(3)
251
+ const handler = function (data) {
252
+ t.equal(data.msg, 'world')
253
+ }
254
+ const streams = [sink(), sink(), sink()]
255
+ streams.forEach(function (s) {
256
+ s.once('hello', handler)
257
+ })
258
+ const stream = multistream(streams)
259
+ stream.emit('hello', { msg: 'world' })
260
+ })
261
+
262
+ test('children support custom levels', function (t) {
263
+ const stream = writeStream(function (data, enc, cb) {
264
+ t.equal(JSON.parse(data).msg, 'bar')
265
+ t.end()
266
+ })
267
+ const parent = pino({
268
+ customLevels: {
269
+ foo: 35
270
+ }
271
+ }, multistream([{ level: 35, stream }]))
272
+ const child = parent.child({ child: 'yes' })
273
+ child.foo('bar')
274
+ })
275
+
276
+ test('levelVal overrides level', function (t) {
277
+ let messageCount = 0
278
+ const stream = writeStream(function (data, enc, cb) {
279
+ messageCount += 1
280
+ cb()
281
+ })
282
+ const streams = [
283
+ { stream },
284
+ { level: 'blabla', levelVal: 15, stream },
285
+ { level: 60, stream }
286
+ ]
287
+ const log = pino({
288
+ level: 'debug'
289
+ }, multistream(streams))
290
+ log.info('info stream')
291
+ log.debug('debug stream')
292
+ log.fatal('fatal stream')
293
+ t.equal(messageCount, 6)
294
+ t.end()
295
+ })
296
+
297
+ test('forwards metadata', function (t) {
298
+ t.plan(4)
299
+ const streams = [
300
+ {
301
+ stream: {
302
+ [Symbol.for('pino.metadata')]: true,
303
+ write (chunk) {
304
+ t.equal(log, this.lastLogger)
305
+ t.equal(30, this.lastLevel)
306
+ t.same({ hello: 'world' }, this.lastObj)
307
+ t.same('a msg', this.lastMsg)
308
+ }
309
+ }
310
+ }
311
+ ]
312
+
313
+ const log = pino({
314
+ level: 'debug'
315
+ }, multistream(streams))
316
+
317
+ log.info({ hello: 'world' }, 'a msg')
318
+ t.end()
319
+ })
320
+
321
+ test('forward name', function (t) {
322
+ t.plan(2)
323
+ const streams = [
324
+ {
325
+ stream: {
326
+ [Symbol.for('pino.metadata')]: true,
327
+ write (chunk) {
328
+ const line = JSON.parse(chunk)
329
+ t.equal(line.name, 'helloName')
330
+ t.equal(line.hello, 'world')
331
+ }
332
+ }
333
+ }
334
+ ]
335
+
336
+ const log = pino({
337
+ level: 'debug',
338
+ name: 'helloName'
339
+ }, multistream(streams))
340
+
341
+ log.info({ hello: 'world' }, 'a msg')
342
+ t.end()
343
+ })
344
+
345
+ test('forward name with child', function (t) {
346
+ t.plan(3)
347
+ const streams = [
348
+ {
349
+ stream: {
350
+ write (chunk) {
351
+ const line = JSON.parse(chunk)
352
+ t.equal(line.name, 'helloName')
353
+ t.equal(line.hello, 'world')
354
+ t.equal(line.component, 'aComponent')
355
+ }
356
+ }
357
+ }
358
+ ]
359
+
360
+ const log = pino({
361
+ level: 'debug',
362
+ name: 'helloName'
363
+ }, multistream(streams)).child({ component: 'aComponent' })
364
+
365
+ log.info({ hello: 'world' }, 'a msg')
366
+ t.end()
367
+ })
368
+
369
+ test('clone generates a new multistream with all stream at the same level', function (t) {
370
+ let messageCount = 0
371
+ const stream = writeStream(function (data, enc, cb) {
372
+ messageCount += 1
373
+ cb()
374
+ })
375
+ const streams = [
376
+ { stream },
377
+ { level: 'debug', stream },
378
+ { level: 'trace', stream },
379
+ { level: 'fatal', stream }
380
+ ]
381
+ const ms = multistream(streams)
382
+ const clone = ms.clone(30)
383
+
384
+ t.not(clone, ms)
385
+
386
+ clone.streams.forEach((s, i) => {
387
+ t.not(s, streams[i])
388
+ t.equal(s.stream, streams[i].stream)
389
+ t.equal(s.level, 30)
390
+ })
391
+
392
+ const log = pino({
393
+ level: 'trace'
394
+ }, clone)
395
+
396
+ log.info('info stream')
397
+ log.debug('debug message not counted')
398
+ log.fatal('fatal stream')
399
+ t.equal(messageCount, 8)
400
+
401
+ t.end()
402
+ })
403
+
404
+ test('one stream', function (t) {
405
+ let messageCount = 0
406
+ const stream = writeStream(function (data, enc, cb) {
407
+ messageCount += 1
408
+ cb()
409
+ })
410
+ const log = pino({
411
+ level: 'trace'
412
+ }, multistream({ stream, level: 'fatal' }))
413
+ log.info('info stream')
414
+ log.debug('debug stream')
415
+ log.fatal('fatal stream')
416
+ t.equal(messageCount, 1)
417
+ t.end()
418
+ })
419
+
420
+ test('dedupe', function (t) {
421
+ let messageCount = 0
422
+ const stream1 = writeStream(function (data, enc, cb) {
423
+ messageCount -= 1
424
+ cb()
425
+ })
426
+
427
+ const stream2 = writeStream(function (data, enc, cb) {
428
+ messageCount += 1
429
+ cb()
430
+ })
431
+
432
+ const streams = [
433
+ {
434
+ stream: stream1,
435
+ level: 'info'
436
+ },
437
+ {
438
+ stream: stream2,
439
+ level: 'fatal'
440
+ }
441
+ ]
442
+
443
+ const log = pino({
444
+ level: 'trace'
445
+ }, multistream(streams, { dedupe: true }))
446
+ log.info('info stream')
447
+ log.fatal('fatal stream')
448
+ log.fatal('fatal stream')
449
+ t.equal(messageCount, 1)
450
+ t.end()
451
+ })
452
+
453
+ test('dedupe when logs have different levels', function (t) {
454
+ let messageCount = 0
455
+ const stream1 = writeStream(function (data, enc, cb) {
456
+ messageCount += 1
457
+ cb()
458
+ })
459
+
460
+ const stream2 = writeStream(function (data, enc, cb) {
461
+ messageCount += 2
462
+ cb()
463
+ })
464
+
465
+ const streams = [
466
+ {
467
+ stream: stream1,
468
+ level: 'info'
469
+ },
470
+ {
471
+ stream: stream2,
472
+ level: 'error'
473
+ }
474
+ ]
475
+
476
+ const log = pino({
477
+ level: 'trace'
478
+ }, multistream(streams, { dedupe: true }))
479
+
480
+ log.info('info stream')
481
+ log.warn('warn stream')
482
+ log.error('error streams')
483
+ log.fatal('fatal streams')
484
+ t.equal(messageCount, 6)
485
+ t.end()
486
+ })
487
+
488
+ test('dedupe when some streams has the same level', function (t) {
489
+ let messageCount = 0
490
+ const stream1 = writeStream(function (data, enc, cb) {
491
+ messageCount -= 1
492
+ cb()
493
+ })
494
+
495
+ const stream2 = writeStream(function (data, enc, cb) {
496
+ messageCount += 1
497
+ cb()
498
+ })
499
+
500
+ const stream3 = writeStream(function (data, enc, cb) {
501
+ messageCount += 1
502
+ cb()
503
+ })
504
+
505
+ const streams = [
506
+ {
507
+ stream: stream1,
508
+ level: 'info'
509
+ },
510
+ {
511
+ stream: stream2,
512
+ level: 'fatal'
513
+ },
514
+ {
515
+ stream: stream3,
516
+ level: 'fatal'
517
+ }
518
+ ]
519
+
520
+ const log = pino({
521
+ level: 'trace'
522
+ }, multistream(streams, { dedupe: true }))
523
+ log.info('info stream')
524
+ log.fatal('fatal streams')
525
+ log.fatal('fatal streams')
526
+ t.equal(messageCount, 3)
527
+ t.end()
528
+ })
529
+
530
+ test('no stream', function (t) {
531
+ const log = pino({
532
+ level: 'trace'
533
+ }, multistream())
534
+ log.info('info stream')
535
+ log.debug('debug stream')
536
+ log.fatal('fatal stream')
537
+ t.end()
538
+ })
539
+
540
+ test('one stream', function (t) {
541
+ let messageCount = 0
542
+ const stream = writeStream(function (data, enc, cb) {
543
+ messageCount += 1
544
+ cb()
545
+ })
546
+ const log = pino({
547
+ level: 'trace'
548
+ }, multistream(stream))
549
+ log.info('info stream')
550
+ log.debug('debug stream')
551
+ log.fatal('fatal stream')
552
+ t.equal(messageCount, 2)
553
+ t.end()
554
+ })
555
+
556
+ test('add a stream', function (t) {
557
+ let messageCount = 0
558
+ const stream = writeStream(function (data, enc, cb) {
559
+ messageCount += 1
560
+ cb()
561
+ })
562
+
563
+ const log = pino({
564
+ level: 'trace'
565
+ }, multistream().add(stream))
566
+ log.info('info stream')
567
+ log.debug('debug stream')
568
+ log.fatal('fatal stream')
569
+ t.equal(messageCount, 2)
570
+ t.end()
571
+ })
572
+
573
+ test('multistream.add throws if not a stream', function (t) {
574
+ try {
575
+ pino({
576
+ level: 'trace'
577
+ }, multistream().add({}))
578
+ } catch (_) {
579
+ t.end()
580
+ }
581
+ })
582
+
583
+ test('multistream throws if not a stream', function (t) {
584
+ try {
585
+ pino({
586
+ level: 'trace'
587
+ }, multistream({}))
588
+ } catch (_) {
589
+ t.end()
590
+ }
591
+ })
592
+
593
+ test('multistream.write should not throw if one stream fails', function (t) {
594
+ let messageCount = 0
595
+ const stream = writeStream(function (data, enc, cb) {
596
+ messageCount += 1
597
+ cb()
598
+ })
599
+ const noopStream = pino.transport({
600
+ target: join(__dirname, 'fixtures', 'noop-transport.js')
601
+ })
602
+ // eslint-disable-next-line
603
+ noopStream.on('error', function (err) {
604
+ // something went wrong while writing to noop stream, ignoring!
605
+ })
606
+ const log = pino({
607
+ level: 'trace'
608
+ },
609
+ multistream([
610
+ {
611
+ level: 'trace',
612
+ stream
613
+ },
614
+ {
615
+ level: 'debug',
616
+ stream: noopStream
617
+ }
618
+ ])
619
+ )
620
+ log.debug('0')
621
+ noopStream.end()
622
+ // noop stream is ending, should emit an error but not throw
623
+ log.debug('1')
624
+ log.debug('2')
625
+ t.equal(messageCount, 3)
626
+ t.end()
627
+ })
628
+
629
+ test('flushSync', function (t) {
630
+ const tmp = file()
631
+ const destination = pino.destination({ dest: tmp, sync: false, minLength: 4096 })
632
+ const stream = multistream([{ level: 'info', stream: destination }])
633
+ const log = pino({ level: 'info' }, stream)
634
+ destination.on('ready', () => {
635
+ log.info('foo')
636
+ log.info('bar')
637
+ stream.flushSync()
638
+ t.equal(readFileSync(tmp, { encoding: 'utf-8' }).split('\n').length - 1, 2)
639
+ log.info('biz')
640
+ stream.flushSync()
641
+ t.equal(readFileSync(tmp, { encoding: 'utf-8' }).split('\n').length - 1, 3)
642
+ t.end()
643
+ })
644
+ })
645
+
646
+ test('ends all streams', function (t) {
647
+ t.plan(7)
648
+ const stream = writeStream(function (data, enc, cb) {
649
+ t.pass('message')
650
+ cb()
651
+ })
652
+ stream.flushSync = function () {
653
+ t.pass('flushSync')
654
+ }
655
+ // stream2 has no flushSync
656
+ const stream2 = writeStream(function (data, enc, cb) {
657
+ t.pass('message2')
658
+ cb()
659
+ })
660
+ const streams = [
661
+ { stream },
662
+ { level: 'debug', stream },
663
+ { level: 'trace', stream: stream2 },
664
+ { level: 'fatal', stream },
665
+ { level: 'silent', stream }
666
+ ]
667
+ const multi = multistream(streams)
668
+ const log = pino({
669
+ level: 'trace'
670
+ }, multi)
671
+ log.info('info stream')
672
+ multi.end()
673
+ })
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const os = require('node:os')
4
+ const { join } = require('node:path')
5
+ const { readFile } = require('node:fs').promises
6
+ const { watchFileCreated, file } = require('../helper')
7
+ const { test } = require('tap')
8
+ const pino = require('../../pino')
9
+
10
+ const { pid } = process
11
+ const hostname = os.hostname()
12
+
13
+ /**
14
+ * This file is packaged using pkg in order to test if transport-stream.js works in that context
15
+ */
16
+
17
+ test('pino.transport with worker destination overridden by bundler and mjs transport', async ({ same, teardown }) => {
18
+ globalThis.__bundlerPathsOverrides = {
19
+ 'pino-worker': join(__dirname, '..', '..', 'lib/worker.js')
20
+ }
21
+
22
+ const destination = file()
23
+ const transport = pino.transport({
24
+ targets: [
25
+ {
26
+ target: join(__dirname, '..', 'fixtures', 'ts', 'to-file-transport.es2017.cjs'),
27
+ options: { destination }
28
+ }
29
+ ]
30
+ })
31
+
32
+ teardown(transport.end.bind(transport))
33
+ const instance = pino(transport)
34
+ instance.info('hello')
35
+ await watchFileCreated(destination)
36
+ const result = JSON.parse(await readFile(destination))
37
+ delete result.time
38
+ same(result, {
39
+ pid,
40
+ hostname,
41
+ level: 30,
42
+ msg: 'hello'
43
+ })
44
+
45
+ globalThis.__bundlerPathsOverrides = undefined
46
+ })