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

winston-error-format

v3.0.1

Published

Log errors with Winston

Downloads

7,015

Readme

Node TypeScript Codecov Minified size Mastodon Medium

Log errors with Winston.

Hire me

Please reach out if you're looking for a Node.js API or CLI engineer (11 years of experience). Most recently I have been Netlify Build's and Netlify Plugins' technical lead for 2.5 years. I am available for full-time remote positions.

Features

This provides with two Winston formats:

  • Full: includes all properties
  • Short: includes only the error's name, message and stack

Unlike Winston's default error format:

  • The error name is logged
  • The full format logs nested errors, including cause and aggregate errors
  • The full format is JSON-safe
  • The short format optionally logs the stack trace
  • The error instance is not modified

Example

Using the full format.

import { createLogger, transports, format } from 'winston'

import { fullFormat } from 'winston-error-format'

const logger = createLogger({
  format: format.combine(fullFormat(), format.json()),
  transports: [new transports.Http(httpOptions)],
})

const error = new ExampleError('Could not read file.')
error.filePath = '/...'
logger.error(error)
// Sent via HTTP:
// {
//   level: 'error',
//   name: 'ExampleError',
//   message: 'Could not read file.',
//   stack: `ExampleError: Could not read file.
//     at ...`,
//   filePath: '/...',
// }

Using the short format.

import { createLogger, transports, format } from 'winston'

import { shortFormat } from 'winston-error-format'

const logger = createLogger({
  format: format.combine(shortFormat(), format.cli()),
  transports: [new transports.Console()],
})

const error = new ExampleError('Could not read file.')
logger.error(error)
// Printed on the console:
// error: ExampleError: Could not read file.
//     at ...

Install

npm install winston-error-format

This package requires installing Winston separately.

npm install winston

This package works in Node.js >=18.18.0.

This is an ES module. It must be loaded using an import or import() statement, not require(). If TypeScript is used, it must be configured to output ES modules, not CommonJS.

API

fullFormat(options?)

options: Options
Return value: Format

Returns a logger format to combine with format.json() or format.prettyPrint(). This logs all error properties, making it useful with transports like HTTP.

Errors should be logged using logger.*(error).

shortFormat(options?)

options: Options
Return value: Format

Returns a logger format to combine with format.simple() or format.cli(). This logs only the error name, message and stack, making it useful with transports like the console.

Errors should be logged using logger.*(error).

Options

Type: object | ((Error) => object)

The options object can be error-specific by passing a function returning it instead.

stack

Type: boolean
Default: true

Whether to log the stack trace.

level

Type: string

Override the log level.

transform

Type: (Error) => Error

Maps the error before logging it.

Related projects

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!