`sync` doesn't work
inwenis opened this issue · comments
fku-incom commented
const pino = require('pino')
const logger = pino({
transport: {
target: 'pino-pretty',
options: {
colorize: true,
sync: true
}
}
}, pino.destination({sync:true}))
console.log('yyy');
logger.info('hi');
console.log('xxx');
Expected:
yyy
[15:02:27.684] INFO (8368): hi
xxx
Actual:
yyy
xxx
[15:02:27.684] INFO (8368): hi
It works fine without pretty-print
:
const pino = require('pino')
const logger = pino({}, pino.destination({sync:true}))
console.log('yyy');
logger.info('hi');
console.log('xxx');
Output:
yyy
{"level":30,"time":1712668061532,"pid":6376,"hostname":"LAPTOP-GOU7DNK8","msg":"hi"}
xxx
package.json
{
"name": "test11",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"pino": "^8.20.0",
"pino-pretty": "^11.0.0"
}
}
Matteo Collina commented
A few notes:
- you are using both a transport and a destination. You can't have a both (we should probably throw)
- the transport logic is inherently asynchronous, as it ran off thread. If you want synchronous pretty printing, you should just use it as a stream.
Adding some docs on all the above would be good, as it seems it's a source of confusion.
fku-incom commented
thank you for the answer, that explains it