-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Migrate Logger to Typescript #1120
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9aeb98c
feat: Migrate Logger to Typescript
gtamanaha ef26f36
refactor: Change Logger export to named export
gtamanaha 59084e0
refactor: Remove Logger implementation and related ConsoleLogger class
gtamanaha d08805f
refactor: Update Logger import to named export in multiple files
gtamanaha 2bac35c
refactor: Use nullish coalescing operator for logLevel and logger ini…
gtamanaha e7c10ee
refactor: Update logging calls to use the new Logger instance directly
gtamanaha 5c3f846
refactor: Simplify logging calls by directly using the Logger instanc…
gtamanaha 771e011
refactor: Optimize Logger methods to return early for None log level …
gtamanaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { LogLevelType, SDKInitConfig, SDKLoggerApi } from './sdkRuntimeModels'; | ||
|
|
||
| export type ILoggerConfig = Pick<SDKInitConfig, 'logLevel' | 'logger'>; | ||
| export type IConsoleLogger = Partial<Pick<SDKLoggerApi, 'error' | 'warning' | 'verbose'>>; | ||
|
|
||
| export class Logger { | ||
| private logLevel: LogLevelType; | ||
| private logger: IConsoleLogger; | ||
|
|
||
| constructor(config: ILoggerConfig) { | ||
| this.logLevel = config.logLevel ?? LogLevelType.Warning; | ||
| this.logger = config.logger ?? new ConsoleLogger(); | ||
| } | ||
|
|
||
| public verbose(msg: string): void { | ||
| if(this.logLevel === LogLevelType.None) | ||
| return; | ||
|
|
||
| if (this.logger.verbose && this.logLevel === LogLevelType.Verbose) { | ||
| this.logger.verbose(msg); | ||
| } | ||
| } | ||
|
|
||
| public warning(msg: string): void { | ||
| if(this.logLevel === LogLevelType.None) | ||
| return; | ||
|
|
||
| if (this.logger.warning && | ||
| (this.logLevel === LogLevelType.Verbose || this.logLevel === LogLevelType.Warning)) { | ||
| this.logger.warning(msg); | ||
| } | ||
| } | ||
|
|
||
| public error(msg: string): void { | ||
| if(this.logLevel === LogLevelType.None) | ||
| return; | ||
|
|
||
| if (this.logger.error) { | ||
| this.logger.error(msg); | ||
| } | ||
| } | ||
|
|
||
| public setLogLevel(newLogLevel: LogLevelType): void { | ||
| this.logLevel = newLogLevel; | ||
| } | ||
| } | ||
|
|
||
| export class ConsoleLogger implements IConsoleLogger { | ||
| public verbose(msg: string): void { | ||
| if (console && console.info) { | ||
| console.info(msg); | ||
| } | ||
| } | ||
|
|
||
| public error(msg: string): void { | ||
| if (console && console.error) { | ||
| console.error(msg); | ||
| } | ||
| } | ||
|
|
||
| public warning(msg: string): void { | ||
| if (console && console.warn) { | ||
| console.warn(msg); | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.