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

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

Closed
yaaasuu opened this issue Jan 26, 2024 · 8 comments
Closed

Comments

@yaaasuu
Copy link

yaaasuu commented Jan 26, 2024

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,
      };
    },
  },
@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.

@yaaasuu
Copy link
Author

yaaasuu commented Jan 29, 2024

@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'
}

@mcollina
Copy link
Member

mcollina commented Feb 1, 2024

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.

@mcollina mcollina changed the title cannot get label string in level when I use pino in middleware.ts browser: cannot get label string in level when I use pino in middleware.ts Feb 1, 2024
@KatelynKim
Copy link
Contributor

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!

@yaaasuu
Copy link
Author

yaaasuu commented Feb 26, 2024

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

@mcollina
Copy link
Member

v8.19.0

@yaaasuu
Copy link
Author

yaaasuu commented Feb 27, 2024

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...'
}

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

No branches or pull requests

3 participants