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

pinetto

v3.0.0

Published

Isomorphic, opinionated logging library focusing on simplicity and readability. Supports child loggers.

Downloads

635

Readme

Pinetto

An isomorphic, opinionated logging library that focuses on:

  • Simplicity: zero runtime dependencies, ~500 LoCs
  • Readability: produces plain-text, human-readable output
  • Performance: uses asynchronous logging techniques when possible
  • Child loggers: supports chained child loggers using prefix concatenation
  • Isomorphism: supports browsers and server-side runtimes
  • ESM: ships with separate ESM and CommonJS builds
  • Flexibility: log level can be changed at runtime

Etymology

In many areas this library stands opposite to pino, hence the name.

-etto

forms nouns from nouns, denoting a diminutive

Wikipedia

Usage

Within ES modules

import pinetto from 'pinetto';

Within CommonJS modules

const { default: pinetto } = require('pinetto');

Basic usage

const root = pinetto({ level: 'debug' });
root.info('Hello, %s!', 'World');
// => 2024-09-09T19:05:28.884Z INF Hello, World!

const child = logger.child('[foo]');
child.debug('Hello, %s!', () => 'World');
// => 2024-09-09T19:06:02.643Z INF [foo] Hello, World!

const grandchild = child.child('[bar]');
grandchild.debug('Hello, %s!', 'World');
// => 2024-09-09T19:06:02.643Z INF [foo][bar] Hello, World!

// The log level can be changed at runtime and the change
// propagates to child loggers.
logger.level = 'warn';        
child.info('Hello, world!'); 
// => <prints nothing>

Supported options

| Option | Description | Default value | | --- | --- | --- | | level | Starting log level, one of "trace", "debug", "info", "warn", "error" | "info" | | writer | Log writer function (see below) | Depends on the environment | | datetime | A function that returns a date/time string (see below) | datetimeISO |

String formatting

printf-style syntax is supported:

const logger = pinetto({ level: 'debug' });

logger.info('Hello, %s!', 'World');

Date/time

The datetime option may be used to customize whether and how each log line will be prefixed with a date/time string:

const logger = pinetto({ 
  level: 'debug',
  datetime: () => `${new Date().getFullYear()} `,
});

logger.info('Hello, %s!', 'World');
// => 2024 INF Hello, World!

Pinetto ships with two datetime functions: datetimeVoid, which returns an empty string, and datetimeISO, which returns an ISO 8601 string (well, technically it's the RFC 3339 string returned by Date#toISOString).

Note that datetime functions must return a string that ends with a space character.

Functions as arguments

If a log argument is provided in the form of a function it will invoked only when the log triggers and its return value will be passed to the formatter.

This helps with reducing the number of expensive serialization operations, such as JSON.stringify(), taking place even when the log level is such that the result of the serialization will never be used:

logger.level = 'warn';
logger.info('Foo %s', () => JSON.serialize({ bar: 42 }));
// JSON.serialize() will never be invoked

Log writers

Pinetto ships with three different writers:

  • ConsoleWriter, which falls back onto console.log() and works pretty much everywhere;

  • ProcessWriter, which falls back onto process.stdout.write() and can only be used in Node.js-like environments;

  • BufferedWriter, which buffers entries and periodically flushes its buffer out using process.stdout.write() (when in Node.js-like environments) or console.log() (everywhere else).

By default, pinetto will use ProcessWriter in Node.js-like environments and ConsoleWriter everywhere else. A custom writer can be set via the respective constructor option:

import pinetto, { BufferedWriter } from 'pinetto';

const logger = pinetto({ level: 'debug', writer: new BufferedWriter() });

License

Pinetto is released under the MIT license.

The following packages have been vendored into pinetto, although slowly diverging from the respective sources: