Closed pavannarayan05 closed 1 year ago
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
Hi, Sure. Have posted the code below. pino.multistream is not being recognized as a valid function. I would like to display logs in console and simultaneously write the logs to a file, with a specific message display pattern
import pinoCaller from 'pino-caller'
import pino from 'pino'
const streams = [
{ stream: process.stdout },
{ stream: pino.destination('commonlogs.log') },]
export const setLog = (job_name: any) => {
const pinoPretty = pino(
{
prettyPrint: {
messageFormat: `{"job_name":${job_name}, "message":{msg}}`,
},
},
pino.multistream(streams)
)
const logObj = process.env.NODE_ENV !== 'production' ? pinoCaller(pinoPretty) : pinoPretty
return logObj
}
The following code runs fine on my system:
import pino from 'pino'
console.log(pino.multistream)
Hi, Thanks. I was able to use multistream after I upgraded Pino npm package. However, I need help in formatting the log text that goes into the file. I was able to format the logs that appears on console using pino-pretty. But I am not sure how the same can be done for the content that goes into file.
Below is my code. I would like to add/remove fields in content writing into file. Any suggestion would be appreciated.
import pino from 'pino'
import pretty from 'pino-pretty'
const streams = [
{stream: pino.destination('logfilePath')},
{stream: pretty({
colorize: true,
sync: true,
messageFormat: `{"job_name":${job_name}, "message":{msg}}`
})}
]
const logger = pino({level: 'info', timestamp: pino.stdTimeFunctions.isoTime}, pino.multistream(streams))
logger.info("execution begins");
Not tested, but it should works according to the code
const prettyOption = { colorize: true, sync: true, messageFormat: `{"job_name":${job_name}, "message":${msg}}` }
const streams = [
// file
{ stream: pretty({ ...prettyOption, destination: 'logfilePath' }) },
// stdout
{ stream: pretty(prettyOption) }
]
Thanks @climba03003 . Do you have any suggestion on how to include/exclude specific fields. Below is how my log looks. I would like to remove fields like 'level','pid'.
{"level":30,"time":"2022-09-22T08:59:50.026Z","pid":111,"hostname":"12abc34","caller":"Object.performcheck ([file:///app/server/jobs/trial/index.js:111:1)","msg":"Executing function"}
Below is the code I am using:
const prettyOption = {
messageFormat: `{"job_name":${job_name}, "message":{msg}}` }
const streams = [
{stream: pretty({ ...prettyOption, destination: logfilePath })},
{stream: pretty({
colorize: true,
sync: true,
messageFormat: `{"job_name":${job_name}, "message":{msg}}`
})}
]
const pinoLogger = pino({level: 'info', timestamp: pino.stdTimeFunctions.isoTime}, pino.multistream(streams))
const log = process.env.NODE_ENV !== 'production' ? pinoCaller(pinoLogger) : pinoLogger
log.info('Executing function');
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.
I am not able to use pino.multistream in my nodejs/typescript project though I am using the latest version of Pino package (8.5.0). I am getting the error - pino.multistream is not a function. Also, when I hover over pino.multistream, I get a pop-up saying "Property 'multistream' does not exist on type 'typeof P'." Can someone please suggest.
Below is my code import pino from 'pino' pino.multistream() --> doesnt work.
However, I am getting following suggestion when I do pino. (dot) Not sure why only multistream doesnt work.
LOG_VERSION default destination extreme final levels stdSerializers stdTimeFunctions symbols version