tslog
tslog copied to clipboard
Expose default loglevels
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)