New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes final warn that is not supported instead of throwing #528
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I've read up on the issue - not sure I agree that warning is better than throwing. Throwing is the right thing because you shouldn't use pino.final at all with streams I'd rather pino-pretty catches the error and then prints a warning itself |
I think it is. The following currently won't work, and a user would have to add another if for const pino = require('pino')
const logger = pino({
prettyPrint: process.env.NODE_ENV === 'development'
})
const run = async () => {
process.on('SIGTERM', pino.final(logger, (err, finalLogger) => {
finalLogger.info('Graceful shutdown 1')
finalLogger.info('Graceful shutdown 2')
process.exit(0)
}))
await delay(30)
}
const delay = (secs) => {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), secs * 1000)
})
}
run().catch(err => {
logger.error({ err })
})
You cannot catch that error, as pino-pretty is not involved at all in the check. Another option is to replace the |
yeah I think it caters to the two targeted cases -
|
PTAL |
test/final.test.js
Outdated
@@ -27,7 +27,7 @@ test('throws if the supplied handler is not a function', async ({ throws }) => { | |||
test('throws if not supplied logger with pino.destination or pino.extreme instance', async ({ throws, doesNotThrow }) => { | |||
throws(() => { | |||
pino.final(pino(fs.createWriteStream('/dev/null')), () => {}) | |||
}, Error('only compatible with loggers with pino.destination and pino.extreme')) | |||
}, Error('inal requires a stream that has a flushSync method, such as pino.destination and pino.extreme')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: inal
-> final
other than the typo - LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fixes pinojs/pino-pretty#37