p-log
v3.0.0
Published
Log the value/error of a promise
Downloads
978
Maintainers
Readme
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
- 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…