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.
Files changed (196) hide show
  1. package/.nojekyll +0 -0
  2. package/.prettierignore +1 -0
  3. package/CNAME +1 -0
  4. package/CONTRIBUTING.md +30 -0
  5. package/LICENSE +21 -0
  6. package/README.md +175 -0
  7. package/SECURITY.md +87 -0
  8. package/benchmarks/basic.bench.js +95 -0
  9. package/benchmarks/child-child.bench.js +52 -0
  10. package/benchmarks/child-creation.bench.js +73 -0
  11. package/benchmarks/child.bench.js +62 -0
  12. package/benchmarks/deep-object.bench.js +88 -0
  13. package/benchmarks/formatters.bench.js +50 -0
  14. package/benchmarks/internal/custom-levels.js +67 -0
  15. package/benchmarks/internal/just-pino-heavy.bench.js +76 -0
  16. package/benchmarks/internal/just-pino.bench.js +182 -0
  17. package/benchmarks/internal/parent-vs-child.bench.js +75 -0
  18. package/benchmarks/internal/redact.bench.js +86 -0
  19. package/benchmarks/long-string.bench.js +81 -0
  20. package/benchmarks/multi-arg.bench.js +193 -0
  21. package/benchmarks/multistream.js +98 -0
  22. package/benchmarks/object.bench.js +82 -0
  23. package/benchmarks/utils/generate-benchmark-doc.js +36 -0
  24. package/benchmarks/utils/runbench.js +138 -0
  25. package/benchmarks/utils/wrap-log-level.js +55 -0
  26. package/bin.js +6 -0
  27. package/browser.js +547 -0
  28. package/build/sync-version.js +25 -0
  29. package/docs/api.md +1593 -0
  30. package/docs/asynchronous.md +40 -0
  31. package/docs/benchmarks.md +55 -0
  32. package/docs/browser.md +278 -0
  33. package/docs/bundling.md +40 -0
  34. package/docs/child-loggers.md +95 -0
  35. package/docs/diagnostics.md +16 -0
  36. package/docs/ecosystem.md +86 -0
  37. package/docs/help.md +345 -0
  38. package/docs/lts.md +64 -0
  39. package/docs/pretty.md +35 -0
  40. package/docs/redaction.md +135 -0
  41. package/docs/transports.md +1376 -0
  42. package/docs/web.md +309 -0
  43. package/eslint.config.js +28 -0
  44. package/examples/basic.js +43 -0
  45. package/examples/transport.js +68 -0
  46. package/favicon.ico +0 -0
  47. package/file.js +12 -0
  48. package/inc-version.sh +42 -0
  49. package/index.html +55 -0
  50. package/lib/caller.js +30 -0
  51. package/lib/constants.js +28 -0
  52. package/lib/contract.js +8 -0
  53. package/lib/deprecations.js +8 -0
  54. package/lib/levels.js +241 -0
  55. package/lib/meta.js +3 -0
  56. package/lib/multistream.js +203 -0
  57. package/lib/proto.js +256 -0
  58. package/lib/redaction.js +114 -0
  59. package/lib/symbols.js +74 -0
  60. package/lib/time.js +39 -0
  61. package/lib/tools.js +427 -0
  62. package/lib/transport-stream.js +56 -0
  63. package/lib/transport.js +289 -0
  64. package/lib/worker.js +194 -0
  65. package/package.json +119 -0
  66. package/pino.d.ts +908 -0
  67. package/pino.js +240 -0
  68. package/test/basic.test.js +886 -0
  69. package/test/broken-pipe.test.js +59 -0
  70. package/test/browser-child.test.js +132 -0
  71. package/test/browser-disabled.test.js +87 -0
  72. package/test/browser-early-console-freeze.test.js +12 -0
  73. package/test/browser-is-level-enabled.test.js +101 -0
  74. package/test/browser-levels.test.js +241 -0
  75. package/test/browser-serializers.test.js +352 -0
  76. package/test/browser-timestamp.test.js +88 -0
  77. package/test/browser-transmit.test.js +417 -0
  78. package/test/browser.test.js +698 -0
  79. package/test/complex-objects.test.js +36 -0
  80. package/test/crlf.test.js +34 -0
  81. package/test/custom-levels.test.js +267 -0
  82. package/test/diagnostics.test.js +107 -0
  83. package/test/error-key.test.js +37 -0
  84. package/test/error.test.js +403 -0
  85. package/test/escaping.test.js +93 -0
  86. package/test/esm/esm.mjs +14 -0
  87. package/test/esm/index.test.js +21 -0
  88. package/test/esm/named-exports.mjs +29 -0
  89. package/test/exit.test.js +79 -0
  90. package/test/fixtures/broken-pipe/basic.js +9 -0
  91. package/test/fixtures/broken-pipe/destination.js +10 -0
  92. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  93. package/test/fixtures/console-transport.js +13 -0
  94. package/test/fixtures/crashing-transport.js +13 -0
  95. package/test/fixtures/default-exit.js +8 -0
  96. package/test/fixtures/destination-exit.js +8 -0
  97. package/test/fixtures/eval/index.js +13 -0
  98. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  99. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  100. package/test/fixtures/eval/node_modules/file1.js +5 -0
  101. package/test/fixtures/eval/node_modules/file10.js +5 -0
  102. package/test/fixtures/eval/node_modules/file11.js +5 -0
  103. package/test/fixtures/eval/node_modules/file12.js +5 -0
  104. package/test/fixtures/eval/node_modules/file13.js +5 -0
  105. package/test/fixtures/eval/node_modules/file14.js +11 -0
  106. package/test/fixtures/eval/node_modules/file2.js +5 -0
  107. package/test/fixtures/eval/node_modules/file3.js +5 -0
  108. package/test/fixtures/eval/node_modules/file4.js +5 -0
  109. package/test/fixtures/eval/node_modules/file5.js +5 -0
  110. package/test/fixtures/eval/node_modules/file6.js +5 -0
  111. package/test/fixtures/eval/node_modules/file7.js +5 -0
  112. package/test/fixtures/eval/node_modules/file8.js +5 -0
  113. package/test/fixtures/eval/node_modules/file9.js +5 -0
  114. package/test/fixtures/noop-transport.js +10 -0
  115. package/test/fixtures/pretty/null-prototype.js +8 -0
  116. package/test/fixtures/stdout-hack-protection.js +11 -0
  117. package/test/fixtures/syncfalse-child.js +6 -0
  118. package/test/fixtures/syncfalse-exit.js +9 -0
  119. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  120. package/test/fixtures/syncfalse.js +6 -0
  121. package/test/fixtures/syntax-error-esm.mjs +2 -0
  122. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  123. package/test/fixtures/to-file-transport.js +13 -0
  124. package/test/fixtures/to-file-transport.mjs +8 -0
  125. package/test/fixtures/transport/index.js +12 -0
  126. package/test/fixtures/transport/package.json +5 -0
  127. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  128. package/test/fixtures/transport-exit-immediately.js +11 -0
  129. package/test/fixtures/transport-exit-on-ready.js +12 -0
  130. package/test/fixtures/transport-invalid-node-options.js +26 -0
  131. package/test/fixtures/transport-main.js +9 -0
  132. package/test/fixtures/transport-many-lines.js +29 -0
  133. package/test/fixtures/transport-preload-main.mjs +13 -0
  134. package/test/fixtures/transport-preload.mjs +13 -0
  135. package/test/fixtures/transport-string-stdout.js +9 -0
  136. package/test/fixtures/transport-transform.js +21 -0
  137. package/test/fixtures/transport-uses-pino-config.js +33 -0
  138. package/test/fixtures/transport-with-on-exit.js +12 -0
  139. package/test/fixtures/transport-worker-data.js +19 -0
  140. package/test/fixtures/transport-worker-name.js +24 -0
  141. package/test/fixtures/transport-worker.js +15 -0
  142. package/test/fixtures/transport-wrong-export-type.js +3 -0
  143. package/test/fixtures/ts/to-file-transport-native.mts +15 -0
  144. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  145. package/test/fixtures/ts/to-file-transport.ts +11 -0
  146. package/test/fixtures/ts/transpile.cjs +36 -0
  147. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  148. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  149. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  150. package/test/fixtures/ts/transport-main.ts +8 -0
  151. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  152. package/test/fixtures/ts/transport-worker.ts +14 -0
  153. package/test/formatters.test.js +364 -0
  154. package/test/helper.d.ts +4 -0
  155. package/test/helper.js +155 -0
  156. package/test/hooks.test.js +114 -0
  157. package/test/http.test.js +214 -0
  158. package/test/internals/version.test.js +17 -0
  159. package/test/is-level-enabled.test.js +179 -0
  160. package/test/jest/basic.spec.js +10 -0
  161. package/test/levels.test.js +810 -0
  162. package/test/metadata.test.js +120 -0
  163. package/test/mixin-merge-strategy.test.js +57 -0
  164. package/test/mixin.test.js +241 -0
  165. package/test/multistream.test.js +729 -0
  166. package/test/redact.test.js +893 -0
  167. package/test/serializers.test.js +257 -0
  168. package/test/stdout-protection.test.js +41 -0
  169. package/test/syncfalse.test.js +186 -0
  170. package/test/timestamp-nano.test.js +37 -0
  171. package/test/timestamp.test.js +124 -0
  172. package/test/transport/big.test.js +42 -0
  173. package/test/transport/bundlers-support.test.js +99 -0
  174. package/test/transport/caller.test.js +24 -0
  175. package/test/transport/core.test.js +733 -0
  176. package/test/transport/core.transpiled.test.ts +114 -0
  177. package/test/transport/crash.test.js +36 -0
  178. package/test/transport/module-link.test.js +241 -0
  179. package/test/transport/native-type-stripping.test.mjs +151 -0
  180. package/test/transport/node-options.test.js +116 -0
  181. package/test/transport/pipeline.test.js +137 -0
  182. package/test/transport/preload.test.js +54 -0
  183. package/test/transport/repl.test.js +15 -0
  184. package/test/transport/sync-false.test.js +67 -0
  185. package/test/transport/sync-true.test.js +57 -0
  186. package/test/transport/targets.test.js +48 -0
  187. package/test/transport/uses-pino-config.test.js +166 -0
  188. package/test/transport-stream.test.js +40 -0
  189. package/test/types/pino-import.test-d.cts +30 -0
  190. package/test/types/pino-multistream.test-d.ts +28 -0
  191. package/test/types/pino-top-export.test-d.ts +34 -0
  192. package/test/types/pino-transport.test-d.ts +156 -0
  193. package/test/types/pino-type-only.test-d.ts +75 -0
  194. package/test/types/pino.test-d.ts +683 -0
  195. package/test/types/pino.ts +91 -0
  196. package/tsconfig.json +14 -0
