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

semantic-pretty

v1.0.1

Published

Prettifier for Semantic Logger pretty log lines

Downloads

1

Readme

pino-pretty

Build Status Coverage Status

This module provides a basic log prettifier for the Pino logging library. It reads a standard Pino log line like:

{"level":30,"time":1522431328992,"msg":"hello world","pid":42,"hostname":"foo","v":1}

And formats it to:

[1522431328992] INFO (42 on foo): hello world

Example

Using the example script from the Pino module, and specifying that logs should be colored and the time translated, we can see what the prettified logs will look like:

demo

Install

$ npm install -g pino-pretty

Usage

It's recommended to use pino-pretty with pino by piping output to the CLI tool:

pino app.js | pino-pretty

CLI Arguments

  • --colorize (-c): Adds terminal color escape sequences to the output.
  • --crlf (-f): Appends carriage return and line feed, instead of just a line feed, to the formatted log line.
  • --errorProps (-e): When formatting an error object, display this list of properties. The list should be a comma separated list of properties Default: ''.
  • --levelFirst (-l): Display the log level name before the logged date and time.
  • --errorLikeObjectKeys (-k): Define the log keys that are associated with error like objects. Default: err,error.
  • --messageKey (-m): Define the key that contains the main log message. Default: msg.
  • --translateTime (-t): Translate the epoch time value into a human readable date and time string. This flag also can set the format string to apply when translating the date to human readable format. For a list of available pattern letters see the dateformat documentation.
    • The default format is yyyy-mm-dd HH:MM:ss.l o in UTC.
    • Require a SYS: prefix to translate time to the local system's timezone. A shortcut SYS:standard to translate time to yyyy-mm-dd HH:MM:ss.l o in system timezone.
  • --search (-s): Specifiy a search pattern according to jmespath.

Programmatic Integration

We recommend against using pino-pretty in production, and highly recommend installing pino-pretty as a development dependency.

When installed, pretty-print will be used by pino as the default prettifier.

Install pino-pretty alongside pino and set the prettyPrint option to true:

const pino = require('pino')
const logger = pino({
  prettyPrint: true
})

logger.info('hi')

The prettyPrint option can also be an object containing pretty-print options:

const pino = require('pino')
const logger = pino({
  prettyPrint: { colorize: true }
})

logger.info('hi')

See the Options section for all possible options.

Options

pino-pretty exports a factory function that can be used to format log strings. This factory function is used internally by pino, and accepts an options argument with keys corresponding to the options described in CLI Arguments:

{
  colorize: chalk.supportsColor, // --colorize
  crlf: false, // --crlf
  errorLikeObjectKeys: ['err', 'error'], // --errorLikeObjectKeys
  errorProps: '', // --errorProps
  levelFirst: false, // --levelFirst
  messageKey: 'msg', // --messageKey
  translateTime: false, // --translateTime
  search: 'foo == `bar`' // --search
}

The colorize default follows `chalk.supportsColor.

License

MIT License