Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pino-std-serializers' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
}
function serializeIlpReply (res: SerializedIlpResponse): SerializedIlpResponse {
if (res.raw && res.raw.fulfill) {
res['ilp-fulfillment'] = res.raw.fulfill.fulfillment.toString('hex')
}
if (res.raw && res.raw.reject) {
res['ilp-reject-code'] = res.raw.reject.code
res['ilp-reject-message'] = res.raw.reject.message
res['ilp-reject-triggered-by'] = res.raw.reject.triggeredBy
}
return res
}
export const serializers = {
req: wrapRequestSerializer(serializeIlpPrepare),
res: wrapResponseSerializer(serializeIlpReply)
}
export function createPinoMiddleware (
options?: Options,
stream?: DestinationStream
): RafikiMiddleware {
const pino = logger(options, stream)
return async function pinoLogger (
ctx: RafikiContext,
next: () => Promise
): Promise {
return pino(ctx, async () => {
// Attach the pino logger to services
ctx.services.logger = ctx.log
await next()
function serializeIlpReply (res: SerializedIlpResponse): SerializedIlpResponse {
if (res.raw && res.raw.fulfill) {
res['ilp-fulfillment'] = res.raw.fulfill.fulfillment.toString('hex')
}
if (res.raw && res.raw.reject) {
res['ilp-reject-code'] = res.raw.reject.code
res['ilp-reject-message'] = res.raw.reject.message
res['ilp-reject-triggered-by'] = res.raw.reject.triggeredBy
}
return res
}
export const serializers = {
req: wrapRequestSerializer(serializeIlpPrepare),
res: wrapResponseSerializer(serializeIlpReply)
}
export function createPinoMiddleware (
options?: Options,
stream?: DestinationStream
): RafikiMiddleware {
const pino = logger(options, stream)
return async function pinoLogger (
ctx: RafikiContext,
next: () => Promise
): Promise {
return pino(ctx, async () => {
// Attach the pino logger to services
ctx.services.logger = ctx.log
await next()
})
streamSym,
stringifySym,
stringifiersSym,
setLevelSym,
endSym,
formatOptsSym,
messageKeySym,
useLevelLabelsSym,
changeLevelNameSym,
mixinSym,
useOnlyCustomLevelsSym
} = symbols
const { epochTime, nullTime } = time
const { pid } = process
const hostname = os.hostname()
const defaultErrorSerializer = stdSerializers.err
const defaultOptions = {
level: 'info',
useLevelLabels: false,
messageKey: 'msg',
enabled: true,
prettyPrint: false,
base: { pid, hostname },
serializers: Object.assign(Object.create(null), {
err: defaultErrorSerializer
}),
timestamp: epochTime,
name: undefined,
redact: null,
customLevels: null,
changeLevelName: 'level',
useOnlyCustomLevels: false
function pinoLogger (opts, stream) {
if (opts && opts._writableState) {
stream = opts
opts = null
}
opts = opts || {}
opts.serializers = opts.serializers || {}
opts.serializers.req = serializers.wrapRequestSerializer(opts.serializers.req || serializers.req)
opts.serializers.res = serializers.wrapResponseSerializer(opts.serializers.res || serializers.res)
opts.serializers.err = serializers.wrapErrorSerializer(opts.serializers.err || serializers.err)
if (opts.useLevel && opts.customLogLevel) {
throw new Error("You can't pass 'useLevel' and 'customLogLevel' together")
}
var useLevel = opts.useLevel || 'info'
var customLogLevel = opts.customLogLevel
delete opts.useLevel
delete opts.customLogLevel
var theStream = opts.stream || stream
delete opts.stream
var autoLogging = (opts.autoLogging !== false)
delete opts.autoLogging
return logger
}
function reqIdGenFactory (func) {
if (typeof func === 'function') return func
var maxInt = 2147483647
var nextReqId = 0
return function genReqId (req) {
return req.id || (nextReqId = (nextReqId + 1) & maxInt)
}
}
module.exports = pinoLogger
module.exports.stdSerializers = {
err: serializers.err,
req: serializers.req,
res: serializers.res
}
module.exports.startTime = startTime
return logger
}
function reqIdGenFactory (func) {
if (typeof func === 'function') return func
var maxInt = 2147483647
var nextReqId = 0
return function genReqId (req) {
return req.id || (nextReqId = (nextReqId + 1) & maxInt)
}
}
module.exports = pinoLogger
module.exports.stdSerializers = {
err: serializers.err,
req: serializers.req,
res: serializers.res
}
module.exports.startTime = startTime
function pinoLogger (opts, stream) {
if (opts && opts._writableState) {
stream = opts
opts = null
}
opts = opts || {}
opts.serializers = opts.serializers || {}
opts.serializers.req = serializers.wrapRequestSerializer(opts.serializers.req || serializers.req)
opts.serializers.res = serializers.wrapResponseSerializer(opts.serializers.res || serializers.res)
opts.serializers.err = serializers.wrapErrorSerializer(opts.serializers.err || serializers.err)
if (opts.useLevel && opts.customLogLevel) {
throw new Error("You can't pass 'useLevel' and 'customLogLevel' together")
}
var useLevel = opts.useLevel || 'info'
var customLogLevel = opts.customLogLevel
delete opts.useLevel
delete opts.customLogLevel
var theStream = opts.stream || stream
delete opts.stream
var autoLogging = (opts.autoLogging !== false)
}
function reqIdGenFactory (func) {
if (typeof func === 'function') return func
var maxInt = 2147483647
var nextReqId = 0
return function genReqId (req) {
return req.id || (nextReqId = (nextReqId + 1) & maxInt)
}
}
module.exports = pinoLogger
module.exports.stdSerializers = {
err: serializers.err,
req: serializers.req,
res: serializers.res
}
module.exports.startTime = startTime
function pinoLogger (opts, stream) {
if (opts && opts._writableState) {
stream = opts
opts = null
}
opts = opts || {}
opts.serializers = opts.serializers || {}
opts.serializers.req = serializers.wrapRequestSerializer(opts.serializers.req || serializers.req)
opts.serializers.res = serializers.wrapResponseSerializer(opts.serializers.res || serializers.res)
opts.serializers.err = serializers.wrapErrorSerializer(opts.serializers.err || serializers.err)
if (opts.useLevel && opts.customLogLevel) {
throw new Error("You can't pass 'useLevel' and 'customLogLevel' together")
}
var useLevel = opts.useLevel || 'info'
var customLogLevel = opts.customLogLevel
delete opts.useLevel
delete opts.customLogLevel
var theStream = opts.stream || stream
delete opts.stream
var autoLogging = (opts.autoLogging !== false)
delete opts.autoLogging
return function LOG (o, ...n) {
if (typeof o === 'object' && o !== null) {
if (o.method && o.headers && o.socket) {
o = mapHttpRequest(o)
} else if (typeof o.setHeader === 'function') {
o = mapHttpResponse(o)
}
this[writeSym](o, format(null, n, this[formatOptsSym]), z)
} else this[writeSym](null, format(o, n, this[formatOptsSym]), z)
}
}