pino-v2-sdk.diff

Creato Il diff non scade mai
43 rimozioni
427 linee
4 aggiunte
391 linee
'use strict'
'use strict'


/* eslint no-prototype-builtins: 0 */
/* eslint no-prototype-builtins: 0 */


const diagChan = require('node:diagnostics_channel')
const format = require('quick-format-unescaped')
const format = require('quick-format-unescaped')
const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers')
const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers')
const SonicBoom = require('sonic-boom')
const SonicBoom = require('sonic-boom')
const onExit = require('on-exit-leak-free')
const onExit = require('on-exit-leak-free')
const {
const {
lsCacheSym,
lsCacheSym,
chindingsSym,
chindingsSym,
writeSym,
writeSym,
serializersSym,
serializersSym,
formatOptsSym,
formatOptsSym,
endSym,
endSym,
stringifiersSym,
stringifiersSym,
stringifySym,
stringifySym,
stringifySafeSym,
stringifySafeSym,
wildcardFirstSym,
wildcardFirstSym,
nestedKeySym,
nestedKeySym,
formattersSym,
formattersSym,
messageKeySym,
messageKeySym,
errorKeySym,
errorKeySym,
nestedKeyStrSym,
nestedKeyStrSym,
msgPrefixSym
msgPrefixSym
} = require('./symbols')
} = require('./symbols')
const { isMainThread } = require('worker_threads')
const { isMainThread } = require('worker_threads')
const transport = require('./transport')
const transport = require('./transport')
const [nodeMajor] = process.versions.node.split('.').map(v => Number(v))

const asJsonChan = diagChan.tracingChannel('pino_asJson')

// JSON.stringify is faster in node 25+.
const asString = nodeMajor >= 25 ? str => JSON.stringify(str) : _asString


function noop () {
function noop () {
}
}


function genLog (level, hook) {
function genLog (level, hook) {
if (!hook) return LOG
if (!hook) return LOG


return function hookWrappedLog (...args) {
return function hookWrappedLog (...args) {
hook.call(this, args, LOG, level)
hook.call(this, args, LOG, level)
}
}


function LOG (o, ...n) {
function LOG (o, ...n) {
if (typeof o === 'object') {
if (typeof o === 'object') {
let msg = o
let msg = o
if (o !== null) {
if (o !== null) {
if (o.method && o.headers && o.socket) {
if (o.method && o.headers && o.socket) {
o = mapHttpRequest(o)
o = mapHttpRequest(o)
} else if (typeof o.setHeader === 'function') {
} else if (typeof o.setHeader === 'function') {
o = mapHttpResponse(o)
o = mapHttpResponse(o)
}
}
}
}
let formatParams
let formatParams
if (msg === null && n.length === 0) {
if (msg === null && n.length === 0) {
formatParams = [null]
formatParams = [null]
} else {
} else {
msg = n.shift()
msg = n.shift()
formatParams = n
formatParams = n
}
}
// We do not use a coercive check for `msg` as it is
// We do not use a coercive check for `msg` as it is
// measurably slower than the explicit checks.
// measurably slower than the explicit checks.
if (typeof this[msgPrefixSym] === 'string' && msg !== undefined && msg !== null) {
if (typeof this[msgPrefixSym] === 'string' && msg !== undefined && msg !== null) {
msg = this[msgPrefixSym] + msg
msg = this[msgPrefixSym] + msg
}
}
this[writeSym](o, format(msg, formatParams, this[formatOptsSym]), level)
this[writeSym](o, format(msg, formatParams, this[formatOptsSym]), level)
} else {
} else {
let msg = o === undefined ? n.shift() : o
let msg = o === undefined ? n.shift() : o


// We do not use a coercive check for `msg` as it is
// We do not use a coercive check for `msg` as it is
// measurably slower than the explicit checks.
// measurably slower than the explicit checks.
if (typeof this[msgPrefixSym] === 'string' && msg !== undefined && msg !== null) {
if (typeof this[msgPrefixSym] === 'string' && msg !== undefined && msg !== null) {
msg = this[msgPrefixSym] + msg
msg = this[msgPrefixSym] + msg
}
}
this[writeSym](null, format(msg, n, this[formatOptsSym]), level)
this[writeSym](null, format(msg, n, this[formatOptsSym]), level)
}
}
}
}
}
}


// magically escape strings for json
// magically escape strings for json
// relying on their charCodeAt
// relying on their charCodeAt
// everything below 32 needs JSON.stringify()
// everything below 32 needs JSON.stringify()
// 34 and 92 happens all the time, so we
// 34 and 92 happens all the time, so we
// have a fast case for them
// have a fast case for them
function _asString (str) {
function asString (str) {
let result = ''
let result = ''
let last = 0
let last = 0
let found = false
let found = false
let point = 255
let point = 255
const l = str.length
const l = str.length
if (l > 100) {
if (l > 100) {
return JSON.stringify(str)
return JSON.stringify(str)
}
}
for (var i = 0; i < l && point >= 32; i++) {
for (var i = 0; i < l && point >= 32; i++) {
point = str.charCodeAt(i)
point = str.charCodeAt(i)
if (point === 34 || point === 92) {
if (point === 34 || point === 92) {
result += str.slice(last, i) + '\\'
result += str.slice(last, i) + '\\'