Home

Awesome

p-log

Log the value/error of a promise

Install

$ npm install p-log

Usage

import pLog from 'p-log';

Promise.resolve('unicorn')
	.then(pLog()) // Logs `unicorn`
	.then(value => {
		// `value` is still `unicorn`
	});
import pLog from '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