Add Typescript support for custom log levels#2349
Open
eschablowski wants to merge 7 commits intowinstonjs:masterfrom
Open
Add Typescript support for custom log levels#2349eschablowski wants to merge 7 commits intowinstonjs:masterfrom
eschablowski wants to merge 7 commits intowinstonjs:masterfrom
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
Contributor
|
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.
[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.
mind that custom log levels still break application-insights instrumentation translating them to the correct appinsights severities.
jayden-chan
added a commit
to saasquatch/program-tools
that referenced
this pull request
Mar 5, 2024
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.
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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