How to use the pino-std-serializers.wrapResponseSerializer function in pino-std-serializers

To help you get started, we’ve selected a few pino-std-serializers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github interledgerjs / rafiki / packages / rafiki-logger-pino / src / index.ts View on Github external
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()
    })
github pinojs / pino-http / logger.js View on Github external
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