-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Improve category types #21
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
==========================================
- Coverage 97.24% 97.24% -0.01%
==========================================
Files 10 10
Lines 1018 1016 -2
Branches 217 217
==========================================
- Hits 990 988 -2
Misses 28 28 ☔ View full report in Codecov by Sentry. |
getChild( | ||
subcategory: string | readonly [string] | readonly [string, ...string[]], | ||
): Logger; | ||
getChild(subcategory: Category): Logger; |
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.
We should not allow empty arrays here.
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.
why?
I have a case where I generate category dynamically and it can be empty. In the case of this lib there is no real difference between returning current logger from getChild or returning a child as new instance. We just need to get the correct logger.
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.
In my fork I even made that if a category is empty string, empty array, null or undefined then it will return current logger instead of new child
Seems ok by me)
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.
I think it's misleading that the method name is getChild()
but the object returned is clearly not a child logger, and I don't want the signature of the method to change. 🤔
logtape/logger.ts
Outdated
private constructor(parent: LoggerImpl | null, category: readonly string[]) { | ||
constructor(parent: LoggerImpl | null, category: CategoryList) { |
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.
Why did you remove the private
keyword?
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.
was playing with class inheritance. this can be rolled back
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.
done
| string | ||
| readonly [string] | ||
| readonly [string, ...(readonly string[])], | ||
subcategory: Category, |
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.
We should not allow empty arrays here.
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.
same as above
@@ -692,7 +686,7 @@ export class LoggerCtx implements Logger { | |||
} | |||
|
|||
getChild( | |||
subcategory: string | readonly [string] | readonly [string, ...string[]], | |||
subcategory: Category, |
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.
We should not allow empty arrays here.
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.
same as above
logtape/category.ts
Outdated
export type CategoryList = Readonly<string[]>; | ||
|
||
export type Category = string | CategoryList; |
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.
Could you add TSDoc comments for those two types?
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.
done
No description provided.