-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #3040 - Add KetcherLogger * #3040 - Add default logInfo * #3040 - Raname variables and add default logging settings * #3040 - Rename variables * #3040 - Apply suggestions from reviews
- Loading branch information
Showing
45 changed files
with
314 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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,84 @@ | ||
export enum LogLevel { | ||
ERROR = 0, | ||
WARN = 1, | ||
INFO = 2, | ||
LOG = 3, | ||
} | ||
|
||
export interface LogSettings { | ||
enabled?: boolean; | ||
showTrace?: boolean; | ||
level?: LogLevel; | ||
} | ||
|
||
export class KetcherLogger { | ||
static get settings(): LogSettings { | ||
if (!window?.ketcher) { | ||
throw new Error( | ||
'Ketcher needs to be initialized before KetcherLogger is used', | ||
); | ||
} | ||
|
||
return window.ketcher.logging; | ||
} | ||
|
||
static set settings(newSettings: LogSettings) { | ||
for (const [settingName, settingValue] of Object.entries(newSettings)) { | ||
this.settings[settingName] = settingValue; | ||
} | ||
} | ||
|
||
static log(...messages: unknown[]): void { | ||
if (!this.isMinimumLogLevel(LogLevel.LOG)) { | ||
return; | ||
} | ||
|
||
const { showTrace } = this.settings; | ||
|
||
if (showTrace) { | ||
window.console.trace(messages); | ||
} else { | ||
window.console.log(messages); | ||
} | ||
} | ||
|
||
static info(...messages: unknown[]): void { | ||
if (!this.isMinimumLogLevel(LogLevel.INFO)) { | ||
return; | ||
} | ||
|
||
const { showTrace } = this.settings; | ||
|
||
if (showTrace) { | ||
window.console.trace(messages); | ||
} else { | ||
window.console.info(messages); | ||
} | ||
} | ||
|
||
static warn(...warnings: unknown[]): void { | ||
if (!this.isMinimumLogLevel(LogLevel.WARN)) { | ||
return; | ||
} | ||
|
||
window.console.warn(warnings); | ||
} | ||
|
||
static error(...errors: unknown[]): void { | ||
if (!this.isMinimumLogLevel(LogLevel.ERROR)) { | ||
return; | ||
} | ||
|
||
window.console.error(errors); | ||
} | ||
|
||
private static isMinimumLogLevel(minimumLevel: LogLevel): boolean { | ||
const { enabled, level } = this.settings; | ||
|
||
if (!enabled || level == null) { | ||
return false; | ||
} | ||
|
||
return level >= minimumLevel; | ||
} | ||
} |
This file contains 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 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.