Why node-emoji won't print properly on nestjs/pino logger?

796 Views Asked by At

I am investigating a strange behavior from a Nestjs project I am developing, that wants to use @NestJs/Pino logger to display emojis in the terminal's logs. However, node-emoji only display the emoji properly in the terminal if I use console.log(emoji.get('gear')). However, if I use pino.info(emoji.get('gear') + ' test string.....'), I get an output of: [1646848210346] INFO (18320 on DESKTOP-2H3BS4O): **⚙️** test string...... Where "⚙️", is supposed to be the emoji printed by the logger at the terminal.

I have seek support at Nestjs's discord, but there, a user used my minimum reproduction repository, and the problem did not happened in their environment. I am using Windows/VSCode which leads me to believe that the problem might be something with my environment. So, here is the link to the repo:link, to run the project:

  • npm i
  • npm run start:dev
  • Go to http://localhost:3000/api/#/default/AppController_getHello, and call the Get '/testEmoji'.
  • Look at VSCode's terminal.

MY VSCode Env:

  • Version: 1.62.3 (user setup)
  • Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
  • Date: 2021-11-17T08:11:14.551Z
  • Electron: 13.5.2
  • Chrome: 91.0.4472.164
  • Node.js: 14.16.0
  • V8: 9.1.269.39-electron.0
  • OS: Windows_NT x64 10.0.19044

My PC environment:

  • OS Name: Microsoft Windows 10 Pro
  • OS Version: 10.0.19044 N/A Build 19044

Information about package.json, package-lock.json, and confiuraton for @nestjs/pino logger can be found at the linked repo.

1

There are 1 best solutions below

0
On BEST ANSWER

This is known limitation of Node.js that was discovered by Pino back in 2018. Pino team proposes this workaround in their documentation.

Run this command in terminal:

chcp 65001

If you use nodemon and pino-pretty, you may have to add something like this to package.json to make it work in VSCode terminal (powershell by default).

  "scripts": {
    "start": "node index.js",
    "dev": "chcp 65001 && nodemon index.js | pino-pretty"
  },

Then, running npm run dev will work.