Skip to content
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 doesn't work #504

Open
inwenis opened this issue Apr 9, 2024 · 2 comments
Open

sync doesn't work #504

inwenis opened this issue Apr 9, 2024 · 2 comments
Labels

Comments

@inwenis
Copy link

inwenis commented Apr 9, 2024

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"
  }
}

@mcollina
Copy link
Member

A few notes:

  1. you are using both a transport and a destination. You can't have a both (we should probably throw)
  2. 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.

@inwenis
Copy link
Author

inwenis commented Apr 12, 2024

thank you for the answer, that explains it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants