-
Notifications
You must be signed in to change notification settings - Fork 847
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
Sync logging is not working as expected #1532
Comments
Why do you think it's a problem? Depending on the destination and operating system, console.log might not synchronous. |
Generally useful in dev for debugging the sequence of things. I'm used to inserting console logs to track down where some execution takes place. I think it used to be the case that console logs would interleave with pino logs and helped identify sequence of what happened when and where when developing locally. Now pino logs just go after all console logs making such dev flow less useful. Unless I'm wrong and this never behaved that way. Yes, an actual debugger is also useful for debugging.. but console log debugging in js is useful, you can understand program behavior by observing state changes over time. And yes, this is just for dev, not for prod, not for all environments. But I understand if there are good technical reasons not to allow this. Or can I do this by using a custom transport already? |
Please provide a minimal reproducible example. The code you have provided is incomplete. |
Didn't realise when posting, but this is only happening with pino-pretty transport when configured via transport option key: const pino = require('pino')
const log = pino({
transport: {
target: 'pino-pretty',
options: {
sync: true,
}
}
})
console.log('before')
log.info('pino log')
log.info('pino log')
console.log('after') Outputs:
|
From https://getpino.io/#/docs/api?id=transport-object => https://getpino.io/#/docs/api?id=pino-transport : In your example, the object attached to the |
These 2 behave differently: const pino = require('pino')
const log = pino({
transport: { target: 'pino-pretty', options: { sync: true } }
})
console.log('before')
log.info('pino log')
log.info('pino log')
console.log('after')
/** logs out
before
after
pino log
pino log
*/ and const pino = require('pino')
const log = pino({}, require('pino-pretty')({ sync: true }))
console.log('before')
log.info('pino log')
log.info('pino log')
console.log('after')
/** logs out
before
pino log
pino log
after
*/ That inconsistency is a bit surprising (and udocumented)! Looking closer, it's because pino-pretty set up via Lines 279 to 292 in 7d16f04
And so in the first example it gets created via the Hm, not sure what would be best here without understanding more of the context, history and goals of the project, e.g. why are there 2 ways to pass in the transport, and both behave subtly differently 🤔, and is Anyway, this isn't a deal breaker, but I hope helpful feedback. I can switch to using that 2nd approach for now if I want to get the sync behaviour working. |
Again, this is totally expected. Transports are run asynchronously on a separate thread. By running pino-pretty in the same process with Would you like to update the docs so it's clearer? |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Outputs
The text was updated successfully, but these errors were encountered: