pinetto
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

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

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 logger = pinetto({ level: 'debug' });
const child = logger.child('child-prefix');

logger.info('Hello, world!'); // prints hello world
child.debug('Hello, world!'); // prints hello world

logger.level = 'warn';        // log level can be changed at runtime
                              // the change propagates to child loggers

child.info('Hello, world!');  // prints nothing

Supported options

const logger = pinetto({
  level: 'debug',
  writer: new BufferedWriter(),
  prefixSeparator: '',
})
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
prefixSeparator A string that is used to concatenate prefixes in chain of child loggers " "

Formatting

printf-style syntax is supported:

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

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

Log writers

Pinetto ships with two different writers: ConsoleWriter and BufferedWriter. The former falls back onto standard console logging methods while the latter flushes log entries to either console.log() or process.stdout.write() in an asynchronous fashion, depending on whether a node-like environment is detected.

By default, pinetto will use BufferedWriter in node-like environments and ConsoleWriter everywhere else. However, the writer can be manually set via the respective constructor option:

import pinetto, { ConsoleWriter, BufferedWriter } from 'pinetto';

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

License

Pinetto is released under the MIT license.

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.3
    54
    • latest

Version History

Package Sidebar

Install

npm i pinetto

Weekly Downloads

64

Version

1.3.3

License

MIT

Unpacked Size

46.3 kB

Total Files

61

Last publish

Collaborators

  • jacoscaz