pinojs/pino

browser: cannot get label string in level when I use pino in middleware.ts

Closed this issue · 8 comments

Thank you for useful library.
Although I want to indicate a label of level in logs(e.g. "level":"info"), I could not get the string (I can get number like level: 30) .
I check your document and write like below and it works in api.
I wonder why it is not available for middleware.

  formatters: {
    level: (label: string) => {
      return {
        level: label,
      };
    },
  },

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.

@mcollina
Sorry for late replaying.
I prepare test source.

I got like the following log.

{
time: ',"timestamp":"2024/1/29 9:10:44"',
level: 30,
msg: 'start middleware.info'
}

It's not available in middleware because middlewares run in a non-Node.js environment, so pino uses its browser implementation, that lacks this feature.

A PR to add it would be amazing.

It's not available in middleware because middlewares run in a non-Node.js environment, so pino uses its browser implementation, that lacks this feature.

A PR to add it would be amazing.

Hello, I just opened up a PR for this! Could you take a look please? 👀 Thank you!

Hello, I update pino latest version.
But I cannot get the above result. Could you tell me when #1898 is added?

v8.19.0

Although my pino version is already 8.19.0 and write like the following, log level is a number yet, like level: 30.

import pino from 'pino'

const logger = pino({ 
  browser: {
    formatters: {
      level (label, number) {
        return { label, level: number}
      }
    }
  }
})

export default logger
{
  time: ',"timestamp":"2024/2/27 15:59:06"',
  level: 30,
  msg: 'start middleware.info...'
}

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.