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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@plandek-utils/logging

v1.1.0

Published

TypeScript utils for Logging. Includes prettifying of JSON, logging utils, and colour utils.

Readme

@plandek-utils/logging

npm version Maintainability Test Coverage

TypeScript utils for Logging. Includes prettifying of JSON, logging utils, and colour utils.

Installation

npm install @plandek-utils/logging

Usage

Pretty JSON: prettyJSON and colorPrettyJSON or colourPrettyJSON

import { prettyJSON } from "@plandek-utils/logging";

const obj = { name: "John", age: 30 };
console.log(prettyJSON(obj)); // OUTPUT: {\n  "name": "John",\n  "age": 30\n}
import { colorPrettyJSON } from "@plandek-utils/logging";

const obj = { name: "John", age: 30 };
console.log(colorPrettyJSON(obj));

output:

"\x1b[90m{\x1b[39m\x1b[90m\n" +
  '  \x1b[39m\x1b[35m"name"\x1b[39m\x1b[90m:\x1b[39m\x1b[90m \x1b[39m\x1b[33m"John"\x1b[39m\x1b[90m,\x1b[39m\x1b[90m\n' +
  '  \x1b[39m\x1b[35m"age"\x1b[39m\x1b[90m:\x1b[39m\x1b[90m \x1b[39m\x1b[32m30\x1b[39m\x1b[90m\n' +
  "\x1b[39m\x1b[90m}\x1b[39m"

You can use colorPrettyJSON or colourPrettyJSON (alias).

makeColourUtils(mode: "with-colour" | "plain"): LogColourUtils

Creates a utility object for colouring log messages using CHALK.

import { makeColourUtils } from "@plandek-utils/logging";

const colorUtils = makeColourUtils("with-colour");
console.log(colorUtils.blue("Hello"));

const plainColorUtils = makeColourUtils("plain");
console.log(plainColorUtils.blue("Hello")); // Output: Hello as is.

Loggers

  • for real: buildPinoLogger(level: LevelWithSilent, redactPaths?: string[]): PreparedLogger
  • for test: buildSinkLogger(level: LevelWithSilent, bindings?: PlainObject): PreparedLogger
  • parse log level: parseLogLevelOrDefault(x: string): LogLevel

Creates a Pino logger with common configuration.

import { buildPinoLogger, buildSinkLogger, parseLogLevelOrDefault } from "@plandek-utils/logging";

const level = parseLogLevelOrDefault(process.env.LOG_LEVEL, "info"); // gets the log level if present, otherwise info. If the LOG_LEVEL is not a valid one it will throw.
const logger = buildPinoLogger(level, ["req.headers.authorization"]);

const testLogger = buildSinkLogger(level); // does not send any log -> useful for tests.

logger.info({ req: { headers: { authorization: "Bearer token" } } }, "User logged in");
// {"level":30,"time":"2024-10-28T11:10:58.250Z","pid":18166,"hostname":"044ce1509ebe","req":{"headers":{"authorization":"[REDACTED]"}},"msg":"User logged in"}

logger.info("Hi!");
// {"level":30,"time":"2024-10-28T11:12:48.732Z","pid":18166,"hostname":"044ce1509ebe","msg":"Hi!"}

makeLogging

import { makeLogging } from "@plandek-utils/logging";

const logger = buildPinoLogger("info");
const logging = makeLogging({ logger, section: "api" });

logging.info("User logged in", { userId: 123 });
// {"level":30,"time":"2024-10-28T11:14:13.519Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"userId":123,"msg":"User logged in"}

logging.withSection("database").debug("Query executed");
// no output since `debug` is not enabled in the logger

logging.withSection("database").error("Query failed");
// {"level":50,"time":"2024-10-28T11:14:59.509Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"logSections":["api","database"],"msg":"Query failed"}

makeLoggingWithRecord

Same as makeLogging, but keeping an in-memory record of all messages (and contexts) sent. This is meant for testing purposes.

import { makeLoggingWithRecord, type PreparedLogger } from "@plandek-utils/logging";

const logger: PreparedLogger = buildPinoLogger("info");
const loggingWithRecords = makeLoggingWithRecord({ logger, section: "api" });

loggingWithRecords.info("User logged in", { userId: 123 });
// {"level":30,"time":"2024-10-28T11:16:49.607Z","pid":18166,"hostname":"044ce1509ebe","logSections":["api"],"userId":123,"msg":"User logged in"}

console.log(loggingWithRecords.messages.info);
// [ [ "User logged in", { userId: 123 } ] ]

Development

This package is developed with TypeScript and uses Vitest for testing.

  • npm run build: build the package
  • npm test: run tests
  • npm run test:watch: run tests in watch mode
  • npm run test:coverage: run tests with coverage
  • npm run lint: lint files
  • npm run format: format files

License

MIT License - see LICENSE file