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

palin

v2.3.0

Published

A beautiful Bristol formatter for development logging

Downloads

3,043

Readme

Palin

Palin is a beautiful Bristol formatter for development logging.

Build Status

Preview

preview

Use

Install with npm install palin --save

Please remember to star ⭐️ this repo!

const log = require('bristol');
const palin = require('palin');
log.addTarget('console').withFormatter(palin);

log.info("We're up and running!");

One of Palin's main features is the ability to log whatever you throw at it. For example, you may want to log two Errors and other associated data.

const err1 = new Error('Error 1');
const err2 = new Error('Error 2');
log.error('oh, snap!', err1, err2, [ 'thing', 123 ])

Produces:

23:00:46:035 ERROR oh, snap! (test/integration.js:16)
  →  { '0': 'thing', '1': 123 }
  →  Error: Error 1
  →      at Object.<anonymous> (/Users/Mark/projects/palin/test/integration.js:14:12)
  →      at Module._compile (module.js:425:26)
  →      at Object.Module._extensions..js (module.js:432:10)
  →      at Module.load (module.js:356:32)
  →      at Function.Module._load (module.js:313:12)
  →      at Function.Module.runMain (module.js:457:10)
  →      at startup (node.js:138:18)
  →      at node.js:974:3
  →  Error: Error 2
  →      at Object.<anonymous> (/Users/Mark/projects/palin/test/integration.js:15:12)
  →      at Module._compile (module.js:425:26)
  →      at Object.Module._extensions..js (module.js:432:10)
  →      at Module.load (module.js:356:32)
  →      at Function.Module._load (module.js:313:12)
  →      at Function.Module.runMain (module.js:457:10)
  →      at startup (node.js:138:18)
  →      at node.js:974:3

API

Formatter Options

As per the Bristol logger API, you may specify options for formatters.

log
  .addTarget('console')
  .withFormatter(palin, {
    // formatter options go here
  });

Root Folder

Palin logs the file path where log messages originate from. Usually these paths are needlessly long. The rootFolderName option allows you to specify a string prefix of where to shorten the path.

log
  .addTarget('console')
  .withFormatter(palin, {
    rootFolderName: 'MyProject'
  });
  // produces log messages like:
  //  08:54:25:892 LOG hello (controller/hello.js:9)
  // instead of:
  //  08:54:25:892 LOG hello (/Users/Mark/projects/MyProject/controller/hello.js:9)

Timestamp

Palin logs timestamps in the "HH:mm:ss:SSS" format by default. You may want your timestamps to be different. This can be controlled with the timestamp option.

You can disable timestamps:

log
  .addTarget('console')
  .withFormatter(palin, {
    timestamp: false
  });

You can also provide your own timestamp function (shown with Moment.js):

var moment = require('moment'); // using moment.js
log
  .addTarget('console')
  .withFormatter(palin, {
    timestamp: function(date) {
        return moment(date).format(); // produces moment's default format
    }
  });

Indent

Any information that is attached to a log message is indented and included on the next line. The indentation format can be controlled with the indent option.

log
  .addTarget('console')
  .withFormatter(palin, {
    indent: '\n    ⇒  '
  });

Object Depth

Palin formats objects using the built-in require('util').inspect(). Use the objectDepth option to increase depth of each object printed.

log
  .addTarget('console')
  .withFormatter(palin, {
    objectDepth: 5 // instead of inspect's default level ( usually 2 )
  });

Source

Hide the source line/file of messages. Useful for logging purely informational messages.

log
  .addTarget('console')
  .withFormatter(palin, {
    souce: false
  });

Other features

Palin supports the concept of a "scope", which is a way of labeling groups of log messages. To use this, simply add an object with the key scope to the list of arguments. The color of the scope variable will be maintained for the lifetime of the the Bristol logger.

log.info('hello world', { scope: 'welcome' });
// produces:
// 08:54:25:892 INFO controller welcome (controller/hello.js:9)