aboutsummaryrefslogtreecommitdiff
path: root/ext/js/yomichan.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-14 17:52:01 -0500
committerGitHub <noreply@github.com>2021-02-14 17:52:01 -0500
commit9279ced68660610764931da681f22c8b71bf1b6e (patch)
tree2a4d015cf57adfe74af72615bad19c9308388e99 /ext/js/yomichan.js
parent286534e648af350d24fbf3c7892a7ec81aaeb4bd (diff)
Log refactoring (#1393)
* Create Logger class and log instance * Replace yomichan.logWarning with log.warn * Replace yomichan.logError with log.error * Replace yomichan.log with log.log * Update the Yomichan class to use the global log object * Update lint rules
Diffstat (limited to 'ext/js/yomichan.js')
-rw-r--r--ext/js/yomichan.js64
1 files changed, 1 insertions, 63 deletions
diff --git a/ext/js/yomichan.js b/ext/js/yomichan.js
index 73deeab9..107694e9 100644
--- a/ext/js/yomichan.js
+++ b/ext/js/yomichan.js
@@ -103,7 +103,7 @@ class Yomichan extends EventDispatcher {
this.sendMessage({action: 'requestBackendReadySignal'});
await this._isBackendReadyPromise;
- this.on('log', this._onForwardLog.bind(this));
+ log.on('log', this._onForwardLog.bind(this));
}
}
@@ -156,68 +156,6 @@ class Yomichan extends EventDispatcher {
});
}
- logWarning(error) {
- this.log(error, 'warn');
- }
-
- logError(error) {
- this.log(error, 'error');
- }
-
- log(error, level, context=null) {
- if (!isObject(context)) {
- context = this._getLogContext();
- }
-
- let errorString;
- try {
- errorString = error.toString();
- if (/^\[object \w+\]$/.test(errorString)) {
- errorString = JSON.stringify(error);
- }
- } catch (e) {
- errorString = `${error}`;
- }
-
- let errorStack;
- try {
- errorStack = (typeof error.stack === 'string' ? error.stack.trimRight() : '');
- } catch (e) {
- errorStack = '';
- }
-
- let errorData;
- try {
- errorData = error.data;
- } catch (e) {
- // NOP
- }
-
- if (errorStack.startsWith(errorString)) {
- errorString = errorStack;
- } else if (errorStack.length > 0) {
- errorString += `\n${errorStack}`;
- }
-
- let message = `${this._extensionName} has encountered a problem.`;
- message += `\nOriginating URL: ${context.url}\n`;
- message += errorString;
- if (typeof errorData !== 'undefined') {
- message += `\nData: ${JSON.stringify(errorData, null, 4)}`;
- }
- message += '\n\nIssues can be reported at https://github.com/FooSoft/yomichan/issues';
-
- switch (level) {
- case 'info': console.info(message); break;
- case 'debug': console.debug(message); break;
- case 'warn': console.warn(message); break;
- case 'error': console.error(message); break;
- default: console.log(message); break;
- }
-
- this.trigger('log', {error, level, context});
- }
-
sendMessage(...args) {
try {
return chrome.runtime.sendMessage(...args);