2

I have created a logger instance of bunyan

export const createLogger = (
  appname: string,
) =>
  bunyan.createLogger({
    name: appname,
    streams: [
      {
        level: 'error',
        stream: process.stdout
      },
    ],
  })

After creating the instance of this createLogger, I am adding a stream to the createLogger instance, like this -

export const logs = createLogger(
  appname,
);

logs.addStream({
  name: 'logRequest',
  stream: process.stdout,
  level: 'debug',
});

I just want to be able to use log.logRequest() as a function wherever I require logging. But I keep getting this error that -

Property 'logRequest' does not exist on type 'Logger'

Please suggest an answer.

Aayushi
  • 1,736
  • 1
  • 26
  • 48

1 Answers1

1

You don't use the name of the stream for logging, you use the log level. For instance, use

logs.debug('something went wrong')
logs.fatal('something REALLY went wrong')

Also, if you create the logger at a log level of error, you won't see debug messages, because those are lower in priority. Only log events of a higher priority will be emitted.