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

pino.multistream is not a function #1552

Closed
pavannarayan05 opened this issue Sep 10, 2022 · 7 comments
Closed

pino.multistream is not a function #1552

pavannarayan05 opened this issue Sep 10, 2022 · 7 comments

Comments

@pavannarayan05
Copy link

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

@mcollina
Copy link
Member

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.

@pavannarayan05
Copy link
Author

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
}

@mcollina
Copy link
Member

The following code runs fine on my system:

import pino from 'pino'

console.log(pino.multistream)

@pavannarayan05
Copy link
Author

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");

@climba03003
Copy link
Contributor

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) }
]

@pavannarayan05
Copy link
Author

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');

@github-actions
Copy link

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 Mar 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants