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

Error: levels cannot be overridden #507

Closed
kilianc opened this issue Aug 29, 2018 · 13 comments
Closed

Error: levels cannot be overridden #507

kilianc opened this issue Aug 29, 2018 · 13 comments

Comments

@kilianc
Copy link

kilianc commented Aug 29, 2018

I was wondering what was the reasoning behind this. We're trying to configure the logger with the stackdriver levels.

info and debug are at the moment not configurable.

cc/ @Arun4rangan

@mcollina
Copy link
Member

I do not understand. Can you please make an example with code with what would you like to do, and what is currently throwing?

@kilianc
Copy link
Author

kilianc commented Aug 30, 2018

@Arun4rangan do you mind jumping in with the snippet?

@kilianc
Copy link
Author

kilianc commented Aug 31, 2018

@mcollina this currently throws:

new Pino({
  default: 0,
  debug: 100,
  info: 200,
  notice: 300,
  warning: 400,
  error: 500,
  critical: 600,
  alert: 700,
  emergency: 800
})

@mcollina
Copy link
Member

What is it throwing, and what are you expecting that to do?

@kilianc
Copy link
Author

kilianc commented Aug 31, 2018

..../node_modules/pino/lib/levels.js:119
      throw Error('levels cannot be overridden')
      ^

Error: levels cannot be overridden
    at assertNoLevelCollisions (..../node_modules/pino/lib/levels.js:119:13)
    at new pino (..../node_modules/pino/pino.js:69:3)
    at Object.<anonymous> (..../lib/logger.js:6:18)

Expected behavior is to use my levels and discard default ones.

@mcollina
Copy link
Member

That is not possible. You might want to send a PR for that and add a new option.

@cberg-zalando
Copy link
Contributor

We are storing our logs in Scalyr, which does not suport pino's log levels by default. I was really excited to see, that with #515 it is possible to allow to overwrite the levels being provided. Or at least I thought so.

From the description of the new useOnlyCustomLevels configuration option it sounds as if you can also redefine what pino uses for its standard levels, but this isn't the case.

I created a small test case

test('default levels can be redefined using custom levels', async ({ is }) => {
  const stream = sink()
  const logger = pino({
    customLevels: {
      info: 35
    },
    useOnlyCustomLevels: true
  }, stream)

  logger.info('test')
  const { priority } = await once(stream, 'data')
  is(priority, 35)
})

which fails as pino still uses its default value of 30 for the priority.

The cause of this is that the isStandardLevel function in levels.js does not take the useOnlyCustomLevels into account happily returns true as it is indeed a standard level.

@mcollina
Copy link
Member

Would you like to send a PR with a fix?

@cberg-zalando
Copy link
Contributor

@mcollina Actually, I already tried this morning, but it didn't work out. So I could open a WIP PR and you might have an idea why my the code I wrote is actually not doing what it should. If this approach is fine with you.

@mcollina
Copy link
Member

mcollina commented Sep 28, 2018 via email

@cberg-zalando
Copy link
Contributor

@kilianc Do the changes done in #515 and #522 should suffice to consider this issue as done?

@davidmarkclements
Copy link
Member

closes by #515 and #522

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

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 Feb 8, 2022
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

4 participants