package/browser.js ADDED
@@ -0,0 +1,547 @@
1
+ 'use strict'
2
+
3
+ const format = require('quick-format-unescaped')
4
+
5
+ module.exports = pino
6
+
7
+ const _console = pfGlobalThisOrFallback().console || {}
8
+ const stdSerializers = {
9
+ mapHttpRequest: mock,
10
+ mapHttpResponse: mock,
11
+ wrapRequestSerializer: passthrough,
12
+ wrapResponseSerializer: passthrough,
13
+ wrapErrorSerializer: passthrough,
14
+ req: mock,
15
+ res: mock,
16
+ err: asErrValue,
17
+ errWithCause: asErrValue
18
+ }
19
+ function levelToValue (level, logger) {
20
+ return level === 'silent'
21
+ ? Infinity
22
+ : logger.levels.values[level]
23
+ }
24
+ const baseLogFunctionSymbol = Symbol('pino.logFuncs')
25
+ const hierarchySymbol = Symbol('pino.hierarchy')
26
+
27
+ const logFallbackMap = {
28
+ error: 'log',
29
+ fatal: 'error',
30
+ warn: 'error',
31
+ info: 'log',
32
+ debug: 'log',
33
+ trace: 'log'
34
+ }
35
+
36
+ function appendChildLogger (parentLogger, childLogger) {
37
+ const newEntry = {
38
+ logger: childLogger,
39
+ parent: parentLogger[hierarchySymbol]
40
+ }
41
+ childLogger[hierarchySymbol] = newEntry
42
+ }
43
+
44
+ function setupBaseLogFunctions (logger, levels, proto) {
45
+ const logFunctions = {}
46
+ levels.forEach(level => {
47
+ logFunctions[level] = proto[level] ? proto[level] : (_console[level] || _console[logFallbackMap[level] || 'log'] || noop)
48
+ })
49
+ logger[baseLogFunctionSymbol] = logFunctions
50
+ }
51
+
52
+ function shouldSerialize (serialize, serializers) {
53
+ if (Array.isArray(serialize)) {
54
+ const hasToFilter = serialize.filter(function (k) {
55
+ return k !== '!stdSerializers.err'
56
+ })
57
+ return hasToFilter
58
+ } else if (serialize === true) {
59
+ return Object.keys(serializers)
60
+ }
61
+
62
+ return false
63
+ }
64
+
65
+ function pino (opts) {
66
+ opts = opts || {}
67
+ opts.browser = opts.browser || {}
68
+
69
+ const transmit = opts.browser.transmit
70
+ if (transmit && typeof transmit.send !== 'function') { throw Error('pino: transmit option must have a send function') }
71
+
72
+ const proto = opts.browser.write || _console
73
+ if (opts.browser.write) opts.browser.asObject = true
74
+ const serializers = opts.serializers || {}
75
+ const serialize = shouldSerialize(opts.browser.serialize, serializers)
76
+ let stdErrSerialize = opts.browser.serialize
77
+
78
+ if (
79
+ Array.isArray(opts.browser.serialize) &&
80
+ opts.browser.serialize.indexOf('!stdSerializers.err') > -1
81
+ ) stdErrSerialize = false
82
+
83
+ const customLevels = Object.keys(opts.customLevels || {})
84
+ const levels = ['error', 'fatal', 'warn', 'info', 'debug', 'trace'].concat(customLevels)
85
+
86
+ if (typeof proto === 'function') {
87
+ levels.forEach(function (level) {
88
+ proto[level] = proto
89
+ })
90
+ }
91
+ if (opts.enabled === false || opts.browser.disabled) opts.level = 'silent'
92
+ const level = opts.level || 'info'
93
+ const logger = Object.create(proto)
94
+ if (!logger.log) logger.log = noop
95
+
96
+ setupBaseLogFunctions(logger, levels, proto)
97
+ // setup root hierarchy entry
98
+ appendChildLogger({}, logger)
99
+
100
+ Object.defineProperty(logger, 'levelVal', {
101
+ get: getLevelVal
102
+ })
103
+ Object.defineProperty(logger, 'level', {
104
+ get: getLevel,
105
+ set: setLevel
106
+ })
107
+
108
+ const setOpts = {
109
+ transmit,
110
+ serialize,
111
+ asObject: opts.browser.asObject,
112
+ asObjectBindingsOnly: opts.browser.asObjectBindingsOnly,
113
+ formatters: opts.browser.formatters,
114
+ reportCaller: opts.browser.reportCaller,
115
+ levels,
116
+ timestamp: getTimeFunction(opts),
117
+ messageKey: opts.messageKey || 'msg',
118
+ onChild: opts.onChild || noop
119
+ }
120
+ logger.levels = getLevels(opts)
121
+ logger.level = level
122
+
123
+ logger.isLevelEnabled = function (level) {
124
+ if (!this.levels.values[level]) {
125
+ return false
126
+ }
127
+
128
+ return this.levels.values[level] >= this.levels.values[this.level]
129
+ }
130
+ logger.setMaxListeners = logger.getMaxListeners =
131
+ logger.emit = logger.addListener = logger.on =
132
+ logger.prependListener = logger.once =
133
+ logger.prependOnceListener = logger.removeListener =
134
+ logger.removeAllListeners = logger.listeners =
135
+ logger.listenerCount = logger.eventNames =
136
+ logger.write = logger.flush = noop
137
+ logger.serializers = serializers
138
+ logger._serialize = serialize
139
+ logger._stdErrSerialize = stdErrSerialize
140
+ logger.child = function (...args) { return child.call(this, setOpts, ...args) }
141
+
142
+ if (transmit) logger._logEvent = createLogEventShape()
143
+
144
+ function getLevelVal () {
145
+ return levelToValue(this.level, this)
146
+ }
147
+
148
+ function getLevel () {
149
+ return this._level
150
+ }
151
+ function setLevel (level) {
152
+ if (level !== 'silent' && !this.levels.values[level]) {
153
+ throw Error('unknown level ' + level)
154
+ }
155
+ this._level = level
156
+
157
+ set(this, setOpts, logger, 'error') // <-- must stay first
158
+ set(this, setOpts, logger, 'fatal')
159
+ set(this, setOpts, logger, 'warn')
160
+ set(this, setOpts, logger, 'info')
161
+ set(this, setOpts, logger, 'debug')
162
+ set(this, setOpts, logger, 'trace')
163
+
164
+ customLevels.forEach((level) => {
165
+ set(this, setOpts, logger, level)
166
+ })
167
+ }
168
+
169
+ function child (setOpts, bindings, childOptions) {
170
+ if (!bindings) {
171
+ throw new Error('missing bindings for child Pino')
172
+ }
173
+ childOptions = childOptions || {}
174
+ if (serialize && bindings.serializers) {
175
+ childOptions.serializers = bindings.serializers
176
+ }
177
+ const childOptionsSerializers = childOptions.serializers
178
+ if (serialize && childOptionsSerializers) {
179
+ var childSerializers = Object.assign({}, serializers, childOptionsSerializers)
180
+ var childSerialize = opts.browser.serialize === true
181
+ ? Object.keys(childSerializers)
182
+ : serialize
183
+ delete bindings.serializers
184
+ applySerializers([bindings], childSerialize, childSerializers, this._stdErrSerialize)
185
+ }
186
+ function Child (parent) {
187
+ this._childLevel = (parent._childLevel | 0) + 1
188
+
189
+ // make sure bindings are available in the `set` function
190
+ this.bindings = bindings
191
+
192
+ if (childSerializers) {
193
+ this.serializers = childSerializers
194
+ this._serialize = childSerialize
195
+ }
196
+ if (transmit) {
197
+ this._logEvent = createLogEventShape(
198
+ [].concat(parent._logEvent.bindings, bindings)
199
+ )
200
+ }
201
+ }
202
+ Child.prototype = this
203
+ const newLogger = new Child(this)
204
+
205
+ // must happen before the level is assigned
206
+ appendChildLogger(this, newLogger)
207
+ newLogger.child = function (...args) { return child.call(this, setOpts, ...args) }
208
+ // required to actually initialize the logger functions for any given child
209
+ newLogger.level = childOptions.level || this.level // allow level to be set by childOptions
210
+ setOpts.onChild(newLogger)
211
+
212
+ return newLogger
213
+ }
214
+ return logger
215
+ }
216
+
217
+ function getLevels (opts) {
218
+ const customLevels = opts.customLevels || {}
219
+
220
+ const values = Object.assign({}, pino.levels.values, customLevels)
221
+ const labels = Object.assign({}, pino.levels.labels, invertObject(customLevels))
222
+
223
+ return {
224
+ values,
225
+ labels
226
+ }
227
+ }
228
+
229
+ function invertObject (obj) {
230
+ const inverted = {}
231
+ Object.keys(obj).forEach(function (key) {
232
+ inverted[obj[key]] = key
233
+ })
234
+ return inverted
235
+ }
236
+
237
+ pino.levels = {
238
+ values: {
239
+ fatal: 60,
240
+ error: 50,
241
+ warn: 40,
242
+ info: 30,
243
+ debug: 20,
244
+ trace: 10
245
+ },
246
+ labels: {
247
+ 10: 'trace',
248
+ 20: 'debug',
249
+ 30: 'info',
250
+ 40: 'warn',
251
+ 50: 'error',
252
+ 60: 'fatal'
253
+ }
254
+ }
255
+
256
+ pino.stdSerializers = stdSerializers
257
+ pino.stdTimeFunctions = Object.assign({}, { nullTime, epochTime, unixTime, isoTime })
258
+
259
+ function getBindingChain (logger) {
260
+ const bindings = []
261
+ if (logger.bindings) {
262
+ bindings.push(logger.bindings)
263
+ }
264
+
265
+ // traverse up the tree to get all bindings
266
+ let hierarchy = logger[hierarchySymbol]
267
+ while (hierarchy.parent) {
268
+ hierarchy = hierarchy.parent
269
+ if (hierarchy.logger.bindings) {
270
+ bindings.push(hierarchy.logger.bindings)
271
+ }
272
+ }
273
+
274
+ return bindings.reverse()
275
+ }
276
+
277
+ function set (self, opts, rootLogger, level) {
278
+ // override the current log functions with either `noop` or the base log function
279
+ Object.defineProperty(self, level, {
280
+ value: (levelToValue(self.level, rootLogger) > levelToValue(level, rootLogger)
281
+ ? noop
282
+ : rootLogger[baseLogFunctionSymbol][level]),
283
+ writable: true,
284
+ enumerable: true,
285
+ configurable: true
286
+ })
287
+
288
+ if (self[level] === noop) {
289
+ if (!opts.transmit) return
290
+
291
+ const transmitLevel = opts.transmit.level || self.level
292
+ const transmitValue = levelToValue(transmitLevel, rootLogger)
293
+ const methodValue = levelToValue(level, rootLogger)
294
+ if (methodValue < transmitValue) return
295
+ }
296
+
297
+ // make sure the log format is correct
298
+ self[level] = createWrap(self, opts, rootLogger, level)
299
+
300
+ // prepend bindings if it is not the root logger
301
+ const bindings = getBindingChain(self)
302
+ if (bindings.length === 0) {
303
+ // early exit in case for rootLogger
304
+ return
305
+ }
306
+ self[level] = prependBindingsInArguments(bindings, self[level])
307
+ }
308
+
309
+ function prependBindingsInArguments (bindings, logFunc) {
310
+ return function () {
311
+ return logFunc.apply(this, [...bindings, ...arguments])
312
+ }
313
+ }
314
+
315
+ function createWrap (self, opts, rootLogger, level) {
316
+ return (function (write) {
317
+ return function LOG () {
318
+ const ts = opts.timestamp()
319
+ const args = new Array(arguments.length)
320
+ const proto = (Object.getPrototypeOf && Object.getPrototypeOf(this) === _console) ? _console : this
321
+ for (var i = 0; i < args.length; i++) args[i] = arguments[i]
322
+
323
+ var argsIsSerialized = false
324
+ if (opts.serialize) {
325
+ applySerializers(args, this._serialize, this.serializers, this._stdErrSerialize)
326
+ argsIsSerialized = true
327
+ }
328
+ if (opts.asObject || opts.formatters) {
329
+ const out = asObject(this, level, args, ts, opts)
330
+ if (opts.reportCaller && out && out.length > 0 && out[0] && typeof out[0] === 'object') {
331
+ try {
332
+ const caller = getCallerLocation()
333
+ if (caller) out[0].caller = caller
334
+ } catch (e) {}
335
+ }
336
+ write.call(proto, ...out)
337
+ } else {
338
+ if (opts.reportCaller) {
339
+ try {
340
+ const caller = getCallerLocation()
341
+ if (caller) args.push(caller)
342
+ } catch (e) {}
343
+ }
344
+ write.apply(proto, args)
345
+ }
346
+
347
+ if (opts.transmit) {
348
+ const transmitLevel = opts.transmit.level || self._level
349
+ const transmitValue = levelToValue(transmitLevel, rootLogger)
350
+ const methodValue = levelToValue(level, rootLogger)
351
+ if (methodValue < transmitValue) return
352
+ transmit(this, {
353
+ ts,
354
+ methodLevel: level,
355
+ methodValue,
356
+ transmitLevel,
357
+ transmitValue: rootLogger.levels.values[opts.transmit.level || self._level],
358
+ send: opts.transmit.send,
359
+ val: levelToValue(self._level, rootLogger)
360
+ }, args, argsIsSerialized)
361
+ }
362
+ }
363
+ })(self[baseLogFunctionSymbol][level])
364
+ }
365
+
366
+ function asObject (logger, level, args, ts, opts) {
367
+ const {
368
+ level: levelFormatter,
369
+ log: logObjectFormatter = (obj) => obj
370
+ } = opts.formatters || {}
371
+ const argsCloned = args.slice()
372
+ let msg = argsCloned[0]
373
+ const logObject = {}
374
+
375
+ let lvl = (logger._childLevel | 0) + 1
376
+ if (lvl < 1) lvl = 1
377
+
378
+ if (ts) {
379
+ logObject.time = ts
380
+ }
381
+
382
+ if (levelFormatter) {
383
+ const formattedLevel = levelFormatter(level, logger.levels.values[level])
384
+ Object.assign(logObject, formattedLevel)
385
+ } else {
386
+ logObject.level = logger.levels.values[level]
387
+ }
388
+
389
+ if (opts.asObjectBindingsOnly) {
390
+ if (msg !== null && typeof msg === 'object') {
391
+ while (lvl-- && typeof argsCloned[0] === 'object') {
392
+ Object.assign(logObject, argsCloned.shift())
393
+ }
394
+ }
395
+
396
+ const formattedLogObject = logObjectFormatter(logObject)
397
+ return [formattedLogObject, ...argsCloned]
398
+ } else {
399
+ // deliberate, catching objects, arrays
400
+ if (msg !== null && typeof msg === 'object') {
401
+ while (lvl-- && typeof argsCloned[0] === 'object') {
402
+ Object.assign(logObject, argsCloned.shift())
403
+ }
404
+ msg = argsCloned.length ? format(argsCloned.shift(), argsCloned) : undefined
405
+ } else if (typeof msg === 'string') msg = format(argsCloned.shift(), argsCloned)
406
+ if (msg !== undefined) logObject[opts.messageKey] = msg
407
+
408
+ const formattedLogObject = logObjectFormatter(logObject)
409
+ return [formattedLogObject]
410
+ }
411
+ }
412
+
413
+ function applySerializers (args, serialize, serializers, stdErrSerialize) {
414
+ for (const i in args) {
415
+ if (stdErrSerialize && args[i] instanceof Error) {
416
+ args[i] = pino.stdSerializers.err(args[i])
417
+ } else if (typeof args[i] === 'object' && !Array.isArray(args[i]) && serialize) {
418
+ for (const k in args[i]) {
419
+ if (serialize.indexOf(k) > -1 && k in serializers) {
420
+ args[i][k] = serializers[k](args[i][k])
421
+ }
422
+ }
423
+ }
424
+ }
425
+ }
426
+
427
+ function transmit (logger, opts, args, argsIsSerialized = false) {
428
+ const send = opts.send
429
+ const ts = opts.ts
430
+ const methodLevel = opts.methodLevel
431
+ const methodValue = opts.methodValue
432
+ const val = opts.val
433
+ const bindings = logger._logEvent.bindings
434
+
435
+ if (!argsIsSerialized) {
436
+ applySerializers(
437
+ args,
438
+ logger._serialize || Object.keys(logger.serializers),
439
+ logger.serializers,
440
+ logger._stdErrSerialize === undefined ? true : logger._stdErrSerialize
441
+ )
442
+ }
443
+
444
+ logger._logEvent.ts = ts
445
+ logger._logEvent.messages = args.filter(function (arg) {
446
+ // bindings can only be objects, so reference equality check via indexOf is fine
447
+ return bindings.indexOf(arg) === -1
448
+ })
449
+
450
+ logger._logEvent.level.label = methodLevel
451
+ logger._logEvent.level.value = methodValue
452
+
453
+ send(methodLevel, logger._logEvent, val)
454
+
455
+ logger._logEvent = createLogEventShape(bindings)
456
+ }
457
+
458
+ function createLogEventShape (bindings) {
459
+ return {
460
+ ts: 0,
461
+ messages: [],
462
+ bindings: bindings || [],
463
+ level: { label: '', value: 0 }
464
+ }
465
+ }
466
+
467
+ function asErrValue (err) {
468
+ const obj = {
469
+ type: err.constructor.name,
470
+ msg: err.message,
471
+ stack: err.stack
472
+ }
473
+ for (const key in err) {
474
+ if (obj[key] === undefined) {
475
+ obj[key] = err[key]
476
+ }
477
+ }
478
+ return obj
479
+ }
480
+
481
+ function getTimeFunction (opts) {
482
+ if (typeof opts.timestamp === 'function') {
483
+ return opts.timestamp
484
+ }
485
+ if (opts.timestamp === false) {
486
+ return nullTime
487
+ }
488
+ return epochTime
489
+ }
490
+
491
+ function mock () { return {} }
492
+ function passthrough (a) { return a }
493
+ function noop () {}
494
+
495
+ function nullTime () { return false }
496
+ function epochTime () { return Date.now() }
497
+ function unixTime () { return Math.round(Date.now() / 1000.0) }
498
+ function isoTime () { return new Date(Date.now()).toISOString() } // using Date.now() for testability
499
+
500
+ /* eslint-disable */
501
+ /* istanbul ignore next */
502
+ function pfGlobalThisOrFallback () {
503
+ function defd (o) { return typeof o !== 'undefined' && o }
504
+ try {
505
+ if (typeof globalThis !== 'undefined') return globalThis
506
+ Object.defineProperty(Object.prototype, 'globalThis', {
507
+ get: function () {
508
+ delete Object.prototype.globalThis
509
+ return (this.globalThis = this)
510
+ },
511
+ configurable: true
512
+ })
513
+ return globalThis
514
+ } catch (e) {
515
+ return defd(self) || defd(window) || defd(this) || {}
516
+ }
517
+ }
518
+ /* eslint-enable */
519
+
520
+ module.exports.default = pino
521
+ module.exports.pino = pino
522
+
523
+ // Attempt to extract the user callsite (file:line:column)
524
+ /* istanbul ignore next */
525
+ function getCallerLocation () {
526
+ const stack = (new Error()).stack
527
+ if (!stack) return null
528
+ const lines = stack.split('\n')
529
+ for (let i = 1; i < lines.length; i++) {
530
+ const l = lines[i].trim()
531
+ // skip frames from this file and internals
532
+ if (/(^at\s+)?(createWrap|LOG|set\s*\(|asObject|Object\.apply|Function\.apply)/.test(l)) continue
533
+ if (l.indexOf('browser.js') !== -1) continue
534
+ if (l.indexOf('node:internal') !== -1) continue
535
+ if (l.indexOf('node_modules') !== -1) continue
536
+ // try formats like: at func (file:line:col) or at file:line:col
537
+ let m = l.match(/\((.*?):(\d+):(\d+)\)/)
538
+ if (!m) m = l.match(/at\s+(.*?):(\d+):(\d+)/)
539
+ if (m) {
540
+ const file = m[1]
541
+ const line = m[2]
542
+ const col = m[3]
543
+ return file + ':' + line + ':' + col
544
+ }
545
+ }
546
+ return null
547
+ }
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ const fs = require('node:fs')
4
+ const path = require('node:path')
5
+ let { version } = require('../package.json')
6
+
7
+ let passedVersion = process.argv[2]
8
+
9
+ if (passedVersion) {
10
+ passedVersion = passedVersion.trim().replace(/^v/, '')
11
+ if (version !== passedVersion) {
12
+ console.log(`Syncing version from ${version} to ${passedVersion}`)
13
+ version = passedVersion
14
+ const packageJson = require('../package.json')
15
+ packageJson.version = version
16
+ fs.writeFileSync(path.resolve('./package.json'), JSON.stringify(packageJson, null, 2) + '\n', { encoding: 'utf-8' })
17
+ }
18
+ }
19
+
20
+ const metaContent = `'use strict'
21
+
22
+ module.exports = { version: '${version}' }
23
+ `
24
+
25
+ fs.writeFileSync(path.resolve('./lib/meta.js'), metaContent, { encoding: 'utf-8' })