pino-testkit 10.4.5
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.
- package/.nojekyll +0 -0
- package/.prettierignore +1 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/SECURITY.md +87 -0
- package/benchmarks/basic.bench.js +95 -0
- package/benchmarks/child-child.bench.js +52 -0
- package/benchmarks/child-creation.bench.js +73 -0
- package/benchmarks/child.bench.js +62 -0
- package/benchmarks/deep-object.bench.js +88 -0
- package/benchmarks/formatters.bench.js +50 -0
- package/benchmarks/internal/custom-levels.js +67 -0
- package/benchmarks/internal/just-pino-heavy.bench.js +76 -0
- package/benchmarks/internal/just-pino.bench.js +182 -0
- package/benchmarks/internal/parent-vs-child.bench.js +75 -0
- package/benchmarks/internal/redact.bench.js +86 -0
- package/benchmarks/long-string.bench.js +81 -0
- package/benchmarks/multi-arg.bench.js +193 -0
- package/benchmarks/multistream.js +98 -0
- package/benchmarks/object.bench.js +82 -0
- package/benchmarks/utils/generate-benchmark-doc.js +36 -0
- package/benchmarks/utils/runbench.js +138 -0
- package/benchmarks/utils/wrap-log-level.js +55 -0
- package/bin.js +6 -0
- package/browser.js +547 -0
- package/build/sync-version.js +25 -0
- package/docs/api.md +1593 -0
- package/docs/asynchronous.md +40 -0
- package/docs/benchmarks.md +55 -0
- package/docs/browser.md +278 -0
- package/docs/bundling.md +40 -0
- package/docs/child-loggers.md +95 -0
- package/docs/diagnostics.md +16 -0
- package/docs/ecosystem.md +86 -0
- package/docs/help.md +345 -0
- package/docs/lts.md +64 -0
- package/docs/pretty.md +35 -0
- package/docs/redaction.md +135 -0
- package/docs/transports.md +1376 -0
- package/docs/web.md +309 -0
- package/eslint.config.js +28 -0
- package/examples/basic.js +43 -0
- package/examples/transport.js +68 -0
- package/favicon.ico +0 -0
- package/file.js +12 -0
- package/inc-version.sh +42 -0
- package/index.html +55 -0
- package/lib/caller.js +30 -0
- package/lib/constants.js +28 -0
- package/lib/contract.js +8 -0
- package/lib/deprecations.js +8 -0
- package/lib/levels.js +241 -0
- package/lib/meta.js +3 -0
- package/lib/multistream.js +203 -0
- package/lib/proto.js +256 -0
- package/lib/redaction.js +114 -0
- package/lib/symbols.js +74 -0
- package/lib/time.js +39 -0
- package/lib/tools.js +427 -0
- package/lib/transport-stream.js +56 -0
- package/lib/transport.js +289 -0
- package/lib/worker.js +194 -0
- package/package.json +119 -0
- package/pino.d.ts +908 -0
- package/pino.js +240 -0
- package/test/basic.test.js +886 -0
- package/test/broken-pipe.test.js +59 -0
- package/test/browser-child.test.js +132 -0
- package/test/browser-disabled.test.js +87 -0
- package/test/browser-early-console-freeze.test.js +12 -0
- package/test/browser-is-level-enabled.test.js +101 -0
- package/test/browser-levels.test.js +241 -0
- package/test/browser-serializers.test.js +352 -0
- package/test/browser-timestamp.test.js +88 -0
- package/test/browser-transmit.test.js +417 -0
- package/test/browser.test.js +698 -0
- package/test/complex-objects.test.js +36 -0
- package/test/crlf.test.js +34 -0
- package/test/custom-levels.test.js +267 -0
- package/test/diagnostics.test.js +107 -0
- package/test/error-key.test.js +37 -0
- package/test/error.test.js +403 -0
- package/test/escaping.test.js +93 -0
- package/test/esm/esm.mjs +14 -0
- package/test/esm/index.test.js +21 -0
- package/test/esm/named-exports.mjs +29 -0
- package/test/exit.test.js +79 -0
- package/test/fixtures/broken-pipe/basic.js +9 -0
- package/test/fixtures/broken-pipe/destination.js +10 -0
- package/test/fixtures/broken-pipe/syncfalse.js +12 -0
- package/test/fixtures/console-transport.js +13 -0
- package/test/fixtures/crashing-transport.js +13 -0
- package/test/fixtures/default-exit.js +8 -0
- package/test/fixtures/destination-exit.js +8 -0
- package/test/fixtures/eval/index.js +13 -0
- package/test/fixtures/eval/node_modules/14-files.js +3 -0
- package/test/fixtures/eval/node_modules/2-files.js +3 -0
- package/test/fixtures/eval/node_modules/file1.js +5 -0
- package/test/fixtures/eval/node_modules/file10.js +5 -0
- package/test/fixtures/eval/node_modules/file11.js +5 -0
- package/test/fixtures/eval/node_modules/file12.js +5 -0
- package/test/fixtures/eval/node_modules/file13.js +5 -0
- package/test/fixtures/eval/node_modules/file14.js +11 -0
- package/test/fixtures/eval/node_modules/file2.js +5 -0
- package/test/fixtures/eval/node_modules/file3.js +5 -0
- package/test/fixtures/eval/node_modules/file4.js +5 -0
- package/test/fixtures/eval/node_modules/file5.js +5 -0
- package/test/fixtures/eval/node_modules/file6.js +5 -0
- package/test/fixtures/eval/node_modules/file7.js +5 -0
- package/test/fixtures/eval/node_modules/file8.js +5 -0
- package/test/fixtures/eval/node_modules/file9.js +5 -0
- package/test/fixtures/noop-transport.js +10 -0
- package/test/fixtures/pretty/null-prototype.js +8 -0
- package/test/fixtures/stdout-hack-protection.js +11 -0
- package/test/fixtures/syncfalse-child.js +6 -0
- package/test/fixtures/syncfalse-exit.js +9 -0
- package/test/fixtures/syncfalse-flush-exit.js +10 -0
- package/test/fixtures/syncfalse.js +6 -0
- package/test/fixtures/syntax-error-esm.mjs +2 -0
- package/test/fixtures/to-file-transport-with-transform.js +20 -0
- package/test/fixtures/to-file-transport.js +13 -0
- package/test/fixtures/to-file-transport.mjs +8 -0
- package/test/fixtures/transport/index.js +12 -0
- package/test/fixtures/transport/package.json +5 -0
- package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
- package/test/fixtures/transport-exit-immediately.js +11 -0
- package/test/fixtures/transport-exit-on-ready.js +12 -0
- package/test/fixtures/transport-invalid-node-options.js +26 -0
- package/test/fixtures/transport-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -0
- package/test/fixtures/transport-preload-main.mjs +13 -0
- package/test/fixtures/transport-preload.mjs +13 -0
- package/test/fixtures/transport-string-stdout.js +9 -0
- package/test/fixtures/transport-transform.js +21 -0
- package/test/fixtures/transport-uses-pino-config.js +33 -0
- package/test/fixtures/transport-with-on-exit.js +12 -0
- package/test/fixtures/transport-worker-data.js +19 -0
- package/test/fixtures/transport-worker-name.js +24 -0
- package/test/fixtures/transport-worker.js +15 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -0
- package/test/fixtures/ts/to-file-transport-native.mts +15 -0
- package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
- package/test/fixtures/ts/to-file-transport.ts +11 -0
- package/test/fixtures/ts/transpile.cjs +36 -0
- package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
- package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
- package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
- package/test/fixtures/ts/transport-main.ts +8 -0
- package/test/fixtures/ts/transport-string-stdout.ts +8 -0
- package/test/fixtures/ts/transport-worker.ts +14 -0
- package/test/formatters.test.js +364 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +155 -0
- package/test/hooks.test.js +114 -0
- package/test/http.test.js +214 -0
- package/test/internals/version.test.js +17 -0
- package/test/is-level-enabled.test.js +179 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +810 -0
- package/test/metadata.test.js +120 -0
- package/test/mixin-merge-strategy.test.js +57 -0
- package/test/mixin.test.js +241 -0
- package/test/multistream.test.js +729 -0
- package/test/redact.test.js +893 -0
- package/test/serializers.test.js +257 -0
- package/test/stdout-protection.test.js +41 -0
- package/test/syncfalse.test.js +186 -0
- package/test/timestamp-nano.test.js +37 -0
- package/test/timestamp.test.js +124 -0
- package/test/transport/big.test.js +42 -0
- package/test/transport/bundlers-support.test.js +99 -0
- package/test/transport/caller.test.js +24 -0
- package/test/transport/core.test.js +733 -0
- package/test/transport/core.transpiled.test.ts +114 -0
- package/test/transport/crash.test.js +36 -0
- package/test/transport/module-link.test.js +241 -0
- package/test/transport/native-type-stripping.test.mjs +151 -0
- package/test/transport/node-options.test.js +116 -0
- package/test/transport/pipeline.test.js +137 -0
- package/test/transport/preload.test.js +54 -0
- package/test/transport/repl.test.js +15 -0
- package/test/transport/sync-false.test.js +67 -0
- package/test/transport/sync-true.test.js +57 -0
- package/test/transport/targets.test.js +48 -0
- package/test/transport/uses-pino-config.test.js +166 -0
- package/test/transport-stream.test.js +40 -0
- package/test/types/pino-import.test-d.cts +30 -0
- package/test/types/pino-multistream.test-d.ts +28 -0
- package/test/types/pino-top-export.test-d.ts +34 -0
- package/test/types/pino-transport.test-d.ts +156 -0
- package/test/types/pino-type-only.test-d.ts +75 -0
- package/test/types/pino.test-d.ts +683 -0
- package/test/types/pino.ts +91 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* eslint no-prototype-builtins: 0 */
|
|
4
|
+
|
|
5
|
+
const test = require('node:test')
|
|
6
|
+
const assert = require('node:assert')
|
|
7
|
+
const os = require('node:os')
|
|
8
|
+
const tspl = require('@matteo.collina/tspl')
|
|
9
|
+
|
|
10
|
+
const { sink, once } = require('./helper')
|
|
11
|
+
const pino = require('../')
|
|
12
|
+
|
|
13
|
+
const { pid } = process
|
|
14
|
+
const hostname = os.hostname()
|
|
15
|
+
const level = 50
|
|
16
|
+
const name = 'error'
|
|
17
|
+
|
|
18
|
+
test('err is serialized with additional properties set on the Error object', async () => {
|
|
19
|
+
const stream = sink()
|
|
20
|
+
const err = Object.assign(new Error('myerror'), { foo: 'bar' })
|
|
21
|
+
const instance = pino(stream)
|
|
22
|
+
instance.level = name
|
|
23
|
+
instance[name](err)
|
|
24
|
+
const result = await once(stream, 'data')
|
|
25
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
26
|
+
delete result.time
|
|
27
|
+
assert.deepEqual(result, {
|
|
28
|
+
pid,
|
|
29
|
+
hostname,
|
|
30
|
+
level,
|
|
31
|
+
err: {
|
|
32
|
+
type: 'Error',
|
|
33
|
+
message: err.message,
|
|
34
|
+
stack: err.stack,
|
|
35
|
+
foo: err.foo
|
|
36
|
+
},
|
|
37
|
+
msg: err.message
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('type should be detected based on constructor', async () => {
|
|
42
|
+
class Bar extends Error {}
|
|
43
|
+
const stream = sink()
|
|
44
|
+
const err = new Bar('myerror')
|
|
45
|
+
const instance = pino(stream)
|
|
46
|
+
instance.level = name
|
|
47
|
+
instance[name](err)
|
|
48
|
+
const result = await once(stream, 'data')
|
|
49
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
50
|
+
delete result.time
|
|
51
|
+
assert.deepEqual(result, {
|
|
52
|
+
pid,
|
|
53
|
+
hostname,
|
|
54
|
+
level,
|
|
55
|
+
err: {
|
|
56
|
+
type: 'Bar',
|
|
57
|
+
message: err.message,
|
|
58
|
+
stack: err.stack
|
|
59
|
+
},
|
|
60
|
+
msg: err.message
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('type, message and stack should be first level properties', async () => {
|
|
65
|
+
const stream = sink()
|
|
66
|
+
const err = Object.assign(new Error('foo'), { foo: 'bar' })
|
|
67
|
+
const instance = pino(stream)
|
|
68
|
+
instance.level = name
|
|
69
|
+
instance[name](err)
|
|
70
|
+
|
|
71
|
+
const result = await once(stream, 'data')
|
|
72
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
73
|
+
delete result.time
|
|
74
|
+
assert.deepEqual(result, {
|
|
75
|
+
pid,
|
|
76
|
+
hostname,
|
|
77
|
+
level,
|
|
78
|
+
err: {
|
|
79
|
+
type: 'Error',
|
|
80
|
+
message: err.message,
|
|
81
|
+
stack: err.stack,
|
|
82
|
+
foo: err.foo
|
|
83
|
+
},
|
|
84
|
+
msg: err.message
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('err serializer', async () => {
|
|
89
|
+
const stream = sink()
|
|
90
|
+
const err = Object.assign(new Error('myerror'), { foo: 'bar' })
|
|
91
|
+
const instance = pino({
|
|
92
|
+
serializers: {
|
|
93
|
+
err: pino.stdSerializers.err
|
|
94
|
+
}
|
|
95
|
+
}, stream)
|
|
96
|
+
|
|
97
|
+
instance.level = name
|
|
98
|
+
instance[name]({ err })
|
|
99
|
+
const result = await once(stream, 'data')
|
|
100
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
101
|
+
delete result.time
|
|
102
|
+
assert.deepEqual(result, {
|
|
103
|
+
pid,
|
|
104
|
+
hostname,
|
|
105
|
+
level,
|
|
106
|
+
err: {
|
|
107
|
+
type: 'Error',
|
|
108
|
+
message: err.message,
|
|
109
|
+
stack: err.stack,
|
|
110
|
+
foo: err.foo
|
|
111
|
+
},
|
|
112
|
+
msg: err.message
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('an error with statusCode property is not confused for a http response', async () => {
|
|
117
|
+
const stream = sink()
|
|
118
|
+
const err = Object.assign(new Error('StatusCodeErr'), { statusCode: 500 })
|
|
119
|
+
const instance = pino(stream)
|
|
120
|
+
|
|
121
|
+
instance.level = name
|
|
122
|
+
instance[name](err)
|
|
123
|
+
const result = await once(stream, 'data')
|
|
124
|
+
|
|
125
|
+
assert.ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
|
126
|
+
delete result.time
|
|
127
|
+
assert.deepEqual(result, {
|
|
128
|
+
pid,
|
|
129
|
+
hostname,
|
|
130
|
+
level,
|
|
131
|
+
err: {
|
|
132
|
+
type: 'Error',
|
|
133
|
+
message: err.message,
|
|
134
|
+
stack: err.stack,
|
|
135
|
+
statusCode: err.statusCode
|
|
136
|
+
},
|
|
137
|
+
msg: err.message
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('stack is omitted if it is not set on err', async (t) => {
|
|
142
|
+
const plan = tspl(t, { plan: 2 })
|
|
143
|
+
const err = new Error('myerror')
|
|
144
|
+
delete err.stack
|
|
145
|
+
const instance = pino(sink(function (chunk, enc, cb) {
|
|
146
|
+
plan.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
|
147
|
+
delete chunk.time
|
|
148
|
+
plan.equal(chunk.hasOwnProperty('stack'), false)
|
|
149
|
+
cb()
|
|
150
|
+
}))
|
|
151
|
+
|
|
152
|
+
instance.level = name
|
|
153
|
+
instance[name](err)
|
|
154
|
+
|
|
155
|
+
await plan
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('correctly ignores toString on errors', async () => {
|
|
159
|
+
const err = new Error('myerror')
|
|
160
|
+
err.toString = () => undefined
|
|
161
|
+
const stream = sink()
|
|
162
|
+
const instance = pino({
|
|
163
|
+
test: 'this'
|
|
164
|
+
}, stream)
|
|
165
|
+
instance.fatal(err)
|
|
166
|
+
const result = await once(stream, 'data')
|
|
167
|
+
delete result.time
|
|
168
|
+
assert.deepEqual(result, {
|
|
169
|
+
pid,
|
|
170
|
+
hostname,
|
|
171
|
+
level: 60,
|
|
172
|
+
err: {
|
|
173
|
+
type: 'Error',
|
|
174
|
+
message: err.message,
|
|
175
|
+
stack: err.stack
|
|
176
|
+
},
|
|
177
|
+
msg: err.message
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('assign mixin()', async () => {
|
|
182
|
+
const err = new Error('myerror')
|
|
183
|
+
const stream = sink()
|
|
184
|
+
const instance = pino({
|
|
185
|
+
mixin () {
|
|
186
|
+
return { hello: 'world' }
|
|
187
|
+
}
|
|
188
|
+
}, stream)
|
|
189
|
+
instance.fatal(err)
|
|
190
|
+
const result = await once(stream, 'data')
|
|
191
|
+
delete result.time
|
|
192
|
+
assert.deepEqual(result, {
|
|
193
|
+
pid,
|
|
194
|
+
hostname,
|
|
195
|
+
level: 60,
|
|
196
|
+
hello: 'world',
|
|
197
|
+
err: {
|
|
198
|
+
type: 'Error',
|
|
199
|
+
message: err.message,
|
|
200
|
+
stack: err.stack
|
|
201
|
+
},
|
|
202
|
+
msg: err.message
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
test('no err serializer', async () => {
|
|
207
|
+
const err = new Error('myerror')
|
|
208
|
+
const stream = sink()
|
|
209
|
+
const instance = pino({
|
|
210
|
+
serializers: {}
|
|
211
|
+
}, stream)
|
|
212
|
+
instance.fatal(err)
|
|
213
|
+
const result = await once(stream, 'data')
|
|
214
|
+
delete result.time
|
|
215
|
+
assert.deepEqual(result, {
|
|
216
|
+
pid,
|
|
217
|
+
hostname,
|
|
218
|
+
level: 60,
|
|
219
|
+
err: {
|
|
220
|
+
type: 'Error',
|
|
221
|
+
message: err.message,
|
|
222
|
+
stack: err.stack
|
|
223
|
+
},
|
|
224
|
+
msg: err.message
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('empty serializer', async () => {
|
|
229
|
+
const err = new Error('myerror')
|
|
230
|
+
const stream = sink()
|
|
231
|
+
const instance = pino({
|
|
232
|
+
serializers: {
|
|
233
|
+
err () {}
|
|
234
|
+
}
|
|
235
|
+
}, stream)
|
|
236
|
+
instance.fatal(err)
|
|
237
|
+
const result = await once(stream, 'data')
|
|
238
|
+
delete result.time
|
|
239
|
+
assert.deepEqual(result, {
|
|
240
|
+
pid,
|
|
241
|
+
hostname,
|
|
242
|
+
level: 60,
|
|
243
|
+
msg: err.message
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
test('assign mixin()', async () => {
|
|
248
|
+
const err = new Error('myerror')
|
|
249
|
+
const stream = sink()
|
|
250
|
+
const instance = pino({
|
|
251
|
+
mixin () {
|
|
252
|
+
return { hello: 'world' }
|
|
253
|
+
}
|
|
254
|
+
}, stream)
|
|
255
|
+
instance.fatal(err)
|
|
256
|
+
const result = await once(stream, 'data')
|
|
257
|
+
delete result.time
|
|
258
|
+
assert.deepEqual(result, {
|
|
259
|
+
pid,
|
|
260
|
+
hostname,
|
|
261
|
+
level: 60,
|
|
262
|
+
hello: 'world',
|
|
263
|
+
err: {
|
|
264
|
+
type: 'Error',
|
|
265
|
+
message: err.message,
|
|
266
|
+
stack: err.stack
|
|
267
|
+
},
|
|
268
|
+
msg: err.message
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
test('no err serializer', async () => {
|
|
273
|
+
const err = new Error('myerror')
|
|
274
|
+
const stream = sink()
|
|
275
|
+
const instance = pino({
|
|
276
|
+
serializers: {}
|
|
277
|
+
}, stream)
|
|
278
|
+
instance.fatal(err)
|
|
279
|
+
const result = await once(stream, 'data')
|
|
280
|
+
delete result.time
|
|
281
|
+
assert.deepEqual(result, {
|
|
282
|
+
pid,
|
|
283
|
+
hostname,
|
|
284
|
+
level: 60,
|
|
285
|
+
err: {
|
|
286
|
+
type: 'Error',
|
|
287
|
+
message: err.message,
|
|
288
|
+
stack: err.stack
|
|
289
|
+
},
|
|
290
|
+
msg: err.message
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
test('empty serializer', async () => {
|
|
295
|
+
const err = new Error('myerror')
|
|
296
|
+
const stream = sink()
|
|
297
|
+
const instance = pino({
|
|
298
|
+
serializers: {
|
|
299
|
+
err () {}
|
|
300
|
+
}
|
|
301
|
+
}, stream)
|
|
302
|
+
instance.fatal(err)
|
|
303
|
+
const result = await once(stream, 'data')
|
|
304
|
+
delete result.time
|
|
305
|
+
assert.deepEqual(result, {
|
|
306
|
+
pid,
|
|
307
|
+
hostname,
|
|
308
|
+
level: 60,
|
|
309
|
+
msg: err.message
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('correctly adds error information when nestedKey is used', async () => {
|
|
314
|
+
const err = new Error('myerror')
|
|
315
|
+
err.toString = () => undefined
|
|
316
|
+
const stream = sink()
|
|
317
|
+
const instance = pino({
|
|
318
|
+
test: 'this',
|
|
319
|
+
nestedKey: 'obj'
|
|
320
|
+
}, stream)
|
|
321
|
+
instance.fatal(err)
|
|
322
|
+
const result = await once(stream, 'data')
|
|
323
|
+
delete result.time
|
|
324
|
+
assert.deepEqual(result, {
|
|
325
|
+
pid,
|
|
326
|
+
hostname,
|
|
327
|
+
level: 60,
|
|
328
|
+
obj: {
|
|
329
|
+
err: {
|
|
330
|
+
type: 'Error',
|
|
331
|
+
stack: err.stack,
|
|
332
|
+
message: err.message
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
msg: err.message
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test('correctly adds msg on error when nestedKey is used', async () => {
|
|
340
|
+
const err = new Error('myerror')
|
|
341
|
+
err.toString = () => undefined
|
|
342
|
+
const stream = sink()
|
|
343
|
+
const instance = pino({
|
|
344
|
+
test: 'this',
|
|
345
|
+
nestedKey: 'obj'
|
|
346
|
+
}, stream)
|
|
347
|
+
instance.fatal(err, 'msg message')
|
|
348
|
+
const result = await once(stream, 'data')
|
|
349
|
+
delete result.time
|
|
350
|
+
assert.deepEqual(result, {
|
|
351
|
+
pid,
|
|
352
|
+
hostname,
|
|
353
|
+
level: 60,
|
|
354
|
+
obj: {
|
|
355
|
+
err: {
|
|
356
|
+
type: 'Error',
|
|
357
|
+
stack: err.stack,
|
|
358
|
+
message: err.message
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
msg: 'msg message'
|
|
362
|
+
})
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
test('msg should take precedence over error message on mergingObject', async () => {
|
|
366
|
+
const err = new Error('myerror')
|
|
367
|
+
const stream = sink()
|
|
368
|
+
const instance = pino(stream)
|
|
369
|
+
instance.error({ msg: 'my message', err })
|
|
370
|
+
const result = await once(stream, 'data')
|
|
371
|
+
delete result.time
|
|
372
|
+
assert.deepEqual(result, {
|
|
373
|
+
pid,
|
|
374
|
+
hostname,
|
|
375
|
+
level: 50,
|
|
376
|
+
err: {
|
|
377
|
+
type: 'Error',
|
|
378
|
+
stack: err.stack,
|
|
379
|
+
message: err.message
|
|
380
|
+
},
|
|
381
|
+
msg: 'my message'
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
test('considers messageKey when giving msg precedence over error', async () => {
|
|
386
|
+
const err = new Error('myerror')
|
|
387
|
+
const stream = sink()
|
|
388
|
+
const instance = pino({ messageKey: 'message' }, stream)
|
|
389
|
+
instance.error({ message: 'my message', err })
|
|
390
|
+
const result = await once(stream, 'data')
|
|
391
|
+
delete result.time
|
|
392
|
+
assert.deepEqual(result, {
|
|
393
|
+
pid,
|
|
394
|
+
hostname,
|
|
395
|
+
level: 50,
|
|
396
|
+
err: {
|
|
397
|
+
type: 'Error',
|
|
398
|
+
stack: err.stack,
|
|
399
|
+
message: err.message
|
|
400
|
+
},
|
|
401
|
+
message: 'my message'
|
|
402
|
+
})
|
|
403
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('node:test')
|
|
4
|
+
const assert = require('node:assert')
|
|
5
|
+
const os = require('node:os')
|
|
6
|
+
|
|
7
|
+
const { sink, once } = require('./helper')
|
|
8
|
+
const pino = require('../')
|
|
9
|
+
|
|
10
|
+
const { pid } = process
|
|
11
|
+
const hostname = os.hostname()
|
|
12
|
+
|
|
13
|
+
function testEscape (ch, key) {
|
|
14
|
+
test('correctly escape ' + ch, async () => {
|
|
15
|
+
const stream = sink()
|
|
16
|
+
const instance = pino({
|
|
17
|
+
name: 'hello'
|
|
18
|
+
}, stream)
|
|
19
|
+
instance.fatal('this contains ' + key)
|
|
20
|
+
const result = await once(stream, 'data')
|
|
21
|
+
delete result.time
|
|
22
|
+
assert.deepEqual(result, {
|
|
23
|
+
pid,
|
|
24
|
+
hostname,
|
|
25
|
+
level: 60,
|
|
26
|
+
name: 'hello',
|
|
27
|
+
msg: 'this contains ' + key
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
testEscape('\\n', '\n')
|
|
33
|
+
testEscape('\\/', '/')
|
|
34
|
+
testEscape('\\\\', '\\')
|
|
35
|
+
testEscape('\\r', '\r')
|
|
36
|
+
testEscape('\\t', '\t')
|
|
37
|
+
testEscape('\\b', '\b')
|
|
38
|
+
|
|
39
|
+
const toEscape = [
|
|
40
|
+
'\u0000', // NUL Null character
|
|
41
|
+
'\u0001', // SOH Start of Heading
|
|
42
|
+
'\u0002', // STX Start of Text
|
|
43
|
+
'\u0003', // ETX End-of-text character
|
|
44
|
+
'\u0004', // EOT End-of-transmission character
|
|
45
|
+
'\u0005', // ENQ Enquiry character
|
|
46
|
+
'\u0006', // ACK Acknowledge character
|
|
47
|
+
'\u0007', // BEL Bell character
|
|
48
|
+
'\u0008', // BS Backspace
|
|
49
|
+
'\u0009', // HT Horizontal tab
|
|
50
|
+
'\u000A', // LF Line feed
|
|
51
|
+
'\u000B', // VT Vertical tab
|
|
52
|
+
'\u000C', // FF Form feed
|
|
53
|
+
'\u000D', // CR Carriage return
|
|
54
|
+
'\u000E', // SO Shift Out
|
|
55
|
+
'\u000F', // SI Shift In
|
|
56
|
+
'\u0010', // DLE Data Link Escape
|
|
57
|
+
'\u0011', // DC1 Device Control 1
|
|
58
|
+
'\u0012', // DC2 Device Control 2
|
|
59
|
+
'\u0013', // DC3 Device Control 3
|
|
60
|
+
'\u0014', // DC4 Device Control 4
|
|
61
|
+
'\u0015', // NAK Negative-acknowledge character
|
|
62
|
+
'\u0016', // SYN Synchronous Idle
|
|
63
|
+
'\u0017', // ETB End of Transmission Block
|
|
64
|
+
'\u0018', // CAN Cancel character
|
|
65
|
+
'\u0019', // EM End of Medium
|
|
66
|
+
'\u001A', // SUB Substitute character
|
|
67
|
+
'\u001B', // ESC Escape character
|
|
68
|
+
'\u001C', // FS File Separator
|
|
69
|
+
'\u001D', // GS Group Separator
|
|
70
|
+
'\u001E', // RS Record Separator
|
|
71
|
+
'\u001F' // US Unit Separator
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
toEscape.forEach((key) => {
|
|
75
|
+
testEscape(JSON.stringify(key), key)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('correctly escape `hello \\u001F world \\n \\u0022`', async () => {
|
|
79
|
+
const stream = sink()
|
|
80
|
+
const instance = pino({
|
|
81
|
+
name: 'hello'
|
|
82
|
+
}, stream)
|
|
83
|
+
instance.fatal('hello \u001F world \n \u0022')
|
|
84
|
+
const result = await once(stream, 'data')
|
|
85
|
+
delete result.time
|
|
86
|
+
assert.deepEqual(result, {
|
|
87
|
+
pid,
|
|
88
|
+
hostname,
|
|
89
|
+
level: 60,
|
|
90
|
+
name: 'hello',
|
|
91
|
+
msg: 'hello \u001F world \n \u0022'
|
|
92
|
+
})
|
|
93
|
+
})
|
package/test/esm/esm.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
|
|
4
|
+
import pino from '../../pino.js'
|
|
5
|
+
import helper from '../helper.js'
|
|
6
|
+
|
|
7
|
+
const { sink, check, once } = helper
|
|
8
|
+
|
|
9
|
+
test('esm support', async () => {
|
|
10
|
+
const stream = sink()
|
|
11
|
+
const instance = pino(stream)
|
|
12
|
+
instance.info('hello world')
|
|
13
|
+
check(assert.equal, await once(stream, 'data'), 30, 'hello world')
|
|
14
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Node v8 throw a `SyntaxError: Unexpected token import`
|
|
4
|
+
// even if this branch is never touched in the code,
|
|
5
|
+
// by using `eval` we can avoid this issue.
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
|
|
8
|
+
process.nextTick(() => {
|
|
9
|
+
throw err
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// Node v8 throw a `SyntaxError: Unexpected token import`
|
|
14
|
+
// even if this branch is never touched in the code,
|
|
15
|
+
// by using `eval` we can avoid this issue.
|
|
16
|
+
// eslint-disable-next-line
|
|
17
|
+
new Function('module', 'return import(module)')('./named-exports.mjs').catch((err) => {
|
|
18
|
+
process.nextTick(() => {
|
|
19
|
+
throw err
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
import { hostname } from 'node:os'
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
|
|
6
|
+
import { sink, check, once, watchFileCreated, file } from '../helper.js'
|
|
7
|
+
import { pino, destination } from '../../pino.js'
|
|
8
|
+
|
|
9
|
+
test('named exports support', async () => {
|
|
10
|
+
const stream = sink()
|
|
11
|
+
const instance = pino(stream)
|
|
12
|
+
instance.info('hello world')
|
|
13
|
+
check(assert.equal, await once(stream, 'data'), 30, 'hello world')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('destination', async () => {
|
|
17
|
+
const tmp = file()
|
|
18
|
+
const instance = pino(destination(tmp))
|
|
19
|
+
instance.info('hello')
|
|
20
|
+
await watchFileCreated(tmp)
|
|
21
|
+
const result = JSON.parse(readFileSync(tmp).toString())
|
|
22
|
+
delete result.time
|
|
23
|
+
assert.deepEqual(result, {
|
|
24
|
+
pid: process.pid,
|
|
25
|
+
hostname,
|
|
26
|
+
level: 30,
|
|
27
|
+
msg: 'hello'
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('node:test')
|
|
4
|
+
const assert = require('node:assert')
|
|
5
|
+
const { join } = require('node:path')
|
|
6
|
+
|
|
7
|
+
const execa = require('execa')
|
|
8
|
+
const writer = require('flush-write-stream')
|
|
9
|
+
const { once } = require('./helper')
|
|
10
|
+
|
|
11
|
+
// https://github.com/pinojs/pino/issues/542
|
|
12
|
+
test('pino.destination log everything when calling process.exit(0)', async () => {
|
|
13
|
+
let actual = ''
|
|
14
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'destination-exit.js')])
|
|
15
|
+
|
|
16
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
17
|
+
actual += s
|
|
18
|
+
cb()
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
await once(child, 'close')
|
|
22
|
+
|
|
23
|
+
assert.equal(actual.match(/hello/) != null, true)
|
|
24
|
+
assert.equal(actual.match(/world/) != null, true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('pino with no args log everything when calling process.exit(0)', async () => {
|
|
28
|
+
let actual = ''
|
|
29
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'default-exit.js')])
|
|
30
|
+
|
|
31
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
32
|
+
actual += s
|
|
33
|
+
cb()
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
await once(child, 'close')
|
|
37
|
+
|
|
38
|
+
assert.equal(actual.match(/hello/) != null, true)
|
|
39
|
+
assert.equal(actual.match(/world/) != null, true)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('sync false logs everything when calling process.exit(0)', async () => {
|
|
43
|
+
let actual = ''
|
|
44
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-exit.js')])
|
|
45
|
+
|
|
46
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
47
|
+
actual += s
|
|
48
|
+
cb()
|
|
49
|
+
}))
|
|
50
|
+
|
|
51
|
+
await once(child, 'close')
|
|
52
|
+
|
|
53
|
+
assert.equal(actual.match(/hello/) != null, true)
|
|
54
|
+
assert.equal(actual.match(/world/) != null, true)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('sync false logs everything when calling flushSync', async () => {
|
|
58
|
+
let actual = ''
|
|
59
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'syncfalse-flush-exit.js')])
|
|
60
|
+
|
|
61
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
62
|
+
actual += s
|
|
63
|
+
cb()
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
await once(child, 'close')
|
|
67
|
+
|
|
68
|
+
assert.equal(actual.match(/hello/) != null, true)
|
|
69
|
+
assert.equal(actual.match(/world/) != null, true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('transports exits gracefully when logging in exit', async () => {
|
|
73
|
+
const child = execa(process.argv[0], [join(__dirname, 'fixtures', 'transport-with-on-exit.js')])
|
|
74
|
+
child.stdout.resume()
|
|
75
|
+
|
|
76
|
+
const code = await once(child, 'close')
|
|
77
|
+
|
|
78
|
+
assert.equal(code, 0)
|
|
79
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
4
|
+
Date.now = function () { return 1459875739796 }
|
|
5
|
+
require('node:os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
6
|
+
|
|
7
|
+
const pino = require('../../..')
|
|
8
|
+
const logger = pino(pino.destination())
|
|
9
|
+
|
|
10
|
+
logger.info('hello world')
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
global.process = { __proto__: process, pid: 123456 }
|
|
4
|
+
Date.now = function () { return 1459875739796 }
|
|
5
|
+
require('node:os').hostname = function () { return 'abcdefghijklmnopqr' }
|
|
6
|
+
|
|
7
|
+
const pino = require('../../..')
|
|
8
|
+
const logger = pino(pino.destination({ sync: false }))
|
|
9
|
+
|
|
10
|
+
for (var i = 0; i < 1000; i++) {
|
|
11
|
+
logger.info('hello world')
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { Writable } = require('node:stream')
|
|
2
|
+
|
|
3
|
+
module.exports = (options) => {
|
|
4
|
+
const myTransportStream = new Writable({
|
|
5
|
+
autoDestroy: true,
|
|
6
|
+
write (chunk, enc, cb) {
|
|
7
|
+
// apply a transform and send to stdout
|
|
8
|
+
console.log(chunk.toString().toUpperCase())
|
|
9
|
+
cb()
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
return myTransportStream
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { Writable } = require('node:stream')
|
|
2
|
+
|
|
3
|
+
module.exports = () =>
|
|
4
|
+
new Writable({
|
|
5
|
+
autoDestroy: true,
|
|
6
|
+
write (chunk, enc, cb) {
|
|
7
|
+
setImmediate(() => {
|
|
8
|
+
/* eslint-disable no-empty */
|
|
9
|
+
for (let i = 0; i < 1e3; i++) {}
|
|
10
|
+
process.exit(0)
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
})
|