node-mongo-orm 0.0.1-security → 3.4.2
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 node-mongo-orm might be problematic. Click here for more details.
- package/.eslintignore +2 -0
- package/.eslintrc +8 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/bench.yml +61 -0
- package/.github/workflows/ci.yml +88 -0
- package/.github/workflows/lock-threads.yml +30 -0
- package/.github/workflows/target-main.yml +23 -0
- package/.nojekyll +0 -0
- package/.prettierignore +1 -0
- package/.taprc.yaml +8 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +21 -0
- package/README.md +159 -3
- package/SECURITY.md +68 -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 +484 -0
- package/build/sync-version.js +10 -0
- package/docs/api.md +1487 -0
- package/docs/asynchronous.md +40 -0
- package/docs/benchmarks.md +55 -0
- package/docs/browser.md +227 -0
- package/docs/bundling.md +40 -0
- package/docs/child-loggers.md +95 -0
- package/docs/ecosystem.md +84 -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 +1238 -0
- package/docs/web.md +269 -0
- package/docsify/sidebar.md +26 -0
- package/examples/basic.js +43 -0
- package/examples/transport.js +68 -0
- package/favicon-16x16.png +0 -0
- package/favicon-32x32.png +0 -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/deprecations.js +8 -0
- package/lib/levels.js +241 -0
- package/lib/meta.js +3 -0
- package/lib/multistream.js +188 -0
- package/lib/proto.js +234 -0
- package/lib/redaction.js +118 -0
- package/lib/symbols.js +74 -0
- package/lib/time.js +11 -0
- package/lib/tools.js +394 -0
- package/lib/transport-stream.js +56 -0
- package/lib/transport.js +167 -0
- package/lib/worker.js +194 -0
- package/lib/writer.js +42 -0
- package/package.json +117 -3
- package/pino-banner.png +0 -0
- package/pino-logo-hire.png +0 -0
- package/pino-tree.png +0 -0
- package/pino.d.ts +889 -0
- package/pino.js +236 -0
- package/pretty-demo.png +0 -0
- package/test/basic.test.js +874 -0
- package/test/broken-pipe.test.js +57 -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-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 +659 -0
- package/test/complex-objects.test.js +34 -0
- package/test/crlf.test.js +32 -0
- package/test/custom-levels.test.js +253 -0
- package/test/error.test.js +398 -0
- package/test/errorKey.test.js +34 -0
- package/test/escaping.test.js +91 -0
- package/test/esm/esm.mjs +12 -0
- package/test/esm/index.test.js +34 -0
- package/test/esm/named-exports.mjs +27 -0
- package/test/exit.test.js +77 -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/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-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -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.js +15 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -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 +355 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +128 -0
- package/test/hooks.test.js +118 -0
- package/test/http.test.js +242 -0
- package/test/internals/version.test.js +15 -0
- package/test/is-level-enabled.test.js +185 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +772 -0
- package/test/metadata.test.js +106 -0
- package/test/mixin-merge-strategy.test.js +55 -0
- package/test/mixin.test.js +218 -0
- package/test/multistream.test.js +673 -0
- package/test/pkg/index.js +46 -0
- package/test/pkg/pkg.config.json +17 -0
- package/test/pkg/pkg.test.js +56 -0
- package/test/redact.test.js +847 -0
- package/test/serializers.test.js +253 -0
- package/test/stdout-protection.test.js +39 -0
- package/test/syncfalse.test.js +188 -0
- package/test/timestamp.test.js +121 -0
- package/test/transport/big.test.js +43 -0
- package/test/transport/bundlers-support.test.js +97 -0
- package/test/transport/caller.test.js +23 -0
- package/test/transport/core.test.js +644 -0
- package/test/transport/core.test.ts +236 -0
- package/test/transport/core.transpiled.test.ts +112 -0
- package/test/transport/module-link.test.js +239 -0
- package/test/transport/pipeline.test.js +135 -0
- package/test/transport/repl.test.js +14 -0
- package/test/transport/syncTrue.test.js +55 -0
- package/test/transport/syncfalse.test.js +68 -0
- package/test/transport/targets.test.js +44 -0
- package/test/transport/uses-pino-config.test.js +167 -0
- package/test/transport-stream.test.js +26 -0
- package/test/types/pino-import.test-d.ts +29 -0
- package/test/types/pino-multistream.test-d.ts +28 -0
- package/test/types/pino-top-export.test-d.ts +35 -0
- package/test/types/pino-transport.test-d.ts +145 -0
- package/test/types/pino-type-only.test-d.ts +64 -0
- package/test/types/pino.test-d.ts +468 -0
- package/test/types/pino.ts +78 -0
- package/tsconfig.json +14 -0
@@ -0,0 +1,253 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
/* eslint no-prototype-builtins: 0 */
|
4
|
+
|
5
|
+
const { test } = require('tap')
|
6
|
+
const { sink, once } = require('./helper')
|
7
|
+
const pino = require('../')
|
8
|
+
|
9
|
+
// Silence all warnings for this test
|
10
|
+
process.removeAllListeners('warning')
|
11
|
+
process.on('warning', () => {})
|
12
|
+
|
13
|
+
test('adds additional levels', async ({ equal }) => {
|
14
|
+
const stream = sink()
|
15
|
+
const logger = pino({
|
16
|
+
customLevels: {
|
17
|
+
foo: 35,
|
18
|
+
bar: 45
|
19
|
+
}
|
20
|
+
}, stream)
|
21
|
+
|
22
|
+
logger.foo('test')
|
23
|
+
const { level } = await once(stream, 'data')
|
24
|
+
equal(level, 35)
|
25
|
+
})
|
26
|
+
|
27
|
+
test('custom levels does not override default levels', async ({ equal }) => {
|
28
|
+
const stream = sink()
|
29
|
+
const logger = pino({
|
30
|
+
customLevels: {
|
31
|
+
foo: 35
|
32
|
+
}
|
33
|
+
}, stream)
|
34
|
+
|
35
|
+
logger.info('test')
|
36
|
+
const { level } = await once(stream, 'data')
|
37
|
+
equal(level, 30)
|
38
|
+
})
|
39
|
+
|
40
|
+
test('default levels can be redefined using custom levels', async ({ equal }) => {
|
41
|
+
const stream = sink()
|
42
|
+
const logger = pino({
|
43
|
+
customLevels: {
|
44
|
+
info: 35,
|
45
|
+
debug: 45
|
46
|
+
},
|
47
|
+
useOnlyCustomLevels: true
|
48
|
+
}, stream)
|
49
|
+
|
50
|
+
equal(logger.hasOwnProperty('info'), true)
|
51
|
+
|
52
|
+
logger.info('test')
|
53
|
+
const { level } = await once(stream, 'data')
|
54
|
+
equal(level, 35)
|
55
|
+
})
|
56
|
+
|
57
|
+
test('custom levels overrides default level label if use useOnlyCustomLevels', async ({ equal }) => {
|
58
|
+
const stream = sink()
|
59
|
+
const logger = pino({
|
60
|
+
customLevels: {
|
61
|
+
foo: 35
|
62
|
+
},
|
63
|
+
useOnlyCustomLevels: true,
|
64
|
+
level: 'foo'
|
65
|
+
}, stream)
|
66
|
+
|
67
|
+
equal(logger.hasOwnProperty('info'), false)
|
68
|
+
})
|
69
|
+
|
70
|
+
test('custom levels overrides default level value if use useOnlyCustomLevels', async ({ equal }) => {
|
71
|
+
const stream = sink()
|
72
|
+
const logger = pino({
|
73
|
+
customLevels: {
|
74
|
+
foo: 35
|
75
|
+
},
|
76
|
+
useOnlyCustomLevels: true,
|
77
|
+
level: 35
|
78
|
+
}, stream)
|
79
|
+
|
80
|
+
equal(logger.hasOwnProperty('info'), false)
|
81
|
+
})
|
82
|
+
|
83
|
+
test('custom levels are inherited by children', async ({ equal }) => {
|
84
|
+
const stream = sink()
|
85
|
+
const logger = pino({
|
86
|
+
customLevels: {
|
87
|
+
foo: 35
|
88
|
+
}
|
89
|
+
}, stream)
|
90
|
+
|
91
|
+
logger.child({ childMsg: 'ok' }).foo('test')
|
92
|
+
const { msg, childMsg, level } = await once(stream, 'data')
|
93
|
+
equal(level, 35)
|
94
|
+
equal(childMsg, 'ok')
|
95
|
+
equal(msg, 'test')
|
96
|
+
})
|
97
|
+
|
98
|
+
test('custom levels can be specified on child bindings', async ({ equal }) => {
|
99
|
+
const stream = sink()
|
100
|
+
const logger = pino(stream).child({
|
101
|
+
childMsg: 'ok'
|
102
|
+
}, {
|
103
|
+
customLevels: {
|
104
|
+
foo: 35
|
105
|
+
}
|
106
|
+
})
|
107
|
+
|
108
|
+
logger.foo('test')
|
109
|
+
const { msg, childMsg, level } = await once(stream, 'data')
|
110
|
+
equal(level, 35)
|
111
|
+
equal(childMsg, 'ok')
|
112
|
+
equal(msg, 'test')
|
113
|
+
})
|
114
|
+
|
115
|
+
test('customLevels property child bindings does not get logged', async ({ equal }) => {
|
116
|
+
const stream = sink()
|
117
|
+
const logger = pino(stream).child({
|
118
|
+
childMsg: 'ok'
|
119
|
+
}, {
|
120
|
+
customLevels: {
|
121
|
+
foo: 35
|
122
|
+
}
|
123
|
+
})
|
124
|
+
|
125
|
+
logger.foo('test')
|
126
|
+
const { customLevels } = await once(stream, 'data')
|
127
|
+
equal(customLevels, undefined)
|
128
|
+
})
|
129
|
+
|
130
|
+
test('throws when specifying pre-existing parent labels via child bindings', async ({ throws }) => {
|
131
|
+
const stream = sink()
|
132
|
+
throws(() => pino({
|
133
|
+
customLevels: {
|
134
|
+
foo: 35
|
135
|
+
}
|
136
|
+
}, stream).child({}, {
|
137
|
+
customLevels: {
|
138
|
+
foo: 45
|
139
|
+
}
|
140
|
+
}), 'levels cannot be overridden')
|
141
|
+
})
|
142
|
+
|
143
|
+
test('throws when specifying pre-existing parent values via child bindings', async ({ throws }) => {
|
144
|
+
const stream = sink()
|
145
|
+
throws(() => pino({
|
146
|
+
customLevels: {
|
147
|
+
foo: 35
|
148
|
+
}
|
149
|
+
}, stream).child({}, {
|
150
|
+
customLevels: {
|
151
|
+
bar: 35
|
152
|
+
}
|
153
|
+
}), 'pre-existing level values cannot be used for new levels')
|
154
|
+
})
|
155
|
+
|
156
|
+
test('throws when specifying core values via child bindings', async ({ throws }) => {
|
157
|
+
const stream = sink()
|
158
|
+
throws(() => pino(stream).child({}, {
|
159
|
+
customLevels: {
|
160
|
+
foo: 30
|
161
|
+
}
|
162
|
+
}), 'pre-existing level values cannot be used for new levels')
|
163
|
+
})
|
164
|
+
|
165
|
+
test('throws when useOnlyCustomLevels is set true without customLevels', async ({ throws }) => {
|
166
|
+
const stream = sink()
|
167
|
+
throws(() => pino({
|
168
|
+
useOnlyCustomLevels: true
|
169
|
+
}, stream), 'customLevels is required if useOnlyCustomLevels is set true')
|
170
|
+
})
|
171
|
+
|
172
|
+
test('custom level on one instance does not affect other instances', async ({ equal }) => {
|
173
|
+
pino({
|
174
|
+
customLevels: {
|
175
|
+
foo: 37
|
176
|
+
}
|
177
|
+
})
|
178
|
+
equal(typeof pino().foo, 'undefined')
|
179
|
+
})
|
180
|
+
|
181
|
+
test('setting level below or at custom level will successfully log', async ({ equal }) => {
|
182
|
+
const stream = sink()
|
183
|
+
const instance = pino({ customLevels: { foo: 35 } }, stream)
|
184
|
+
instance.level = 'foo'
|
185
|
+
instance.info('nope')
|
186
|
+
instance.foo('bar')
|
187
|
+
const { msg } = await once(stream, 'data')
|
188
|
+
equal(msg, 'bar')
|
189
|
+
})
|
190
|
+
|
191
|
+
test('custom level below level threshold will not log', async ({ equal }) => {
|
192
|
+
const stream = sink()
|
193
|
+
const instance = pino({ customLevels: { foo: 15 } }, stream)
|
194
|
+
instance.level = 'info'
|
195
|
+
instance.info('bar')
|
196
|
+
instance.foo('nope')
|
197
|
+
const { msg } = await once(stream, 'data')
|
198
|
+
equal(msg, 'bar')
|
199
|
+
})
|
200
|
+
|
201
|
+
test('does not share custom level state across siblings', async ({ doesNotThrow }) => {
|
202
|
+
const stream = sink()
|
203
|
+
const logger = pino(stream)
|
204
|
+
logger.child({}, {
|
205
|
+
customLevels: { foo: 35 }
|
206
|
+
})
|
207
|
+
doesNotThrow(() => {
|
208
|
+
logger.child({}, {
|
209
|
+
customLevels: { foo: 35 }
|
210
|
+
})
|
211
|
+
})
|
212
|
+
})
|
213
|
+
|
214
|
+
test('custom level does not affect the levels serializer', async ({ equal }) => {
|
215
|
+
const stream = sink()
|
216
|
+
const logger = pino({
|
217
|
+
customLevels: {
|
218
|
+
foo: 35,
|
219
|
+
bar: 45
|
220
|
+
},
|
221
|
+
formatters: {
|
222
|
+
level (label, number) {
|
223
|
+
return { priority: number }
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}, stream)
|
227
|
+
|
228
|
+
logger.foo('test')
|
229
|
+
const { priority } = await once(stream, 'data')
|
230
|
+
equal(priority, 35)
|
231
|
+
})
|
232
|
+
|
233
|
+
test('When useOnlyCustomLevels is set to true, the level formatter should only get custom levels', async ({ equal }) => {
|
234
|
+
const stream = sink()
|
235
|
+
const logger = pino({
|
236
|
+
customLevels: {
|
237
|
+
answer: 42
|
238
|
+
},
|
239
|
+
useOnlyCustomLevels: true,
|
240
|
+
level: 42,
|
241
|
+
formatters: {
|
242
|
+
level (label, number) {
|
243
|
+
equal(label, 'answer')
|
244
|
+
equal(number, 42)
|
245
|
+
return { level: number }
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}, stream)
|
249
|
+
|
250
|
+
logger.answer('test')
|
251
|
+
const { level } = await once(stream, 'data')
|
252
|
+
equal(level, 42)
|
253
|
+
})
|
@@ -0,0 +1,398 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
/* eslint no-prototype-builtins: 0 */
|
4
|
+
|
5
|
+
const os = require('node:os')
|
6
|
+
const { test } = require('tap')
|
7
|
+
const { sink, once } = require('./helper')
|
8
|
+
const pino = require('../')
|
9
|
+
|
10
|
+
const { pid } = process
|
11
|
+
const hostname = os.hostname()
|
12
|
+
const level = 50
|
13
|
+
const name = 'error'
|
14
|
+
|
15
|
+
test('err is serialized with additional properties set on the Error object', async ({ ok, same }) => {
|
16
|
+
const stream = sink()
|
17
|
+
const err = Object.assign(new Error('myerror'), { foo: 'bar' })
|
18
|
+
const instance = pino(stream)
|
19
|
+
instance.level = name
|
20
|
+
instance[name](err)
|
21
|
+
const result = await once(stream, 'data')
|
22
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
23
|
+
delete result.time
|
24
|
+
same(result, {
|
25
|
+
pid,
|
26
|
+
hostname,
|
27
|
+
level,
|
28
|
+
err: {
|
29
|
+
type: 'Error',
|
30
|
+
message: err.message,
|
31
|
+
stack: err.stack,
|
32
|
+
foo: err.foo
|
33
|
+
},
|
34
|
+
msg: err.message
|
35
|
+
})
|
36
|
+
})
|
37
|
+
|
38
|
+
test('type should be detected based on constructor', async ({ ok, same }) => {
|
39
|
+
class Bar extends Error {}
|
40
|
+
const stream = sink()
|
41
|
+
const err = new Bar('myerror')
|
42
|
+
const instance = pino(stream)
|
43
|
+
instance.level = name
|
44
|
+
instance[name](err)
|
45
|
+
const result = await once(stream, 'data')
|
46
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
47
|
+
delete result.time
|
48
|
+
same(result, {
|
49
|
+
pid,
|
50
|
+
hostname,
|
51
|
+
level,
|
52
|
+
err: {
|
53
|
+
type: 'Bar',
|
54
|
+
message: err.message,
|
55
|
+
stack: err.stack
|
56
|
+
},
|
57
|
+
msg: err.message
|
58
|
+
})
|
59
|
+
})
|
60
|
+
|
61
|
+
test('type, message and stack should be first level properties', async ({ ok, same }) => {
|
62
|
+
const stream = sink()
|
63
|
+
const err = Object.assign(new Error('foo'), { foo: 'bar' })
|
64
|
+
const instance = pino(stream)
|
65
|
+
instance.level = name
|
66
|
+
instance[name](err)
|
67
|
+
|
68
|
+
const result = await once(stream, 'data')
|
69
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
70
|
+
delete result.time
|
71
|
+
same(result, {
|
72
|
+
pid,
|
73
|
+
hostname,
|
74
|
+
level,
|
75
|
+
err: {
|
76
|
+
type: 'Error',
|
77
|
+
message: err.message,
|
78
|
+
stack: err.stack,
|
79
|
+
foo: err.foo
|
80
|
+
},
|
81
|
+
msg: err.message
|
82
|
+
})
|
83
|
+
})
|
84
|
+
|
85
|
+
test('err serializer', async ({ ok, same }) => {
|
86
|
+
const stream = sink()
|
87
|
+
const err = Object.assign(new Error('myerror'), { foo: 'bar' })
|
88
|
+
const instance = pino({
|
89
|
+
serializers: {
|
90
|
+
err: pino.stdSerializers.err
|
91
|
+
}
|
92
|
+
}, stream)
|
93
|
+
|
94
|
+
instance.level = name
|
95
|
+
instance[name]({ err })
|
96
|
+
const result = await once(stream, 'data')
|
97
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
98
|
+
delete result.time
|
99
|
+
same(result, {
|
100
|
+
pid,
|
101
|
+
hostname,
|
102
|
+
level,
|
103
|
+
err: {
|
104
|
+
type: 'Error',
|
105
|
+
message: err.message,
|
106
|
+
stack: err.stack,
|
107
|
+
foo: err.foo
|
108
|
+
},
|
109
|
+
msg: err.message
|
110
|
+
})
|
111
|
+
})
|
112
|
+
|
113
|
+
test('an error with statusCode property is not confused for a http response', async ({ ok, same }) => {
|
114
|
+
const stream = sink()
|
115
|
+
const err = Object.assign(new Error('StatusCodeErr'), { statusCode: 500 })
|
116
|
+
const instance = pino(stream)
|
117
|
+
|
118
|
+
instance.level = name
|
119
|
+
instance[name](err)
|
120
|
+
const result = await once(stream, 'data')
|
121
|
+
|
122
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than Date.now()')
|
123
|
+
delete result.time
|
124
|
+
same(result, {
|
125
|
+
pid,
|
126
|
+
hostname,
|
127
|
+
level,
|
128
|
+
err: {
|
129
|
+
type: 'Error',
|
130
|
+
message: err.message,
|
131
|
+
stack: err.stack,
|
132
|
+
statusCode: err.statusCode
|
133
|
+
},
|
134
|
+
msg: err.message
|
135
|
+
})
|
136
|
+
})
|
137
|
+
|
138
|
+
test('stack is omitted if it is not set on err', t => {
|
139
|
+
t.plan(2)
|
140
|
+
const err = new Error('myerror')
|
141
|
+
delete err.stack
|
142
|
+
const instance = pino(sink(function (chunk, enc, cb) {
|
143
|
+
t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
|
144
|
+
delete chunk.time
|
145
|
+
t.equal(chunk.hasOwnProperty('stack'), false)
|
146
|
+
cb()
|
147
|
+
}))
|
148
|
+
|
149
|
+
instance.level = name
|
150
|
+
instance[name](err)
|
151
|
+
})
|
152
|
+
|
153
|
+
test('correctly ignores toString on errors', async ({ same }) => {
|
154
|
+
const err = new Error('myerror')
|
155
|
+
err.toString = () => undefined
|
156
|
+
const stream = sink()
|
157
|
+
const instance = pino({
|
158
|
+
test: 'this'
|
159
|
+
}, stream)
|
160
|
+
instance.fatal(err)
|
161
|
+
const result = await once(stream, 'data')
|
162
|
+
delete result.time
|
163
|
+
same(result, {
|
164
|
+
pid,
|
165
|
+
hostname,
|
166
|
+
level: 60,
|
167
|
+
err: {
|
168
|
+
type: 'Error',
|
169
|
+
message: err.message,
|
170
|
+
stack: err.stack
|
171
|
+
},
|
172
|
+
msg: err.message
|
173
|
+
})
|
174
|
+
})
|
175
|
+
|
176
|
+
test('assign mixin()', async ({ same }) => {
|
177
|
+
const err = new Error('myerror')
|
178
|
+
const stream = sink()
|
179
|
+
const instance = pino({
|
180
|
+
mixin () {
|
181
|
+
return { hello: 'world' }
|
182
|
+
}
|
183
|
+
}, stream)
|
184
|
+
instance.fatal(err)
|
185
|
+
const result = await once(stream, 'data')
|
186
|
+
delete result.time
|
187
|
+
same(result, {
|
188
|
+
pid,
|
189
|
+
hostname,
|
190
|
+
level: 60,
|
191
|
+
hello: 'world',
|
192
|
+
err: {
|
193
|
+
type: 'Error',
|
194
|
+
message: err.message,
|
195
|
+
stack: err.stack
|
196
|
+
},
|
197
|
+
msg: err.message
|
198
|
+
})
|
199
|
+
})
|
200
|
+
|
201
|
+
test('no err serializer', async ({ same }) => {
|
202
|
+
const err = new Error('myerror')
|
203
|
+
const stream = sink()
|
204
|
+
const instance = pino({
|
205
|
+
serializers: {}
|
206
|
+
}, stream)
|
207
|
+
instance.fatal(err)
|
208
|
+
const result = await once(stream, 'data')
|
209
|
+
delete result.time
|
210
|
+
same(result, {
|
211
|
+
pid,
|
212
|
+
hostname,
|
213
|
+
level: 60,
|
214
|
+
err: {
|
215
|
+
type: 'Error',
|
216
|
+
message: err.message,
|
217
|
+
stack: err.stack
|
218
|
+
},
|
219
|
+
msg: err.message
|
220
|
+
})
|
221
|
+
})
|
222
|
+
|
223
|
+
test('empty serializer', async ({ same }) => {
|
224
|
+
const err = new Error('myerror')
|
225
|
+
const stream = sink()
|
226
|
+
const instance = pino({
|
227
|
+
serializers: {
|
228
|
+
err () {}
|
229
|
+
}
|
230
|
+
}, stream)
|
231
|
+
instance.fatal(err)
|
232
|
+
const result = await once(stream, 'data')
|
233
|
+
delete result.time
|
234
|
+
same(result, {
|
235
|
+
pid,
|
236
|
+
hostname,
|
237
|
+
level: 60,
|
238
|
+
msg: err.message
|
239
|
+
})
|
240
|
+
})
|
241
|
+
|
242
|
+
test('assign mixin()', async ({ same }) => {
|
243
|
+
const err = new Error('myerror')
|
244
|
+
const stream = sink()
|
245
|
+
const instance = pino({
|
246
|
+
mixin () {
|
247
|
+
return { hello: 'world' }
|
248
|
+
}
|
249
|
+
}, stream)
|
250
|
+
instance.fatal(err)
|
251
|
+
const result = await once(stream, 'data')
|
252
|
+
delete result.time
|
253
|
+
same(result, {
|
254
|
+
pid,
|
255
|
+
hostname,
|
256
|
+
level: 60,
|
257
|
+
hello: 'world',
|
258
|
+
err: {
|
259
|
+
type: 'Error',
|
260
|
+
message: err.message,
|
261
|
+
stack: err.stack
|
262
|
+
},
|
263
|
+
msg: err.message
|
264
|
+
})
|
265
|
+
})
|
266
|
+
|
267
|
+
test('no err serializer', async ({ same }) => {
|
268
|
+
const err = new Error('myerror')
|
269
|
+
const stream = sink()
|
270
|
+
const instance = pino({
|
271
|
+
serializers: {}
|
272
|
+
}, stream)
|
273
|
+
instance.fatal(err)
|
274
|
+
const result = await once(stream, 'data')
|
275
|
+
delete result.time
|
276
|
+
same(result, {
|
277
|
+
pid,
|
278
|
+
hostname,
|
279
|
+
level: 60,
|
280
|
+
err: {
|
281
|
+
type: 'Error',
|
282
|
+
message: err.message,
|
283
|
+
stack: err.stack
|
284
|
+
},
|
285
|
+
msg: err.message
|
286
|
+
})
|
287
|
+
})
|
288
|
+
|
289
|
+
test('empty serializer', async ({ same }) => {
|
290
|
+
const err = new Error('myerror')
|
291
|
+
const stream = sink()
|
292
|
+
const instance = pino({
|
293
|
+
serializers: {
|
294
|
+
err () {}
|
295
|
+
}
|
296
|
+
}, stream)
|
297
|
+
instance.fatal(err)
|
298
|
+
const result = await once(stream, 'data')
|
299
|
+
delete result.time
|
300
|
+
same(result, {
|
301
|
+
pid,
|
302
|
+
hostname,
|
303
|
+
level: 60,
|
304
|
+
msg: err.message
|
305
|
+
})
|
306
|
+
})
|
307
|
+
|
308
|
+
test('correctly adds error information when nestedKey is used', async ({ same }) => {
|
309
|
+
const err = new Error('myerror')
|
310
|
+
err.toString = () => undefined
|
311
|
+
const stream = sink()
|
312
|
+
const instance = pino({
|
313
|
+
test: 'this',
|
314
|
+
nestedKey: 'obj'
|
315
|
+
}, stream)
|
316
|
+
instance.fatal(err)
|
317
|
+
const result = await once(stream, 'data')
|
318
|
+
delete result.time
|
319
|
+
same(result, {
|
320
|
+
pid,
|
321
|
+
hostname,
|
322
|
+
level: 60,
|
323
|
+
obj: {
|
324
|
+
err: {
|
325
|
+
type: 'Error',
|
326
|
+
stack: err.stack,
|
327
|
+
message: err.message
|
328
|
+
}
|
329
|
+
},
|
330
|
+
msg: err.message
|
331
|
+
})
|
332
|
+
})
|
333
|
+
|
334
|
+
test('correctly adds msg on error when nestedKey is used', async ({ same }) => {
|
335
|
+
const err = new Error('myerror')
|
336
|
+
err.toString = () => undefined
|
337
|
+
const stream = sink()
|
338
|
+
const instance = pino({
|
339
|
+
test: 'this',
|
340
|
+
nestedKey: 'obj'
|
341
|
+
}, stream)
|
342
|
+
instance.fatal(err, 'msg message')
|
343
|
+
const result = await once(stream, 'data')
|
344
|
+
delete result.time
|
345
|
+
same(result, {
|
346
|
+
pid,
|
347
|
+
hostname,
|
348
|
+
level: 60,
|
349
|
+
obj: {
|
350
|
+
err: {
|
351
|
+
type: 'Error',
|
352
|
+
stack: err.stack,
|
353
|
+
message: err.message
|
354
|
+
}
|
355
|
+
},
|
356
|
+
msg: 'msg message'
|
357
|
+
})
|
358
|
+
})
|
359
|
+
|
360
|
+
test('msg should take precedence over error message on mergingObject', async ({ same }) => {
|
361
|
+
const err = new Error('myerror')
|
362
|
+
const stream = sink()
|
363
|
+
const instance = pino(stream)
|
364
|
+
instance.error({ msg: 'my message', err })
|
365
|
+
const result = await once(stream, 'data')
|
366
|
+
delete result.time
|
367
|
+
same(result, {
|
368
|
+
pid,
|
369
|
+
hostname,
|
370
|
+
level: 50,
|
371
|
+
err: {
|
372
|
+
type: 'Error',
|
373
|
+
stack: err.stack,
|
374
|
+
message: err.message
|
375
|
+
},
|
376
|
+
msg: 'my message'
|
377
|
+
})
|
378
|
+
})
|
379
|
+
|
380
|
+
test('considers messageKey when giving msg precedence over error', async ({ same }) => {
|
381
|
+
const err = new Error('myerror')
|
382
|
+
const stream = sink()
|
383
|
+
const instance = pino({ messageKey: 'message' }, stream)
|
384
|
+
instance.error({ message: 'my message', err })
|
385
|
+
const result = await once(stream, 'data')
|
386
|
+
delete result.time
|
387
|
+
same(result, {
|
388
|
+
pid,
|
389
|
+
hostname,
|
390
|
+
level: 50,
|
391
|
+
err: {
|
392
|
+
type: 'Error',
|
393
|
+
stack: err.stack,
|
394
|
+
message: err.message
|
395
|
+
},
|
396
|
+
message: 'my message'
|
397
|
+
})
|
398
|
+
})
|
@@ -0,0 +1,34 @@
|
|
1
|
+
'use strict'
|
2
|
+
const { test } = require('tap')
|
3
|
+
const { sink, once } = require('./helper')
|
4
|
+
const stdSerializers = require('pino-std-serializers')
|
5
|
+
const pino = require('../')
|
6
|
+
|
7
|
+
test('set the errorKey with error serializer', async ({ equal, same }) => {
|
8
|
+
const stream = sink()
|
9
|
+
const errorKey = 'error'
|
10
|
+
const instance = pino({
|
11
|
+
errorKey,
|
12
|
+
serializers: { [errorKey]: stdSerializers.err }
|
13
|
+
}, stream)
|
14
|
+
instance.error(new ReferenceError('test'))
|
15
|
+
const o = await once(stream, 'data')
|
16
|
+
equal(typeof o[errorKey], 'object')
|
17
|
+
equal(o[errorKey].type, 'ReferenceError')
|
18
|
+
equal(o[errorKey].message, 'test')
|
19
|
+
equal(typeof o[errorKey].stack, 'string')
|
20
|
+
})
|
21
|
+
|
22
|
+
test('set the errorKey without error serializer', async ({ equal, same }) => {
|
23
|
+
const stream = sink()
|
24
|
+
const errorKey = 'error'
|
25
|
+
const instance = pino({
|
26
|
+
errorKey
|
27
|
+
}, stream)
|
28
|
+
instance.error(new ReferenceError('test'))
|
29
|
+
const o = await once(stream, 'data')
|
30
|
+
equal(typeof o[errorKey], 'object')
|
31
|
+
equal(o[errorKey].type, 'ReferenceError')
|
32
|
+
equal(o[errorKey].message, 'test')
|
33
|
+
equal(typeof o[errorKey].stack, 'string')
|
34
|
+
})
|