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

nimz-cli

v1.0.2

Published

Group logs according to their asynchronous context and display nicely in a table format.

Downloads

2

Readme

nimz-cli

CLI Logger for Node.JS

Group logs according to their asynchronous context and display nicely in a table format.

Install

Warning: This package is ESM only. Please refer to this guide to migrate your project to ESM or to use this package with CommonJS.

npm install nimz-cli

Blog post

Example

CLI Logger Demo

import delay from "delay";
import randomWords from "random-words";
import { log, logFinished, withGrouping, withLogManager } from "./logger.js";

function randomMs() {
  return Math.random() * 1000;
}

async function doSomething3() {
  log("doSomething-3");
  for (let i = 0; i < 10; i++) {
    log("doSomething-33 " + randomWords(5));
    await delay(randomMs());
    log("doSomething-333 " + randomWords(20));
  }
}

async function doSomething2() {
  log("doSomething-2");
  await delay(randomMs());
  log("doSomething-22");
  await withGrouping("d", doSomething3);
  log("doSomething-222");
  logFinished("You're all set!", randomWords(5).join(" "));
}

withLogManager(
  async () => {
    await withGrouping("a", async () => {
      log("doSomething-1-a start");
      await delay(randomMs());
      await Promise.all([
        withGrouping("b", doSomething2),
        withGrouping("c", doSomething2),
      ]);
      await delay(randomMs());
      log("doSomething-1-a end");
    });
  },
  { saveToFile: true, maxWidth: 100 }
);

API

withLogManager(fn, options?) => Promise

Wrap your code in a withLogManager block to enable context logging. This should be the start of your program or code execution path.

fn

Type: Function

Promise-returning or async function.

options

Type: object

maxLines

Type: number
Default: 5

Limit the number of lines to display per log group in the table.

maxWidth

Type: number
Default: process.stdout.columns - 20

Limit the number of characters to display per line in the table. This does not stop nested tables from overflowing.

disableTerminalOutput

Type: boolean
Default: false

Disable terminal output. Useful for saving logs to a file only.

saveToFile

Type: boolean
Default: true

Should save output to a file.

fileOutputPath

Type: string
Default: path.join(process.cwd(), "logs.txt")

Specify the path to save the log file.

truncateFileOutput

Type: boolean
Default: false

Save the log file in truncate mode (e.g. 16 lines truncated...).

printAsciiTable

Type: boolean
Default: false

Use ascii characters to print table. Useful if running in a terminal that does not support unicode characters.

printFinalOutputOnly

Type: boolean
Default: false

Print the final output only. Useful if running in CI or using multiple log managers in the same program which would write over each other.

withGrouping(title, fn) => Promise

Wrap your code in a withGrouping block to create a new log group.

log(...messages)

Log a message to the current log group.

logFinished(...messages)

Clear and log a message to the current log group. Useful for logging only the final message of a log group.