Closed ghost closed 1 year ago
Hello, i reproduce this and find a way:
First, the pino
function used to initialize receives the parameters in order: (options, destinationStream), you used backwards.
Then, you pass the pretty twice, one for transporter and one as destinationStream, this will confuse your logs, pino-pretty
is a final transporter/stream, he will give you the output, so if you want to add another transporter you will have to use like a transporter but in another way, i recommend create another file, one to each transporter. Finally, I just removed the transporter from pino
and concatenated the pino-pretty
as destinationStream.
Lastly, pino-pretty
has some lacks of documentation so the option you will use is customLevels
which is a string, so:
{
http: 10,
info: 30,
debug: 35,
warn: 40,
error: 50,
fatal: 60,
}
will become: "http:10,info:30,debug:35,warn:40,error:50,fatal:60"
with the replaces and slice i did (so you don't have to do everything manually), the final code working:
const pino = require('pino');
const pretty = require('pino-pretty');
const levels = {
http: 10,
info: 30,
debug: 35,
warn: 40,
error: 50,
fatal: 60,
}
const jsonLevels = JSON.stringify(levels);
const levelsInString = jsonLevels.replaceAll('"','').slice(0,-1).slice(1)
const log = pino(
{
customLevels: levels,
useOnlyCustomLevels: true,
level: 'http',
// transport: {
// target: 'pino-pretty'
// },
},
pretty({
colorize: true,
levelFirst: true,
customLevels: levelsInString,
translateTime: 'yyyy-dd-mm, h:MM:ss TT',
})
);
log.http('Http test log');
log.debug('DEBUG MESSAGE');
Output:
HTTP [2023-06-02, 12:16:57 AM] (22720): Http test log
DEBUG [2023-06-02, 12:19:21 AM] (23016): DEBUG MESSAGE
@ademarsj Thank you!
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.
When I config the log level and custom levels it doesn't work. here is my code
When I used the HTTP level it errors
log.http('Hello World')
Expected Output for HTTP Level[HH:MM:SS.SSS] HTTP (PID): Hello World
Output for HTTP LevelTypeError: log.http is not a function
Why doesn't this work? Also even with the custom levels not working, the levels themselves aren't working! Even if I do this
log.debug
messages still don't show up like the level is still info