Skip to content
Log the value/error of a promise
JavaScript TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitattributes
.gitignore
.npmrc
.travis.yml
index.d.ts
index.js
index.test-d.ts
license
package.json
readme.md Meta tweaks Mar 12, 2019
test.js

readme.md

p-log Build Status

Log the value/error of a promise

Install

$ npm install p-log

Usage

const pLog = require('p-log');

Promise.resolve('unicorn')
	.then(pLog()) // Logs `unicorn`
	.then(value => {
		// `value` is still `unicorn`
	});
const pLog = require('p-log');

Promise.resolve()
	.then(() => {
		throw new Error('pony');
	})
	.catch(pLog.catch()) // Logs `Error: pony`
	.catch(error => {
		// `error` is still `Error: pony`
	});

API

pLog([logger])

Use this in a .then() method.

Returns a thunk that returns a Promise.

pLog.catch([logger])

Use this in a .catch() method.

Returns a thunk that returns a Promise.

logger

Type: Function
Default: console.log

The logger to use. Any return value or exception is ignored.

Related

  • p-tap - Tap into a promise chain without affecting its value or state
  • p-if - Conditional promise chains
  • p-catch-if - Conditional promise catch handler
  • More…

License

MIT © Sindre Sorhus

You can’t perform that action at this time.