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

Forbid using default log levels when useOnlyCustomLevels: true #1998

Closed
chernodub opened this issue Jul 1, 2024 · 3 comments · Fixed by #1999
Closed

Forbid using default log levels when useOnlyCustomLevels: true #1998

chernodub opened this issue Jul 1, 2024 · 3 comments · Fixed by #1999

Comments

@chernodub
Copy link
Contributor

Currently, pino's TS declaration allows using default log levels when useOnlyCustomLevels is true. This following code will result in a runtime error:

import { pino } from 'pino';

const logger = pino({
  customLevels: { customInfo: 10 },
  useOnlyCustomLevels: true,
});

logger.info('123'); // TS should warn here ?
logger.customInfo('123'); // should work fine

Expected behavior:

import { pino } from 'pino';

const logger = pino({
  customLevels: { customInfo: 10 },
  useOnlyCustomLevels: true,
});

logger.info('123'); // TS errors here
logger.customInfo('123'); // works fine
@mcollina
Copy link
Member

mcollina commented Jul 2, 2024

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. We use tsd for the types.

@chernodub
Copy link
Contributor Author

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. We use tsd for the types.

Yep, already submitted the PR #1999 :)

mcollina added a commit that referenced this issue Aug 21, 2024
#1999)

* feat(types): forbid using default log fn when custom only used

* test: move types test to tsd file

* feat: allow overriding default levels

---------

Co-authored-by: Matteo Collina <hello@matteocollina.com>
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 Sep 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants