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-tiny

v2.2.0

Published

a tiny little log formatter for [pino](https://github.com/pinojs/pino).

Downloads

702

Readme

pino-tiny

a tiny little log formatter for pino.

yeah, i know, pino-colada...

...but is does some weird black box stuff, and i did not like some of the formatting, and i was generally not too happy about certain things, so...

i made pino-tiny!

screen-shot

using it

pino-tiny is ran like any other pino output mangler, you run it as a process and pipe to it. first you need to install it. it's really not meant to be a production log formatter, so prolly install it in your project as a dev-dependency.

npm i -D pino-tiny
--or--
yarn add --dev pino-tiny

...run it with your application that is already using pino to log stuff...

$ node index.js | pino-tiny

CLI Arguments

Now you can tweak the output a bit with command line arguments

Options:
      --help            Show help                                      
      --version         Show version number                            
  -i, --hide-icons      Hide level emoji icons.       
  -l, --hide-letters    Hide level letters.           
  -t, --hide-timestamp  Hide the timestamp.           
  -c, --hide-colors     Remove ansi colors from output.
  -w, --hide-web        Hide web stats.               
  -m, --msg-key         The key to use for message from the JSON log data.                                               

...or put it in your package.json file...

{
  ...
  "scripts": {
    "dev": "nodemon index.js | pino-tiny",
    ...
  }
}

use it in code!

pino-tiny can be used in code too as a prettifier, if you want. here is how you set it up:

const { PinoTinyPrettifier } = require('pino-pretty')
const Pino = require('pino')

const logger = new Pino({
  prettifier: PinoTinyPrettifier(/*{[options]}*/),
  prettyPrint: true
})

logger.trace('trace message')
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.fatal('fatal message')

Prettifier Options

The prettifier has the same options as the cli. Plus a filter function.

PinoTinyOptions {
  hideIcons?: boolean
  hideLetters?: boolean
  hideTimestamp?: boolean
  hideColors?: boolean
  hideWeb?: boolean
  msgKey?: string
  filter?: (data: any) => any | undefined
}

The filter option allows you to filter and process the log data. So you can do something like

// remove ansi colors and remove messages that have secrets.
const logger = new Pino({
  prettifier: PinoTinyPrettifier(
    {
      hideColor: true,
      filter:(data) => {
        if (data.hasSecret) {
          return { ...data, msg:'*** secret ***' }
        } else {
          return data
        }
      }
    }
  ),
  prettyPrint: true
})

extensible-ish

pino-tiny runs like a process you pipe the output of your application into and it makes nice output. it also exports a function Run that takes the filter option function as a parameter.

this allows you to control if a log entry gets printed, and you can mangle the output (in the msg property of the log). here is a ridiculous example:

const { Run } = require('pino-tiny')

function filter (data) {
  if(data.msg.indexOf('happy') >= 0) { 
      // nothing happy gets out.
      return false; 
  } 
  else {
      // prepend msg with woah.
      return {
          ...data, 
          msg: `[woah!] ${data.msg}`
      } 
  } 
}
//start the logger
Run(filter)

what does pino-tiny do?

  • shows log level, 3 characters (and not a emoji icon), color coded, and ??? for custom log levels.
  • timestamps (no dates). you know what day it is but millisecond timestamps give you some performance output
  • strips all but the msg for output
  • if there is are res and req properties in the log data, it will put dimmed request and response info (method, url, status code).
  • non-json string data that get piped in (like nodemon) get treated as info logs and outputted.
  • does not swallow error messages
  • non-pino JSON will be logged as dimmed stringified JSON

New in v2.0

  • programmatic prettifier
  • better colors
  • handle non-pino json
  • emojis! 🔎 🪲 ℹ️ ⚠️ 🔥 💣
  • src is now in typescript

New in v2.1

  • added prettifier options
  • added prettifier options as cli args
  • added back the filter method in options
  • added back the extensibility

New in v2.2

  • dep version bumps
  • support for msg and message in logger