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

garnish-data

v5.3.0

Published

prettifies ndjson from wzrd and similar tools - fork to show more data

Downloads

12

Readme

garnish

stable

Prettifies ndjson or bole logs from budo, wzrd and other tools.

Example with budo, which uses this under the hood.

Install

npm install garnish [-g|--save-dev]

Usage

CLI

Pipe a ndjson emitter into garnish like so:

node app.js | garnish [opts]

Options:

    --level, -l    the minimum debug level, default 'debug'
    --name, -n     the default app name

Where level can be debug, info, warn, error.

API

garnish([opt])

Returns a duplexer that parses input as ndjson, and writes a pretty-printed result. Options:

  • level (String)
    • the minimum log level to print (default 'debug')
    • the order is as follows: debug, info, warn, error
  • name (String)
    • the default name for your logger; a message's name field will not be printed when it matches this default name, to reduce redundant/obvious information in the logs.
  • showData (Boolean)
    • should fields that are not specifically handled be printed at the end of the line. Defaults to false.

format

Typically, you would use bole or ndjson to write the content to garnish. You can also write ndjson to stdout like so:

// a log message
console.log({
  name: 'myApp',
  level: 'warn',
  message: 'not found'
})

// a typical server message
console.log({
  name: 'myApp',
  type: 'generated',
  level: 'info',
  url: '/foo.png',
  statusCode: 200,
  contentLength: 12800, // in bytes
  elapsed: 120 // in milliseconds
})

Currently garnish styles the following:

  • level
    • the log level e.g. debug, info, warn, error (default debug) - only shown if message is present
  • name
    • an optional event or application name. It's recommended to always have a name.
  • message
    • an event message.
  • url
    • a url (stripped to pathname), useful for router logging.
  • statusCode
    • an HTTP statusCode. Codes >=400 are displayed in red.
  • contentLength
    • the response size; if a number, bytes are assumed
  • elapsed
    • time elapsed since the previous related event; if a number, milliseconds are assumed
  • type
    • the type of event logged
  • colors
    • an optional color mapping for custom styles

You can use the colors field to override any of the default colors with a new ANSI style.

For example, the following will print elapsed in yellow if it passes our threshold:

function logTime (msg) {
  var now = Date.now()
  var time = now - lastTime
  lastTime = now

  console.log({
    name: 'app',
    message: msg,
    elapsed: time + ' ms',
    colors: {
      elapsed: time > 1000 ? 'yellow' : 'green'
    }
  })
}

See Also

License

MIT, see LICENSE.md for details.