jsonspecific 0.0.1-security → 3.14.7
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 jsonspecific 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 +118 -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,659 @@
|
|
1
|
+
'use strict'
|
2
|
+
const test = require('tape')
|
3
|
+
const fresh = require('import-fresh')
|
4
|
+
const pinoStdSerializers = require('pino-std-serializers')
|
5
|
+
const pino = require('../browser')
|
6
|
+
|
7
|
+
levelTest('fatal')
|
8
|
+
levelTest('error')
|
9
|
+
levelTest('warn')
|
10
|
+
levelTest('info')
|
11
|
+
levelTest('debug')
|
12
|
+
levelTest('trace')
|
13
|
+
|
14
|
+
test('silent level', ({ end, fail, pass }) => {
|
15
|
+
const instance = pino({
|
16
|
+
level: 'silent',
|
17
|
+
browser: { write: fail }
|
18
|
+
})
|
19
|
+
instance.info('test')
|
20
|
+
const child = instance.child({ test: 'test' })
|
21
|
+
child.info('msg-test')
|
22
|
+
// use setTimeout because setImmediate isn't supported in most browsers
|
23
|
+
setTimeout(() => {
|
24
|
+
pass()
|
25
|
+
end()
|
26
|
+
}, 0)
|
27
|
+
})
|
28
|
+
|
29
|
+
test('enabled false', ({ end, fail, pass }) => {
|
30
|
+
const instance = pino({
|
31
|
+
enabled: false,
|
32
|
+
browser: { write: fail }
|
33
|
+
})
|
34
|
+
instance.info('test')
|
35
|
+
const child = instance.child({ test: 'test' })
|
36
|
+
child.info('msg-test')
|
37
|
+
// use setTimeout because setImmediate isn't supported in most browsers
|
38
|
+
setTimeout(() => {
|
39
|
+
pass()
|
40
|
+
end()
|
41
|
+
}, 0)
|
42
|
+
})
|
43
|
+
|
44
|
+
test('throw if creating child without bindings', ({ end, throws }) => {
|
45
|
+
const instance = pino()
|
46
|
+
throws(() => instance.child())
|
47
|
+
end()
|
48
|
+
})
|
49
|
+
|
50
|
+
test('stubs write, flush and ee methods on instance', ({ end, ok, is }) => {
|
51
|
+
const instance = pino()
|
52
|
+
|
53
|
+
ok(isFunc(instance.setMaxListeners))
|
54
|
+
ok(isFunc(instance.getMaxListeners))
|
55
|
+
ok(isFunc(instance.emit))
|
56
|
+
ok(isFunc(instance.addListener))
|
57
|
+
ok(isFunc(instance.on))
|
58
|
+
ok(isFunc(instance.prependListener))
|
59
|
+
ok(isFunc(instance.once))
|
60
|
+
ok(isFunc(instance.prependOnceListener))
|
61
|
+
ok(isFunc(instance.removeListener))
|
62
|
+
ok(isFunc(instance.removeAllListeners))
|
63
|
+
ok(isFunc(instance.listeners))
|
64
|
+
ok(isFunc(instance.listenerCount))
|
65
|
+
ok(isFunc(instance.eventNames))
|
66
|
+
ok(isFunc(instance.write))
|
67
|
+
ok(isFunc(instance.flush))
|
68
|
+
|
69
|
+
is(instance.on(), undefined)
|
70
|
+
|
71
|
+
end()
|
72
|
+
})
|
73
|
+
|
74
|
+
test('exposes levels object', ({ end, same }) => {
|
75
|
+
same(pino.levels, {
|
76
|
+
values: {
|
77
|
+
fatal: 60,
|
78
|
+
error: 50,
|
79
|
+
warn: 40,
|
80
|
+
info: 30,
|
81
|
+
debug: 20,
|
82
|
+
trace: 10
|
83
|
+
},
|
84
|
+
labels: {
|
85
|
+
10: 'trace',
|
86
|
+
20: 'debug',
|
87
|
+
30: 'info',
|
88
|
+
40: 'warn',
|
89
|
+
50: 'error',
|
90
|
+
60: 'fatal'
|
91
|
+
}
|
92
|
+
})
|
93
|
+
|
94
|
+
end()
|
95
|
+
})
|
96
|
+
|
97
|
+
test('exposes faux stdSerializers', ({ end, ok, same }) => {
|
98
|
+
ok(pino.stdSerializers)
|
99
|
+
// make sure faux stdSerializers match pino-std-serializers
|
100
|
+
for (const serializer in pinoStdSerializers) {
|
101
|
+
ok(pino.stdSerializers[serializer], `pino.stdSerializers.${serializer}`)
|
102
|
+
}
|
103
|
+
// confirm faux methods return empty objects
|
104
|
+
same(pino.stdSerializers.req(), {})
|
105
|
+
same(pino.stdSerializers.mapHttpRequest(), {})
|
106
|
+
same(pino.stdSerializers.mapHttpResponse(), {})
|
107
|
+
same(pino.stdSerializers.res(), {})
|
108
|
+
// confirm wrapping function is a passthrough
|
109
|
+
const noChange = { foo: 'bar', fuz: 42 }
|
110
|
+
same(pino.stdSerializers.wrapRequestSerializer(noChange), noChange)
|
111
|
+
same(pino.stdSerializers.wrapResponseSerializer(noChange), noChange)
|
112
|
+
end()
|
113
|
+
})
|
114
|
+
|
115
|
+
test('exposes err stdSerializer', ({ end, ok }) => {
|
116
|
+
ok(pino.stdSerializers.err)
|
117
|
+
ok(pino.stdSerializers.err(Error()))
|
118
|
+
end()
|
119
|
+
})
|
120
|
+
|
121
|
+
consoleMethodTest('error')
|
122
|
+
consoleMethodTest('fatal', 'error')
|
123
|
+
consoleMethodTest('warn')
|
124
|
+
consoleMethodTest('info')
|
125
|
+
consoleMethodTest('debug')
|
126
|
+
consoleMethodTest('trace')
|
127
|
+
absentConsoleMethodTest('error', 'log')
|
128
|
+
absentConsoleMethodTest('warn', 'error')
|
129
|
+
absentConsoleMethodTest('info', 'log')
|
130
|
+
absentConsoleMethodTest('debug', 'log')
|
131
|
+
absentConsoleMethodTest('trace', 'log')
|
132
|
+
|
133
|
+
// do not run this with airtap
|
134
|
+
if (process.title !== 'browser') {
|
135
|
+
test('in absence of console, log methods become noops', ({ end, ok }) => {
|
136
|
+
const console = global.console
|
137
|
+
delete global.console
|
138
|
+
const instance = fresh('../browser')()
|
139
|
+
global.console = console
|
140
|
+
ok(fnName(instance.log).match(/noop/))
|
141
|
+
ok(fnName(instance.fatal).match(/noop/))
|
142
|
+
ok(fnName(instance.error).match(/noop/))
|
143
|
+
ok(fnName(instance.warn).match(/noop/))
|
144
|
+
ok(fnName(instance.info).match(/noop/))
|
145
|
+
ok(fnName(instance.debug).match(/noop/))
|
146
|
+
ok(fnName(instance.trace).match(/noop/))
|
147
|
+
end()
|
148
|
+
})
|
149
|
+
}
|
150
|
+
|
151
|
+
test('opts.browser.asObject logs pino-like object to console', ({ end, ok, is }) => {
|
152
|
+
const info = console.info
|
153
|
+
console.info = function (o) {
|
154
|
+
is(o.level, 30)
|
155
|
+
is(o.msg, 'test')
|
156
|
+
ok(o.time)
|
157
|
+
console.info = info
|
158
|
+
}
|
159
|
+
const instance = require('../browser')({
|
160
|
+
browser: {
|
161
|
+
asObject: true
|
162
|
+
}
|
163
|
+
})
|
164
|
+
|
165
|
+
instance.info('test')
|
166
|
+
end()
|
167
|
+
})
|
168
|
+
test('opts.browser.asObject uses opts.messageKey in logs', ({ end, ok, is }) => {
|
169
|
+
const messageKey = 'message'
|
170
|
+
const instance = require('../browser')({
|
171
|
+
messageKey,
|
172
|
+
browser: {
|
173
|
+
asObject: true,
|
174
|
+
write: function (o) {
|
175
|
+
is(o.level, 30)
|
176
|
+
is(o[messageKey], 'test')
|
177
|
+
ok(o.time)
|
178
|
+
}
|
179
|
+
}
|
180
|
+
})
|
181
|
+
|
182
|
+
instance.info('test')
|
183
|
+
end()
|
184
|
+
})
|
185
|
+
|
186
|
+
test('opts.browser.formatters (level) logs pino-like object to console', ({ end, ok, is }) => {
|
187
|
+
const info = console.info
|
188
|
+
console.info = function (o) {
|
189
|
+
is(o.level, 30)
|
190
|
+
is(o.label, 'info')
|
191
|
+
is(o.msg, 'test')
|
192
|
+
ok(o.time)
|
193
|
+
console.info = info
|
194
|
+
}
|
195
|
+
const instance = require('../browser')({
|
196
|
+
browser: {
|
197
|
+
formatters: {
|
198
|
+
level (label, number) {
|
199
|
+
return { label, level: number }
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
})
|
204
|
+
|
205
|
+
instance.info('test')
|
206
|
+
end()
|
207
|
+
})
|
208
|
+
|
209
|
+
test('opts.browser.formatters (log) logs pino-like object to console', ({ end, ok, is }) => {
|
210
|
+
const info = console.info
|
211
|
+
console.info = function (o) {
|
212
|
+
is(o.level, 30)
|
213
|
+
is(o.msg, 'test')
|
214
|
+
is(o.hello, 'world')
|
215
|
+
is(o.newField, 'test')
|
216
|
+
ok(o.time, `Logged at ${o.time}`)
|
217
|
+
console.info = info
|
218
|
+
}
|
219
|
+
const instance = require('../browser')({
|
220
|
+
browser: {
|
221
|
+
formatters: {
|
222
|
+
log (o) {
|
223
|
+
return { ...o, newField: 'test', time: `Logged at ${o.time}` }
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
})
|
228
|
+
|
229
|
+
instance.info({ hello: 'world' }, 'test')
|
230
|
+
end()
|
231
|
+
})
|
232
|
+
|
233
|
+
test('opts.browser.serialize and opts.browser.transmit only serializes log data once', ({ end, ok, is }) => {
|
234
|
+
const instance = require('../browser')({
|
235
|
+
serializers: {
|
236
|
+
extras (data) {
|
237
|
+
return { serializedExtras: data }
|
238
|
+
}
|
239
|
+
},
|
240
|
+
browser: {
|
241
|
+
serialize: ['extras'],
|
242
|
+
transmit: {
|
243
|
+
level: 'info',
|
244
|
+
send (level, o) {
|
245
|
+
is(o.messages[0].extras.serializedExtras, 'world')
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}
|
249
|
+
})
|
250
|
+
|
251
|
+
instance.info({ extras: 'world' }, 'test')
|
252
|
+
end()
|
253
|
+
})
|
254
|
+
|
255
|
+
test('opts.browser.serialize and opts.asObject only serializes log data once', ({ end, ok, is }) => {
|
256
|
+
const instance = require('../browser')({
|
257
|
+
serializers: {
|
258
|
+
extras (data) {
|
259
|
+
return { serializedExtras: data }
|
260
|
+
}
|
261
|
+
},
|
262
|
+
browser: {
|
263
|
+
serialize: ['extras'],
|
264
|
+
asObject: true,
|
265
|
+
write: function (o) {
|
266
|
+
is(o.extras.serializedExtras, 'world')
|
267
|
+
}
|
268
|
+
}
|
269
|
+
})
|
270
|
+
|
271
|
+
instance.info({ extras: 'world' }, 'test')
|
272
|
+
end()
|
273
|
+
})
|
274
|
+
|
275
|
+
test('opts.browser.serialize, opts.asObject and opts.browser.transmit only serializes log data once', ({ end, ok, is }) => {
|
276
|
+
const instance = require('../browser')({
|
277
|
+
serializers: {
|
278
|
+
extras (data) {
|
279
|
+
return { serializedExtras: data }
|
280
|
+
}
|
281
|
+
},
|
282
|
+
browser: {
|
283
|
+
serialize: ['extras'],
|
284
|
+
asObject: true,
|
285
|
+
transmit: {
|
286
|
+
send (level, o) {
|
287
|
+
is(o.messages[0].extras.serializedExtras, 'world')
|
288
|
+
}
|
289
|
+
}
|
290
|
+
}
|
291
|
+
})
|
292
|
+
|
293
|
+
instance.info({ extras: 'world' }, 'test')
|
294
|
+
end()
|
295
|
+
})
|
296
|
+
|
297
|
+
test('opts.browser.write func log single string', ({ end, ok, is }) => {
|
298
|
+
const instance = pino({
|
299
|
+
browser: {
|
300
|
+
write: function (o) {
|
301
|
+
is(o.level, 30)
|
302
|
+
is(o.msg, 'test')
|
303
|
+
ok(o.time)
|
304
|
+
}
|
305
|
+
}
|
306
|
+
})
|
307
|
+
instance.info('test')
|
308
|
+
|
309
|
+
end()
|
310
|
+
})
|
311
|
+
|
312
|
+
test('opts.browser.write func string joining', ({ end, ok, is }) => {
|
313
|
+
const instance = pino({
|
314
|
+
browser: {
|
315
|
+
write: function (o) {
|
316
|
+
is(o.level, 30)
|
317
|
+
is(o.msg, 'test test2 test3')
|
318
|
+
ok(o.time)
|
319
|
+
}
|
320
|
+
}
|
321
|
+
})
|
322
|
+
instance.info('test %s %s', 'test2', 'test3')
|
323
|
+
|
324
|
+
end()
|
325
|
+
})
|
326
|
+
|
327
|
+
test('opts.browser.write func string joining when asObject is true', ({ end, ok, is }) => {
|
328
|
+
const instance = pino({
|
329
|
+
browser: {
|
330
|
+
asObject: true,
|
331
|
+
write: function (o) {
|
332
|
+
is(o.level, 30)
|
333
|
+
is(o.msg, 'test test2 test3')
|
334
|
+
ok(o.time)
|
335
|
+
}
|
336
|
+
}
|
337
|
+
})
|
338
|
+
instance.info('test %s %s', 'test2', 'test3')
|
339
|
+
|
340
|
+
end()
|
341
|
+
})
|
342
|
+
|
343
|
+
test('opts.browser.write func string object joining', ({ end, ok, is }) => {
|
344
|
+
const instance = pino({
|
345
|
+
browser: {
|
346
|
+
write: function (o) {
|
347
|
+
is(o.level, 30)
|
348
|
+
is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
349
|
+
ok(o.time)
|
350
|
+
}
|
351
|
+
}
|
352
|
+
})
|
353
|
+
instance.info('test %j %j', { test: 'test2' }, { test: 'test3' })
|
354
|
+
|
355
|
+
end()
|
356
|
+
})
|
357
|
+
|
358
|
+
test('opts.browser.write func string object joining when asObject is true', ({ end, ok, is }) => {
|
359
|
+
const instance = pino({
|
360
|
+
browser: {
|
361
|
+
asObject: true,
|
362
|
+
write: function (o) {
|
363
|
+
is(o.level, 30)
|
364
|
+
is(o.msg, 'test {"test":"test2"} {"test":"test3"}')
|
365
|
+
ok(o.time)
|
366
|
+
}
|
367
|
+
}
|
368
|
+
})
|
369
|
+
instance.info('test %j %j', { test: 'test2' }, { test: 'test3' })
|
370
|
+
|
371
|
+
end()
|
372
|
+
})
|
373
|
+
|
374
|
+
test('opts.browser.write func string interpolation', ({ end, ok, is }) => {
|
375
|
+
const instance = pino({
|
376
|
+
browser: {
|
377
|
+
write: function (o) {
|
378
|
+
is(o.level, 30)
|
379
|
+
is(o.msg, 'test2 test ({"test":"test3"})')
|
380
|
+
ok(o.time)
|
381
|
+
}
|
382
|
+
}
|
383
|
+
})
|
384
|
+
instance.info('%s test (%j)', 'test2', { test: 'test3' })
|
385
|
+
|
386
|
+
end()
|
387
|
+
})
|
388
|
+
|
389
|
+
test('opts.browser.write func number', ({ end, ok, is }) => {
|
390
|
+
const instance = pino({
|
391
|
+
browser: {
|
392
|
+
write: function (o) {
|
393
|
+
is(o.level, 30)
|
394
|
+
is(o.msg, 1)
|
395
|
+
ok(o.time)
|
396
|
+
}
|
397
|
+
}
|
398
|
+
})
|
399
|
+
instance.info(1)
|
400
|
+
|
401
|
+
end()
|
402
|
+
})
|
403
|
+
|
404
|
+
test('opts.browser.write func log single object', ({ end, ok, is }) => {
|
405
|
+
const instance = pino({
|
406
|
+
browser: {
|
407
|
+
write: function (o) {
|
408
|
+
is(o.level, 30)
|
409
|
+
is(o.test, 'test')
|
410
|
+
ok(o.time)
|
411
|
+
}
|
412
|
+
}
|
413
|
+
})
|
414
|
+
instance.info({ test: 'test' })
|
415
|
+
|
416
|
+
end()
|
417
|
+
})
|
418
|
+
|
419
|
+
test('opts.browser.write obj writes to methods corresponding to level', ({ end, ok, is }) => {
|
420
|
+
const instance = pino({
|
421
|
+
browser: {
|
422
|
+
write: {
|
423
|
+
error: function (o) {
|
424
|
+
is(o.level, 50)
|
425
|
+
is(o.test, 'test')
|
426
|
+
ok(o.time)
|
427
|
+
}
|
428
|
+
}
|
429
|
+
}
|
430
|
+
})
|
431
|
+
instance.error({ test: 'test' })
|
432
|
+
|
433
|
+
end()
|
434
|
+
})
|
435
|
+
|
436
|
+
test('opts.browser.asObject/write supports child loggers', ({ end, ok, is }) => {
|
437
|
+
const instance = pino({
|
438
|
+
browser: {
|
439
|
+
write (o) {
|
440
|
+
is(o.level, 30)
|
441
|
+
is(o.test, 'test')
|
442
|
+
is(o.msg, 'msg-test')
|
443
|
+
ok(o.time)
|
444
|
+
}
|
445
|
+
}
|
446
|
+
})
|
447
|
+
const child = instance.child({ test: 'test' })
|
448
|
+
child.info('msg-test')
|
449
|
+
|
450
|
+
end()
|
451
|
+
})
|
452
|
+
|
453
|
+
test('opts.browser.asObject/write supports child child loggers', ({ end, ok, is }) => {
|
454
|
+
const instance = pino({
|
455
|
+
browser: {
|
456
|
+
write (o) {
|
457
|
+
is(o.level, 30)
|
458
|
+
is(o.test, 'test')
|
459
|
+
is(o.foo, 'bar')
|
460
|
+
is(o.msg, 'msg-test')
|
461
|
+
ok(o.time)
|
462
|
+
}
|
463
|
+
}
|
464
|
+
})
|
465
|
+
const child = instance.child({ test: 'test' }).child({ foo: 'bar' })
|
466
|
+
child.info('msg-test')
|
467
|
+
|
468
|
+
end()
|
469
|
+
})
|
470
|
+
|
471
|
+
test('opts.browser.asObject/write supports child child child loggers', ({ end, ok, is }) => {
|
472
|
+
const instance = pino({
|
473
|
+
browser: {
|
474
|
+
write (o) {
|
475
|
+
is(o.level, 30)
|
476
|
+
is(o.test, 'test')
|
477
|
+
is(o.foo, 'bar')
|
478
|
+
is(o.baz, 'bop')
|
479
|
+
is(o.msg, 'msg-test')
|
480
|
+
ok(o.time)
|
481
|
+
}
|
482
|
+
}
|
483
|
+
})
|
484
|
+
const child = instance.child({ test: 'test' }).child({ foo: 'bar' }).child({ baz: 'bop' })
|
485
|
+
child.info('msg-test')
|
486
|
+
|
487
|
+
end()
|
488
|
+
})
|
489
|
+
|
490
|
+
test('opts.browser.asObject defensively mitigates naughty numbers', ({ end, pass }) => {
|
491
|
+
const instance = pino({
|
492
|
+
browser: { asObject: true, write: () => {} }
|
493
|
+
})
|
494
|
+
const child = instance.child({ test: 'test' })
|
495
|
+
child._childLevel = -10
|
496
|
+
child.info('test')
|
497
|
+
pass() // if we reached here, there was no infinite loop, so, .. pass.
|
498
|
+
|
499
|
+
end()
|
500
|
+
})
|
501
|
+
|
502
|
+
test('opts.browser.write obj falls back to console where a method is not supplied', ({ end, ok, is }) => {
|
503
|
+
const info = console.info
|
504
|
+
console.info = (o) => {
|
505
|
+
is(o.level, 30)
|
506
|
+
is(o.msg, 'test')
|
507
|
+
ok(o.time)
|
508
|
+
console.info = info
|
509
|
+
}
|
510
|
+
const instance = require('../browser')({
|
511
|
+
browser: {
|
512
|
+
write: {
|
513
|
+
error (o) {
|
514
|
+
is(o.level, 50)
|
515
|
+
is(o.test, 'test')
|
516
|
+
ok(o.time)
|
517
|
+
}
|
518
|
+
}
|
519
|
+
}
|
520
|
+
})
|
521
|
+
instance.error({ test: 'test' })
|
522
|
+
instance.info('test')
|
523
|
+
|
524
|
+
end()
|
525
|
+
})
|
526
|
+
|
527
|
+
function levelTest (name) {
|
528
|
+
test(name + ' logs', ({ end, is }) => {
|
529
|
+
const msg = 'hello world'
|
530
|
+
sink(name, (args) => {
|
531
|
+
is(args[0], msg)
|
532
|
+
end()
|
533
|
+
})
|
534
|
+
pino({ level: name })[name](msg)
|
535
|
+
})
|
536
|
+
|
537
|
+
test('passing objects at level ' + name, ({ end, is }) => {
|
538
|
+
const msg = { hello: 'world' }
|
539
|
+
sink(name, (args) => {
|
540
|
+
is(args[0], msg)
|
541
|
+
end()
|
542
|
+
})
|
543
|
+
pino({ level: name })[name](msg)
|
544
|
+
})
|
545
|
+
|
546
|
+
test('passing an object and a string at level ' + name, ({ end, is }) => {
|
547
|
+
const a = { hello: 'world' }
|
548
|
+
const b = 'a string'
|
549
|
+
sink(name, (args) => {
|
550
|
+
is(args[0], a)
|
551
|
+
is(args[1], b)
|
552
|
+
end()
|
553
|
+
})
|
554
|
+
pino({ level: name })[name](a, b)
|
555
|
+
})
|
556
|
+
|
557
|
+
test('formatting logs as ' + name, ({ end, is }) => {
|
558
|
+
sink(name, (args) => {
|
559
|
+
is(args[0], 'hello %d')
|
560
|
+
is(args[1], 42)
|
561
|
+
end()
|
562
|
+
})
|
563
|
+
pino({ level: name })[name]('hello %d', 42)
|
564
|
+
})
|
565
|
+
|
566
|
+
test('passing error at level ' + name, ({ end, is }) => {
|
567
|
+
const err = new Error('myerror')
|
568
|
+
sink(name, (args) => {
|
569
|
+
is(args[0], err)
|
570
|
+
end()
|
571
|
+
})
|
572
|
+
pino({ level: name })[name](err)
|
573
|
+
})
|
574
|
+
|
575
|
+
test('passing error with a serializer at level ' + name, ({ end, is }) => {
|
576
|
+
// in browser - should have no effect (should not crash)
|
577
|
+
const err = new Error('myerror')
|
578
|
+
sink(name, (args) => {
|
579
|
+
is(args[0].err, err)
|
580
|
+
end()
|
581
|
+
})
|
582
|
+
const instance = pino({
|
583
|
+
level: name,
|
584
|
+
serializers: {
|
585
|
+
err: pino.stdSerializers.err
|
586
|
+
}
|
587
|
+
})
|
588
|
+
instance[name]({ err })
|
589
|
+
})
|
590
|
+
|
591
|
+
test('child logger for level ' + name, ({ end, is }) => {
|
592
|
+
const msg = 'hello world'
|
593
|
+
const parent = { hello: 'world' }
|
594
|
+
sink(name, (args) => {
|
595
|
+
is(args[0], parent)
|
596
|
+
is(args[1], msg)
|
597
|
+
end()
|
598
|
+
})
|
599
|
+
const instance = pino({ level: name })
|
600
|
+
const child = instance.child(parent)
|
601
|
+
child[name](msg)
|
602
|
+
})
|
603
|
+
|
604
|
+
test('child-child logger for level ' + name, ({ end, is }) => {
|
605
|
+
const msg = 'hello world'
|
606
|
+
const grandParent = { hello: 'world' }
|
607
|
+
const parent = { hello: 'you' }
|
608
|
+
sink(name, (args) => {
|
609
|
+
is(args[0], grandParent)
|
610
|
+
is(args[1], parent)
|
611
|
+
is(args[2], msg)
|
612
|
+
end()
|
613
|
+
})
|
614
|
+
const instance = pino({ level: name })
|
615
|
+
const child = instance.child(grandParent).child(parent)
|
616
|
+
child[name](msg)
|
617
|
+
})
|
618
|
+
}
|
619
|
+
|
620
|
+
function consoleMethodTest (level, method) {
|
621
|
+
if (!method) method = level
|
622
|
+
test('pino().' + level + ' uses console.' + method, ({ end, is }) => {
|
623
|
+
sink(method, (args) => {
|
624
|
+
is(args[0], 'test')
|
625
|
+
end()
|
626
|
+
})
|
627
|
+
const instance = require('../browser')({ level })
|
628
|
+
instance[level]('test')
|
629
|
+
})
|
630
|
+
}
|
631
|
+
|
632
|
+
function absentConsoleMethodTest (method, fallback) {
|
633
|
+
test('in absence of console.' + method + ', console.' + fallback + ' is used', ({ end, is }) => {
|
634
|
+
const fn = console[method]
|
635
|
+
console[method] = undefined
|
636
|
+
sink(fallback, function (args) {
|
637
|
+
is(args[0], 'test')
|
638
|
+
end()
|
639
|
+
console[method] = fn
|
640
|
+
})
|
641
|
+
const instance = require('../browser')({ level: method })
|
642
|
+
instance[method]('test')
|
643
|
+
})
|
644
|
+
}
|
645
|
+
|
646
|
+
function isFunc (fn) { return typeof fn === 'function' }
|
647
|
+
function fnName (fn) {
|
648
|
+
const rx = /^\s*function\s*([^(]*)/i
|
649
|
+
const match = rx.exec(fn)
|
650
|
+
return match && match[1]
|
651
|
+
}
|
652
|
+
function sink (method, fn) {
|
653
|
+
if (method === 'fatal') method = 'error'
|
654
|
+
const orig = console[method]
|
655
|
+
console[method] = function () {
|
656
|
+
console[method] = orig
|
657
|
+
fn(Array.prototype.slice.call(arguments))
|
658
|
+
}
|
659
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { test } = require('tap')
|
4
|
+
const { sink, once } = require('./helper')
|
5
|
+
const { PassThrough } = require('node:stream')
|
6
|
+
const pino = require('../')
|
7
|
+
|
8
|
+
test('Proxy and stream objects', async ({ equal }) => {
|
9
|
+
const s = new PassThrough()
|
10
|
+
s.resume()
|
11
|
+
s.write('', () => {})
|
12
|
+
const obj = { s, p: new Proxy({}, { get () { throw new Error('kaboom') } }) }
|
13
|
+
const stream = sink()
|
14
|
+
const instance = pino(stream)
|
15
|
+
instance.info({ obj })
|
16
|
+
|
17
|
+
const result = await once(stream, 'data')
|
18
|
+
|
19
|
+
equal(result.obj, '[unable to serialize, circular reference is too complex to analyze]')
|
20
|
+
})
|
21
|
+
|
22
|
+
test('Proxy and stream objects', async ({ equal }) => {
|
23
|
+
const s = new PassThrough()
|
24
|
+
s.resume()
|
25
|
+
s.write('', () => {})
|
26
|
+
const obj = { s, p: new Proxy({}, { get () { throw new Error('kaboom') } }) }
|
27
|
+
const stream = sink()
|
28
|
+
const instance = pino(stream)
|
29
|
+
instance.info(obj)
|
30
|
+
|
31
|
+
const result = await once(stream, 'data')
|
32
|
+
|
33
|
+
equal(result.p, '[unable to serialize, circular reference is too complex to analyze]')
|
34
|
+
})
|
@@ -0,0 +1,32 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { test } = require('tap')
|
4
|
+
const writer = require('flush-write-stream')
|
5
|
+
const pino = require('../')
|
6
|
+
|
7
|
+
function capture () {
|
8
|
+
const ws = writer((chunk, enc, cb) => {
|
9
|
+
ws.data += chunk.toString()
|
10
|
+
cb()
|
11
|
+
})
|
12
|
+
ws.data = ''
|
13
|
+
return ws
|
14
|
+
}
|
15
|
+
|
16
|
+
test('pino uses LF by default', async ({ ok }) => {
|
17
|
+
const stream = capture()
|
18
|
+
const logger = pino(stream)
|
19
|
+
logger.info('foo')
|
20
|
+
logger.error('bar')
|
21
|
+
ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data))
|
22
|
+
})
|
23
|
+
|
24
|
+
test('pino can log CRLF', async ({ ok }) => {
|
25
|
+
const stream = capture()
|
26
|
+
const logger = pino({
|
27
|
+
crlf: true
|
28
|
+
}, stream)
|
29
|
+
logger.info('foo')
|
30
|
+
logger.error('bar')
|
31
|
+
ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data))
|
32
|
+
})
|