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

Expose default loglevels #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SebastienGllmt
Copy link

@SebastienGllmt SebastienGllmt commented Dec 14, 2024

tslog comes with some default log levels for info/warn/etc.

The problem is that if you're using tslog with custom log severities, things like log.info may stop working and outputs nothing. See for example below where I have a custom severity that sets INFO=9

const log: Logger<ILogObj> = new Logger({
  minLevel: MyCustomSeverity.INFO, // imagine MyCustomSeverity.INFO = 9
});
log.info("foo"); // this stop working because internally it uses `DefaultLogLevels.INFO = 3` and 3<9

To solve this problem, I have to build a mapping from my custom severity levels to the tslog severities so that my code can look like

const log: Logger<ILogObj> = new Logger({
  minLevel: mapSeverities(MyCustomSeverity.INFO) // maps 9 -> 3
});

However, to create the mapSeverity function, it would be nice to have DefaultLogLevels exposed as an enum from this library

Should this PR be merged

Adding an enum does increase the library size by a few lines of code. If every byte matters, you could argue this isn't worth it for a feature not everybody needs.

I think just the existence of this PR that explains the issue and shows the code may be enough to unblock people who can copy-paste this enum into their own code (and can link to this PR if they want share context on where the enum came from and why it's needed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant