1.3.3 • Published 8 months ago

pinetto v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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: '',
})
OptionDescriptionDefault value
levelStarting log level, one of "trace", "debug", "info", "warn", "error""info"
writerLog writer function (see below)Depends on the environment
prefixSeparatorA 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:

1.3.3

8 months ago

1.3.2

8 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.1.0

9 months ago

1.0.2

1 year ago

1.0.1

1 year ago

0.3.0

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.4.1

1 year ago

0.2.3

2 years ago

0.4.0

1 year ago

0.2.2

2 years ago

0.2.4

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.0.1

2 years ago