Closed OnkelTem closed 2 years ago
I have no clue. You can use const logger = pino(pretty())
for those cases.
I'm not sure what pretty()
is?
Got it. It requires an argument:
const logger = pino(pretty({}));
It became even more puzzling now with:
test('test pino-pretty output 2', () => {
const logger = pino(pretty({}));
logger.info('Info');
logger.error('Error');
});
As it returns now only INFO
line while error has disappeared:
[1642527375208] INFO (47538 on fractal): Info
Ok, I've discovered that it's a WebStorm bug.
From command line it works correctly:
$ jest -t 'test pino-pretty output'
PASS test/pino.test.ts
[1642527675060] INFO (49025 on fractal): Info
[1642527675060] ERROR (49025 on fractal): Error
Test Suites: 2 skipped, 1 passed, 1 of 3 total
Tests: 28 skipped, 1 passed, 29 total
Snapshots: 0 total
Time: 1.532 s, estimated 7 s
I was too fast probably. Problems persist and I don't really get their nature.
Does pino-pretty work asynchronously? How to use it properly as a transport?
You see, when I use it with jest it can output:
$ jest -t 'test pino-pretty output 2'
PASS test/pino.test.ts
[1642527980540] INFO (51472 on fractal): Info
Test Suites: 2 skipped, 1 passed, 1 of 3 total
Tests: 28 skipped, 1 passed, 29 total
Snapshots: 0 total
Time: 1.405 s, estimated 7 s
Ran all test suites with tests matching "test pino-pretty output 2".
[1642527980542] ERROR (51472 on fractal): Error
[1642527980542] ERROR (51472 on fractal): Error2
[1642527980543] ERROR (51472 on fractal): Error3
So, messages on stdout
come while jest is working at any moment. Like it was async.
@mcollina Could you please elaborate a little?
No one maintaining this module uses Jest or WebStorm.
@jsumners
That's fine. I just need to know how to use pino-pretty properly. Because now it looks like every call to pino logger has a side-effect, while the code looks like it's synchronous. It doesn't seem to be related to Jest or WebStorm.
How can we improve the documentation to make it easier to understand?
@jsumners we are missing a sync
option to in this module, right now we are only logging asynchronously. Then it's docs.
A more clearer test case.
pino
:import pino from 'pino';
const logger = pino();
logger.info('Line 1');
console.log('Line 1');
logger.info('Line 2');
console.log('Line 2');
logger.info('Line 3');
console.log('Line 3');
Output:
{"level":30,"time":1642530313924,"pid":54664,"hostname":"fractal","msg":"Line 1"}
Line 1
{"level":30,"time":1642530313924,"pid":54664,"hostname":"fractal","msg":"Line 2"}
Line 2
{"level":30,"time":1642530313925,"pid":54664,"hostname":"fractal","msg":"Line 3"}
Line 3
I.e. it corresponds to what one would expect looking at the code, right?
pino-pretty
:import pino from 'pino';
const logger = pino({ transport: { target: 'pino-pretty' } });
logger.info('Line 1');
console.log('Line 1');
logger.info('Line 2');
console.log('Line 2');
logger.info('Line 3');
console.log('Line 3');
Output is:
Line 1
Line 2
Line 3
[1642530508280] INFO (54903 on fractal): Line 1
[1642530508281] INFO (54903 on fractal): Line 2
[1642530508281] INFO (54903 on fractal): Line 3
So... I understand why it could happen. But, really, that doesn't look coherent with the code :(
P.S. Also, I now see how wrong I was trying to use it with my tool. Because sync messages are what I would have needed instead.
@jsumners we are missing a
sync
option to in this module, right now we are only logging asynchronously. Then it's docs.
It does make sense.
Meanwhile, as I don't want to replace the whole logging thing in my app, I can probably use pino directly with my custom formatter.
I noticed that Jest somehow suppresses pino-pretty output and created these simple tests:
Here is the output of running:
'test pino output'
:'test pino-pretty output'
As you may see, there is no any output when using pino-pretty.
Any ideas why?
P.S. I use WebStorm to run tests. Haven't tried to run them in command line. It's worth trying, will write back soon.