Skip to content

Conversation

@mmustafa-tse
Copy link
Contributor

Summary

  • Migrate Logger from JS to TS

Testing Plan

  • Was this tested locally? If not, explain why.
  • E2E and unit tested

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

@sonarqubecloud
Copy link

verbose: (msg: string) => void;
warning: (msg: string) => void;
error: (msg: string) => void;
setLogLevel: (msg: string) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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';
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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);
            }
        }
    };

@gtamanaha
Copy link

Question: Curious why are you targeting mParticle:developmentinstead of development. Is there any particular reason?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants