Open alexv-ds opened 1 year ago
This is amazing! What are those two APIs? I have a feeling we might want to expose them on Node.js itself.
@mcollina I do not understand the question😅, please reword it, english is not my native tongue.
No worries, I did a bit a googling and found my answer!
Thanks!
Would you like to send a PR to add those to our docs? https://github.com/pinojs/pino/blob/master/docs/help.md would be a good page.
ffi-napi
module didn't work for me, so I used koffi
:
import koffi from 'koffi';
if (process.platform === 'win32') {
const CP_UTF8 = 65001;
const kernel32 = koffi.load('Kernel32');
const setConsoleOutputCP = kernel32.func('SetConsoleOutputCP', 'bool', ['int']);
const setConsoleCP = kernel32.func('SetConsoleCP', 'bool', ['int']);
setConsoleOutputCP(CP_UTF8);
setConsoleCP(CP_UTF8);
}
For those who don't want to carry several megabytes of modules from the koffi
library into the project, you can use native Node.js streams. Here is an example with two streams - one outputs data to the console and the other writes logs to a file:
const pino = require('pino');
const pretty = require('pino-pretty');
const fileStream = createWriteStream('log.txt', { flags: 'a' });
const consoleStream = pretty({ colorize: true, destination: process.stdout });
const streams = [{ level: 'debug', stream: fileStream }, { level: 'info', stream: consoleStream }]
const logger = pino({ level: 'info' }, pino.multistream(streams));
But with this approach SonicBoom
will not be used and accordingly the speed of pino
will be lower.
I faced the problem of outputting Cyrillic letters to the console via the pino logger. This has been discussed here -> #548. I present my solution. Perhaps someone will need it.
Tested on node v20.2.0
Using the ffi-napi module.
and result