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

Windows: incorrect encoding on Unicode output #548

Closed
budarin opened this issue Nov 20, 2018 · 17 comments · Fixed by #552
Closed

Windows: incorrect encoding on Unicode output #548

budarin opened this issue Nov 20, 2018 · 17 comments · Fixed by #552
Labels

Comments

@budarin
Copy link
Contributor

budarin commented Nov 20, 2018

I try to log

logger.info(`Сервер запущен по адресу:')

but see in log

{"level":30,"time":1542741475885,"msg":"╨б╨╡╤А╨▓╨╡╤А ╨╖╨░╨┐╤Г╤Й╨╡╨╜ ╨┐╨╛ ╨░╨┤╤А╨╡╤Б╤Г:
@davidmarkclements
Copy link
Member

davidmarkclements commented Nov 20, 2018

ohhhh wow ok - we need to cater to full unicode

this will slow things down, if it causes significant overhead we might have to add an "international" option with a documented perf hit

@davidmarkclements
Copy link
Member

oooor.. maybe we can use a post-processor to re-encode

@budarin
Copy link
Contributor Author

budarin commented Nov 20, 2018

no
here is logger configuration

import pino from 'pino';

const dest = pino.extreme();
const logger = pino(dest);
setInterval(() => logger.flush(), 10000).unref();

export default logger;

@davidmarkclements
Copy link
Member

I'm not able to reproduce

image

@davidmarkclements
Copy link
Member

also verified to work with pino.extreme

image

@davidmarkclements
Copy link
Member

redirecting to file, works:

image

@budarin
Copy link
Contributor Author

budarin commented Nov 20, 2018

default

@davidmarkclements
Copy link
Member

davidmarkclements commented Nov 20, 2018

it might be due to the fact you're transpiling your server

try

process.stdout.write(`Сервер запущен по адресу:`)

@davidmarkclements
Copy link
Member

davidmarkclements commented Nov 20, 2018

or otherwise I'm seeing that the output is being escaped, so something is processing the output

closing for now, as this doesn't seem like a problem with Pino

@budarin
Copy link
Contributor Author

budarin commented Nov 20, 2018

strange - writing into stdout is working right

default

this is in the same transpilled code

logger.info(`Сервер запущен по адресу: ${SERVER_URL || 'error'}`);
process.stdout.write(`Сервер запущен по адресу:`);

@jsumners
Copy link
Member

Oh boy. How has this not come up before?

To be JSON spec compliant we should be outputting UTF-8 strings. I'm not seeing anything in the language spec that that dictates how strings are to be encoded -- https://tc39.github.io/ecma262/#sec-text-processing . But this article implies that they could be UTF-16, and a comment to it indicates they could very well be merely ASCII, -- https://kev.inburke.com/kevin/node-js-string-encoding/

Regarding the problem, I suspect it has to do with the encoding of the destination. So if process.stdout isn't in UTF-8 mode you are likely to get garbage.

@davidmarkclements
Copy link
Member

Ok reopening as it looks like this might be on us - or more likely - sonic-boom cc @mcollina

@budarin - as a workaround try pino(process.stdout)

@budarin
Copy link
Contributor Author

budarin commented Nov 20, 2018

this is only apparent in Windows
have verified on MacOS - everything is ok

@davidmarkclements davidmarkclements changed the title Have a bug with russian language Windows: incorrect encoding on Unicode output Nov 20, 2018
@davidmarkclements
Copy link
Member

The thing is sonic-boom does support UTF-8 (https://github.com/mcollina/sonic-boom/blob/master/index.js#L71) so this problem might go all the way to Node core

@mcollina
Copy link
Member

Turns out it's a known limitation of Node.js.

Running chcp 65001 https://ss64.com/nt/chcp.html solves the problem for me.

I propose we just document this behavior in the pino website https://getpino.io/#/docs/help.

@mcollina
Copy link
Member

Thanks @refack in nodejs/node#24550 (comment).

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants