Skip to content

feat: Migrate Logger to TypeScript#1055

Closed
mmustafa-tse wants to merge 2 commits into
mParticle:developmentfrom
mmustafa-tse:feat/loggerTS
Closed

feat: Migrate Logger to TypeScript#1055
mmustafa-tse wants to merge 2 commits into
mParticle:developmentfrom
mmustafa-tse:feat/loggerTS

Conversation

@mmustafa-tse

Copy link
Copy Markdown
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
Copy Markdown

Comment thread src/logger.ts
verbose: (msg: string) => void;
warning: (msg: string) => void;
error: (msg: string) => void;
setLogLevel: (msg: string) => void;

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

Comment thread src/logger.ts
function Logger(this: Logger, config: SDKInitConfig): void {
var self = this;
var logLevel = config.logLevel || 'warning';
var logLevel: string = config.logLevel || 'warning';

Copy link
Copy Markdown
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.

Comment thread src/logger.ts
this.setLogLevel = function(newLogLevel) {
this.setLogLevel = function(newLogLevel: string) {
logLevel = newLogLevel;
this.logLevel = logLevel;

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

Comment thread src/logger.ts
verbose: (msg: string) => void;
warning: (msg: string) => void;
error: (msg: string) => void;
setLogLevel: (msg: string) => void;

Copy link
Copy Markdown
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';

Comment thread src/logger.ts
}

this.verbose = function(msg) {
this.verbose = function(msg: string) {

Copy link
Copy Markdown
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);
    }
};

Comment thread src/logger.ts
};

this.warning = function(msg) {
this.warning = function(msg: string) {

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@rmi22186 rmi22186 force-pushed the development branch 5 times, most recently from 905641c to b16bdd2 Compare December 10, 2025 21:07
@rmi22186

Copy link
Copy Markdown
Member

Since #1120 was merged, this can be closed, right @gtamanaha ?

@gtamanaha

Copy link
Copy Markdown
Contributor

Since #1120 was merged, this can be closed, right @gtamanaha ?

Yes, lets close this one.

@gtamanaha gtamanaha closed this Jan 13, 2026
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.

5 participants