-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Migrate Logger to TypeScript #1055
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
base: development
Are you sure you want to change the base?
Conversation
|
| verbose: (msg: string) => void; | ||
| warning: (msg: string) => void; | ||
| error: (msg: string) => void; | ||
| setLogLevel: (msg: string) => void; |
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.
| setLogLevel: (msg: string) => void; | |
| setLogLevel: (logLevel: string) => void; |
| function Logger(this: Logger, config: SDKInitConfig): void { | ||
| var self = this; | ||
| var logLevel = config.logLevel || 'warning'; | ||
| var logLevel: string = config.logLevel || 'warning'; |
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.
You should use let and const in this file instead of var.
| this.setLogLevel = function(newLogLevel) { | ||
| this.setLogLevel = function(newLogLevel: string) { | ||
| logLevel = newLogLevel; | ||
| this.logLevel = logLevel; |
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 you should be able to get rid of the redundant assignment and simplify this:
this.setLogLevel = function(_logLevel: string) {
this.logLevel = _logLevel;
| verbose: (msg: string) => void; | ||
| warning: (msg: string) => void; | ||
| error: (msg: string) => void; | ||
| setLogLevel: (msg: string) => void; |
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.
Also, you should create a type definition for log level. For example:
type LogLevelType = 'none' | 'verbose' | 'warning' | 'error';
| } | ||
|
|
||
| this.verbose = function(msg) { | ||
| this.verbose = function(msg: string) { |
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.
Can we try replacing this with arrow functions?
this.verbose = (msg: string) => {
if (logLevel === 'verbose') {
this.logger.verbose?.(msg);
}
};
| }; | ||
|
|
||
| this.warning = function(msg) { | ||
| this.warning = function(msg: string) { |
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.
Can we trying using arrow function here too?
this.warning = (msg: string) => {
if (logLevel !== 'none') {
if (
this.logger.warning &&
(logLevel === 'verbose' || logLevel === 'warning')
) {
this.logger.warning(msg);
}
}
};
|
Question: Curious why are you targeting |



Summary
Testing Plan
Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)