-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add Typescript support for custom log levels #2349
base: master
Are you sure you want to change the base?
Add Typescript support for custom log levels #2349
Conversation
This update removes the "standard" utility method definitions to log to the defined log levels, and check whether they are activated and replaces them with mapped types. This change allows for better intellisense, as well as more rigorous type checking in typescript
This is a fix to get the actual `is<Loglevel>Enabled`, which was a bug in the previous commit
…n previous commits
This looks cool! I'm wondering about semver though. If this forces users to use a newer TS version, should this go into a major release for winston? Or what is the minimum TS version that winston is requiring right now? I recall there being some earlier discussion around us forcing users to migrate to a newer TS version, but I don't remember where those discussions ended up. |
http: LeveledLogMethod; | ||
verbose: LeveledLogMethod; | ||
input: LeveledLogMethod; | ||
silly: LeveledLogMethod; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[key in T]: LeveledLogMethod;
should declare the respective methods for immediate use.
Might make sense to have the levels with their respective numbers as Type parameter:
interface LoggerBase<Levels extends AbstractConfigSetLevels> {
[key in keyof Levels]: LeveledLogMethod;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind that custom log levels still break application-insights instrumentation translating them to the correct appinsights severities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eschablowski thoughts?
Winston 3.12 introduced a breaking change which makes using syslog log levels with TypeScript impossible: winstonjs/winston@c3c3911 A fix is currently in progress but it has not been merged yet: winstonjs/winston#2349 In the meantime, the peer dependency for Winston will be updated to prevent consumers from installing the incompatible version.
This is a small change in the typescript types that allows for the automatic detection of log levels (including custom log levels).
Breaking Changes
To Do
Create a bigger test suite for TypeScript types(many other, dependent types are incompatible already)Test on more TS versions(Not required, as per the previous todo makes this obsolete)Fixes