npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pino-std-serializers

v7.0.0

Published

A collection of standard object serializers for Pino

Downloads

33,936,021

Readme

pino-std-serializers  CI

This module provides a set of standard object serializers for the Pino logger.

Serializers

exports.err(error)

Serializes an Error like object. Returns an object:

{
  type: 'string', // The name of the object's constructor.
  message: 'string', // The supplied error message.
  stack: 'string', // The stack when the error was generated.
  raw: Error  // Non-enumerable, i.e. will not be in the output, original
              // Error object. This is available for subsequent serializers
              // to use.
  [...any additional Enumerable property the original Error had]
}

Any other extra properties, e.g. statusCode, that have been attached to the object will also be present on the serialized object.

If the error object has a cause property, the cause's message and stack will be appended to the top-level message and stack. All other parameters that belong to the error.cause object will be omitted.

Example:

const serializer = require('pino-std-serializers').err;

const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;

const serialized = serializer(outerError);
/* Result:
{
  "type": "Error",
  "message": "outer error: inner error",
  "isInner": false,
  "stack": "Error: outer error
        at <...omitted..>
    caused by: Error: inner error
        at <...omitted..>
}
 */

exports.errWithCause(error)

Serializes an Error like object, including any error.cause. Returns an object:

{
  type: 'string', // The name of the object's constructor.
  message: 'string', // The supplied error message.
  stack: 'string', // The stack when the error was generated.
  cause?: Error, // If the original error had an error.cause, it will be serialized here
  raw: Error  // Non-enumerable, i.e. will not be in the output, original
              // Error object. This is available for subsequent serializers
              // to use.
  [...any additional Enumerable property the original Error had]
}

Any other extra properties, e.g. statusCode, that have been attached to the object will also be present on the serialized object.

Example:

const serializer = require('pino-std-serializers').errWithCause;

const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;

const serialized = serializer(outerError);
/* Result:
{
  "type": "Error",
  "message": "outer error",
  "isInner": false,
  "stack": "Error: outer error
    at <...omitted..>",
  "cause": {
    "type": "Error",
    "message": "inner error",
    "isInner": true,
    "stack": "Error: inner error
      at <...omitted..>"
  },
}
 */

exports.mapHttpResponse(response)

Used internally by Pino for general response logging. Returns an object:

{
  res: {}
}

Where res is the response as serialized by the standard response serializer.

exports.mapHttpRequest(request)

Used internall by Pino for general request logging. Returns an object:

{
  req: {}
}

Where req is the request as serialized by the standard request serializer.

exports.req(request)

The default request serializer. Returns an object:

{
  id: 'string', // Defaults to `undefined`, unless there is an `id` property
                // already attached to the `request` object or to the `request.info`
                // object. Attach a synchronous function
                // to the `request.id` that returns an identifier to have
                // the value filled.
  method: 'string',
  url: 'string', // the request pathname (as per req.url in core HTTP)
  query: 'object', // the request query (as per req.query in express or hapi)
  params: 'object', // the request params (as per req.params in express or hapi)
  headers: Object, // a reference to the `headers` object from the request
                   // (as per req.headers in core HTTP)
  remoteAddress: 'string',
  remotePort: Number,
  raw: Object // Non-enumerable, i.e. will not be in the output, original
              // request object. This is available for subsequent serializers
              // to use. In cases where the `request` input already has
              // a `raw` property this will replace the original `request.raw`
              // property
}

exports.res(response)

The default response serializer. Returns an object:

{
  statusCode: Number, // Response status code, will be null before headers are flushed
  headers: Object, // The headers to be sent in the response.
  raw: Object // Non-enumerable, i.e. will not be in the output, original
              // response object. This is available for subsequent serializers
              // to use.
}

exports.wrapErrorSerializer(customSerializer)

A utility method for wrapping the default error serializer. This allows custom serializers to work with the already serialized object.

The customSerializer accepts one parameter — the newly serialized error object — and returns the new (or updated) error object.

exports.wrapRequestSerializer(customSerializer)

A utility method for wrapping the default request serializer. This allows custom serializers to work with the already serialized object.

The customSerializer accepts one parameter — the newly serialized request object — and returns the new (or updated) request object.

exports.wrapResponseSerializer(customSerializer)

A utility method for wrapping the default response serializer. This allows custom serializers to work with the already serialized object.

The customSerializer accepts one parameter — the newly serialized response object — and returns the new (or updated) response object.

License

MIT License