summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.eslintrc.json5
-rw-r--r--ext/js/accessibility/accessibility-controller.js2
-rw-r--r--ext/js/app/frontend.js2
-rw-r--r--ext/js/app/popup-proxy.js2
-rw-r--r--ext/js/application.js24
-rw-r--r--ext/js/background/backend.js21
-rw-r--r--ext/js/background/background-main.js2
-rw-r--r--ext/js/comm/api.js12
-rw-r--r--ext/js/comm/cross-frame-api.js2
-rw-r--r--ext/js/core/log-utilities.js28
-rw-r--r--ext/js/core/log.js (renamed from ext/js/core/logger.js)103
-rw-r--r--ext/js/dictionary/dictionary-database.js2
-rw-r--r--ext/js/dictionary/dictionary-worker-main.js2
-rw-r--r--ext/js/display/display-anki.js4
-rw-r--r--ext/js/display/display.js5
-rw-r--r--ext/js/display/query-parser.js2
-rw-r--r--ext/js/extension/web-extension.js13
-rw-r--r--ext/js/general/task-accumulator.js2
-rw-r--r--ext/js/language/text-scanner.js2
-rw-r--r--ext/js/pages/settings/anki-controller.js5
-rw-r--r--ext/js/pages/settings/backup-controller.js20
-rw-r--r--ext/js/pages/settings/dictionary-controller.js2
-rw-r--r--ext/js/pages/settings/dictionary-import-controller.js2
-rw-r--r--types/ext/api.d.ts2
-rw-r--r--types/ext/log.d.ts12
25 files changed, 143 insertions, 135 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index a5f0f85e..b8dcaa77 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -584,7 +584,7 @@
"ext/js/core/event-dispatcher.js",
"ext/js/core/extension-error.js",
"ext/js/core/json.js",
- "ext/js/core/logger.js",
+ "ext/js/core/log.js",
"ext/js/core/to-error.js",
"ext/js/core/utilities.js",
"ext/js/data/database.js",
@@ -619,7 +619,8 @@
"ext/js/core/extension-error.js",
"ext/js/core/fetch-utilities.js",
"ext/js/core/json.js",
- "ext/js/core/logger.js",
+ "ext/js/core/log-utilities.js",
+ "ext/js/core/log.js",
"ext/js/core/to-error.js",
"ext/js/core/utilities.js",
"ext/js/data/anki-util.js",
diff --git a/ext/js/accessibility/accessibility-controller.js b/ext/js/accessibility/accessibility-controller.js
index b2785893..0412b337 100644
--- a/ext/js/accessibility/accessibility-controller.js
+++ b/ext/js/accessibility/accessibility-controller.js
@@ -17,7 +17,7 @@
*/
import {isContentScriptRegistered, registerContentScript, unregisterContentScript} from '../background/script-manager.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
/**
* This class controls the registration of accessibility handlers.
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js
index 1a3fbbe1..9c4778cc 100644
--- a/ext/js/app/frontend.js
+++ b/ext/js/app/frontend.js
@@ -18,7 +18,7 @@
import {createApiMap, invokeApiMapHandler} from '../core/api-map.js';
import {EventListenerCollection} from '../core/event-listener-collection.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {promiseAnimationFrame} from '../core/promise-animation-frame.js';
import {DocumentUtil} from '../dom/document-util.js';
import {TextSourceElement} from '../dom/text-source-element.js';
diff --git a/ext/js/app/popup-proxy.js b/ext/js/app/popup-proxy.js
index 3632b8cb..910b2f06 100644
--- a/ext/js/app/popup-proxy.js
+++ b/ext/js/app/popup-proxy.js
@@ -17,7 +17,7 @@
*/
import {EventDispatcher} from '../core/event-dispatcher.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
/**
* This class is a proxy for a Popup that is hosted in a different frame.
diff --git a/ext/js/application.js b/ext/js/application.js
index 7a2f216c..350a4210 100644
--- a/ext/js/application.js
+++ b/ext/js/application.js
@@ -21,7 +21,7 @@ import {CrossFrameAPI} from './comm/cross-frame-api.js';
import {createApiMap, invokeApiMapHandler} from './core/api-map.js';
import {EventDispatcher} from './core/event-dispatcher.js';
import {ExtensionError} from './core/extension-error.js';
-import {log} from './core/logger.js';
+import {log} from './core/log.js';
import {deferPromise} from './core/utilities.js';
import {WebExtension} from './extension/web-extension.js';
@@ -63,19 +63,8 @@ export class Application extends EventDispatcher {
*/
constructor(api, crossFrameApi) {
super();
-
/** @type {WebExtension} */
this._webExtension = new WebExtension();
-
- /** @type {string} */
- this._extensionName = 'Yomitan';
- try {
- const manifest = chrome.runtime.getManifest();
- this._extensionName = `${manifest.name} v${manifest.version}`;
- } catch (e) {
- // NOP
- }
-
/** @type {?boolean} */
this._isBackground = null;
/** @type {API} */
@@ -84,7 +73,6 @@ export class Application extends EventDispatcher {
this._crossFrame = crossFrameApi;
/** @type {boolean} */
this._isReady = false;
-
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {import('application').ApiMap} */
this._apiMap = createApiMap([
@@ -139,7 +127,7 @@ export class Application extends EventDispatcher {
*/
prepare() {
chrome.runtime.onMessage.addListener(this._onMessage.bind(this));
- log.on('log', this._onForwardLog.bind(this));
+ log.on('logGenericError', this._onLogGenericError.bind(this));
}
/**
@@ -167,6 +155,7 @@ export class Application extends EventDispatcher {
*/
static async main(mainFunction) {
const webExtension = new WebExtension();
+ log.configure(webExtension.extensionName);
const api = new API(webExtension);
await this.waitForBackendReady(webExtension);
const {tabId, frameId} = await api.frameInformationGet();
@@ -243,12 +232,11 @@ export class Application extends EventDispatcher {
}
/**
- * @param {{error: unknown, level: import('log').LogLevel, context?: import('log').LogContext}} params
+ * @param {import('log').Events['logGenericError']} params
*/
- async _onForwardLog({error, level, context}) {
+ async _onLogGenericError({error, level, context}) {
try {
- const api = /** @type {API} */ (this._api);
- await api.log(ExtensionError.serialize(error), level, context);
+ await this._api.logGenericErrorBackend(ExtensionError.serialize(error), level, context);
} catch (e) {
// NOP
}
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index ccd828f6..f301b4c6 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -24,7 +24,8 @@ import {Mecab} from '../comm/mecab.js';
import {createApiMap, invokeApiMapHandler} from '../core/api-map.js';
import {ExtensionError} from '../core/extension-error.js';
import {fetchJson, fetchText} from '../core/fetch-utilities.js';
-import {log} from '../core/logger.js';
+import {logErrorLevelToNumber} from '../core/log-utilities.js';
+import {log} from '../core/log.js';
import {clone, deferPromise, isObject, promiseTimeout} from '../core/utilities.js';
import {isNoteDataValid} from '../data/anki-util.js';
import {OptionsUtil} from '../data/options-util.js';
@@ -172,7 +173,7 @@ export class Backend {
['getDictionaryInfo', this._onApiGetDictionaryInfo.bind(this)],
['purgeDatabase', this._onApiPurgeDatabase.bind(this)],
['getMedia', this._onApiGetMedia.bind(this)],
- ['log', this._onApiLog.bind(this)],
+ ['logGenericErrorBackend', this._onApiLogGenericErrorBackend.bind(this)],
['logIndicatorClear', this._onApiLogIndicatorClear.bind(this)],
['modifySettings', this._onApiModifySettings.bind(this)],
['getSettings', this._onApiGetSettings.bind(this)],
@@ -265,7 +266,7 @@ export class Backend {
}, 1000);
this._updateBadge();
- log.on('log', this._onLog.bind(this));
+ log.on('logGenericError', this._onLogGenericError.bind(this));
await this._requestBuilder.prepare();
await this._environment.prepare();
@@ -334,11 +335,11 @@ export class Backend {
}
/**
- * @param {{level: import('log').LogLevel}} params
+ * @param {import('log').Events['logGenericError']} params
*/
- _onLog({level}) {
- const levelValue = log.getLogErrorLevelValue(level);
- const currentLogErrorLevel = this._logErrorLevel !== null ? log.getLogErrorLevelValue(this._logErrorLevel) : 0;
+ _onLogGenericError({level}) {
+ const levelValue = logErrorLevelToNumber(level);
+ const currentLogErrorLevel = this._logErrorLevel !== null ? logErrorLevelToNumber(this._logErrorLevel) : 0;
if (levelValue <= currentLogErrorLevel) { return; }
this._logErrorLevel = level;
@@ -741,9 +742,9 @@ export class Backend {
return await this._getNormalizedDictionaryDatabaseMedia(targets);
}
- /** @type {import('api').ApiHandler<'log'>} */
- _onApiLog({error, level, context}) {
- log.log(ExtensionError.deserialize(error), level, context);
+ /** @type {import('api').ApiHandler<'logGenericErrorBackend'>} */
+ _onApiLogGenericErrorBackend({error, level, context}) {
+ log.logGenericError(ExtensionError.deserialize(error), level, context);
}
/** @type {import('api').ApiHandler<'logIndicatorClear'>} */
diff --git a/ext/js/background/background-main.js b/ext/js/background/background-main.js
index 0f1ddeeb..b7e45cd1 100644
--- a/ext/js/background/background-main.js
+++ b/ext/js/background/background-main.js
@@ -16,12 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {log} from '../core/log.js';
import {WebExtension} from '../extension/web-extension.js';
import {Backend} from './backend.js';
/** Entry point. */
async function main() {
const webExtension = new WebExtension();
+ log.configure(webExtension.extensionName);
const backend = new Backend(webExtension);
await backend.prepare();
diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js
index 40b8e252..f07702da 100644
--- a/ext/js/comm/api.js
+++ b/ext/js/comm/api.js
@@ -253,13 +253,13 @@ export class API {
}
/**
- * @param {import('api').ApiParam<'log', 'error'>} error
- * @param {import('api').ApiParam<'log', 'level'>} level
- * @param {import('api').ApiParam<'log', 'context'>} context
- * @returns {Promise<import('api').ApiReturn<'log'>>}
+ * @param {import('api').ApiParam<'logGenericErrorBackend', 'error'>} error
+ * @param {import('api').ApiParam<'logGenericErrorBackend', 'level'>} level
+ * @param {import('api').ApiParam<'logGenericErrorBackend', 'context'>} context
+ * @returns {Promise<import('api').ApiReturn<'logGenericErrorBackend'>>}
*/
- log(error, level, context) {
- return this._invoke('log', {error, level, context});
+ logGenericErrorBackend(error, level, context) {
+ return this._invoke('logGenericErrorBackend', {error, level, context});
}
/**
diff --git a/ext/js/comm/cross-frame-api.js b/ext/js/comm/cross-frame-api.js
index 33a91c89..45ea268f 100644
--- a/ext/js/comm/cross-frame-api.js
+++ b/ext/js/comm/cross-frame-api.js
@@ -21,7 +21,7 @@ import {EventDispatcher} from '../core/event-dispatcher.js';
import {EventListenerCollection} from '../core/event-listener-collection.js';
import {ExtensionError} from '../core/extension-error.js';
import {parseJson} from '../core/json.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
/**
* @augments EventDispatcher<import('cross-frame-api').CrossFrameAPIPortEvents>
diff --git a/ext/js/core/log-utilities.js b/ext/js/core/log-utilities.js
new file mode 100644
index 00000000..b7e0c914
--- /dev/null
+++ b/ext/js/core/log-utilities.js
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2024 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @param {import('log').LogLevel} errorLevel
+ * @returns {number}
+ */
+export function logErrorLevelToNumber(errorLevel) {
+ switch (errorLevel) {
+ case 'warn': return 1;
+ case 'error': return 2;
+ default: return 0;
+ }
+}
diff --git a/ext/js/core/logger.js b/ext/js/core/log.js
index 6cf1cc1f..8401cc2b 100644
--- a/ext/js/core/logger.js
+++ b/ext/js/core/log.js
@@ -20,35 +20,59 @@ import {EventDispatcher} from './event-dispatcher.js';
import {ExtensionError} from './extension-error.js';
/**
- * This class handles logging of messages to the console and triggering
- * an event for log calls.
+ * This class handles logging of messages to the console and triggering an event for log calls.
* @augments EventDispatcher<import('log').Events>
*/
-export class Logger extends EventDispatcher {
- /**
- * Creates a new instance.
- */
+class Logger extends EventDispatcher {
constructor() {
super();
/** @type {string} */
- this._extensionName = 'Yomitan';
- try {
- const {name, version} = chrome.runtime.getManifest();
- this._extensionName = `${name} ${version}`;
- } catch (e) {
- // NOP
- }
+ this._extensionName = 'Extension';
+ /** @type {?string} */
+ this._issueUrl = 'https://github.com/themoeway/yomitan/issues';
+ }
+
+ /**
+ * @param {string} extensionName
+ */
+ configure(extensionName) {
+ this._extensionName = extensionName;
+ }
+
+ /**
+ * @param {unknown} message
+ * @param {...unknown} optionalParams
+ */
+ log(message, ...optionalParams) {
+ /* eslint-disable no-console */
+ console.log(message, ...optionalParams);
+ /* eslint-enable no-console */
+ }
+
+ /**
+ * Logs a warning.
+ * @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
+ */
+ warn(error) {
+ this.logGenericError(error, 'warn');
}
/**
- * Logs a generic error. This will trigger the 'log' event with the same arguments as the function invocation.
+ * Logs an error.
* @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
- * @param {import('log').LogLevel} level The level to log at. Values include `'info'`, `'debug'`, `'warn'`, and `'error'`.
- * Other values will be logged at a non-error level.
- * @param {?import('log').LogContext} [context] An optional context object for the error which should typically include a `url` field.
*/
- log(error, level, context = null) {
- if (typeof context !== 'object' || context === null) {
+ error(error) {
+ this.logGenericError(error, 'error');
+ }
+
+ /**
+ * Logs a generic error.
+ * @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
+ * @param {import('log').LogLevel} level
+ * @param {import('log').LogContext} [context]
+ */
+ logGenericError(error, level, context) {
+ if (typeof context === 'undefined') {
context = {url: location.href};
}
@@ -103,52 +127,19 @@ export class Logger extends EventDispatcher {
if (typeof errorData !== 'undefined') {
message += `\nData: ${JSON.stringify(errorData, null, 4)}`;
}
- message += '\n\nIssues can be reported at https://github.com/themoeway/yomitan/issues';
+ if (this._issueUrl !== null) {
+ message += `\n\nIssues can be reported at ${this._issueUrl}`;
+ }
/* eslint-disable no-console */
switch (level) {
case 'log': console.log(message); break;
- case 'info': console.info(message); break;
- case 'debug': console.debug(message); break;
case 'warn': console.warn(message); break;
case 'error': console.error(message); break;
}
/* eslint-enable no-console */
- this.trigger('log', {error, level, context});
- }
-
- /**
- * Logs a warning. This function invokes `log` internally.
- * @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
- * @param {?import('log').LogContext} context An optional context object for the error which should typically include a `url` field.
- */
- warn(error, context = null) {
- this.log(error, 'warn', context);
- }
-
- /**
- * Logs an error. This function invokes `log` internally.
- * @param {unknown} error The error to log. This is typically an `Error` or `Error`-like object.
- * @param {?import('log').LogContext} context An optional context object for the error which should typically include a `url` field.
- */
- error(error, context = null) {
- this.log(error, 'error', context);
- }
-
- /**
- * @param {import('log').LogLevel} errorLevel
- * @returns {import('log').LogErrorLevelValue}
- */
- getLogErrorLevelValue(errorLevel) {
- switch (errorLevel) {
- case 'log':
- case 'info':
- case 'debug':
- return 0;
- case 'warn': return 1;
- case 'error': return 2;
- }
+ this.trigger('logGenericError', {error, level, context});
}
}
diff --git a/ext/js/dictionary/dictionary-database.js b/ext/js/dictionary/dictionary-database.js
index 6c7de339..ca90f6a6 100644
--- a/ext/js/dictionary/dictionary-database.js
+++ b/ext/js/dictionary/dictionary-database.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {stringReverse} from '../core/utilities.js';
import {Database} from '../data/database.js';
diff --git a/ext/js/dictionary/dictionary-worker-main.js b/ext/js/dictionary/dictionary-worker-main.js
index d63a3a20..75b86308 100644
--- a/ext/js/dictionary/dictionary-worker-main.js
+++ b/ext/js/dictionary/dictionary-worker-main.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {DictionaryWorkerHandler} from './dictionary-worker-handler.js';
/** Entry point. */
diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js
index d37efa85..03daf003 100644
--- a/ext/js/display/display-anki.js
+++ b/ext/js/display/display-anki.js
@@ -17,6 +17,7 @@
*/
import {EventListenerCollection} from '../core/event-listener-collection.js';
+import {log} from '../core/log.js';
import {toError} from '../core/to-error.js';
import {deferPromise} from '../core/utilities.js';
import {AnkiNoteBuilder} from '../data/anki-note-builder.js';
@@ -568,8 +569,7 @@ export class DisplayAnki {
const content = this._display.displayGenerator.createAnkiNoteErrorsNotificationContent(displayErrors);
for (const node of content.querySelectorAll('.anki-note-error-log-link')) {
/** @type {EventListenerCollection} */ (this._errorNotificationEventListeners).addEventListener(node, 'click', () => {
- // eslint-disable-next-line no-console
- console.log({ankiNoteErrors: errors});
+ log.log({ankiNoteErrors: errors});
}, false);
}
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index f1cd4caf..4cd2d611 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -23,7 +23,7 @@ import {DynamicProperty} from '../core/dynamic-property.js';
import {EventDispatcher} from '../core/event-dispatcher.js';
import {EventListenerCollection} from '../core/event-listener-collection.js';
import {ExtensionError} from '../core/extension-error.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {toError} from '../core/to-error.js';
import {clone, deepEqual, promiseTimeout} from '../core/utilities.js';
import {PopupMenu} from '../dom/popup-menu.js';
@@ -2020,8 +2020,7 @@ export class Display extends EventDispatcher {
}
}
- // eslint-disable-next-line no-console
- console.log(result);
+ log.log(result);
}
/** */
diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js
index c864617b..edae96fb 100644
--- a/ext/js/display/query-parser.js
+++ b/ext/js/display/query-parser.js
@@ -17,7 +17,7 @@
*/
import {EventDispatcher} from '../core/event-dispatcher.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {convertHiraganaToKatakana, convertKatakanaToHiragana, isStringEntirelyKana} from '../language/ja/japanese.js';
import {TextScanner} from '../language/text-scanner.js';
diff --git a/ext/js/extension/web-extension.js b/ext/js/extension/web-extension.js
index bdc9b1b3..ea72ba2f 100644
--- a/ext/js/extension/web-extension.js
+++ b/ext/js/extension/web-extension.js
@@ -33,6 +33,14 @@ export class WebExtension extends EventDispatcher {
} catch (e) {
// NOP
}
+ /** @type {string} */
+ this._extensionName = 'Extension';
+ try {
+ const {name, version} = chrome.runtime.getManifest();
+ this._extensionName = `${name} ${version}`;
+ } catch (e) {
+ // NOP
+ }
}
/** @type {boolean} */
@@ -40,6 +48,11 @@ export class WebExtension extends EventDispatcher {
return this._unloaded;
}
+ /** @type {string} */
+ get extensionName() {
+ return this._extensionName;
+ }
+
/**
* @param {string} path
* @returns {string}
diff --git a/ext/js/general/task-accumulator.js b/ext/js/general/task-accumulator.js
index 62f12869..d6ffdb6a 100644
--- a/ext/js/general/task-accumulator.js
+++ b/ext/js/general/task-accumulator.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
/**
* @template [K=unknown]
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index 1cf346a9..697e2b4d 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -18,7 +18,7 @@
import {EventDispatcher} from '../core/event-dispatcher.js';
import {EventListenerCollection} from '../core/event-listener-collection.js';
-import {log} from '../core/logger.js';
+import {log} from '../core/log.js';
import {clone} from '../core/utilities.js';
import {DocumentUtil} from '../dom/document-util.js';
import {TextSourceElement} from '../dom/text-source-element.js';
diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js
index e161d86b..ecee1788 100644
--- a/ext/js/pages/settings/anki-controller.js
+++ b/ext/js/pages/settings/anki-controller.js
@@ -19,7 +19,7 @@
import {AnkiConnect} from '../../comm/anki-connect.js';
import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {ExtensionError} from '../../core/extension-error.js';
-import {log} from '../../core/logger.js';
+import {log} from '../../core/log.js';
import {toError} from '../../core/to-error.js';
import {getStandardFieldMarkers} from '../../data/anki-template-util.js';
import {stringContainsAnyFieldMarker} from '../../data/anki-util.js';
@@ -205,8 +205,7 @@ export class AnkiController {
/** */
_onAnkiErrorLogLinkClick() {
if (this._ankiError === null) { return; }
- // eslint-disable-next-line no-console
- console.log({error: this._ankiError});
+ log.log({error: this._ankiError});
}
/**
diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js
index 2bab00e3..18991140 100644
--- a/ext/js/pages/settings/backup-controller.js
+++ b/ext/js/pages/settings/backup-controller.js
@@ -18,7 +18,7 @@
import {Dexie} from '../../../lib/dexie.js';
import {parseJson} from '../../core/json.js';
-import {log} from '../../core/logger.js';
+import {log} from '../../core/log.js';
import {toError} from '../../core/to-error.js';
import {isObject} from '../../core/utilities.js';
import {OptionsUtil} from '../../data/options-util.js';
@@ -557,16 +557,14 @@ export class BackupController {
* @param {{totalRows: number, completedRows: number, done: boolean}} details
*/
_databaseExportProgressCallback({totalRows, completedRows, done}) {
- // eslint-disable-next-line no-console
- console.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
+ log.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
/** @type {HTMLElement} */
const messageContainer = querySelectorNotNull(document, '#db-ops-progress-report');
messageContainer.style.display = 'block';
messageContainer.textContent = `Export Progress: ${completedRows} of ${totalRows} rows completed`;
if (done) {
- // eslint-disable-next-line no-console
- console.log('Done exporting.');
+ log.log('Done exporting.');
messageContainer.style.display = 'none';
}
}
@@ -607,8 +605,7 @@ export class BackupController {
const blob = new Blob([data], {type: 'application/json'});
this._saveBlob(blob, fileName);
} catch (error) {
- // eslint-disable-next-line no-console
- console.log(error);
+ log.log(error);
this._databaseExportImportErrorMessage('Errors encountered while exporting. Please try again. Restart the browser if it continues to fail.');
} finally {
pageExitPrevention.end();
@@ -622,8 +619,7 @@ export class BackupController {
* @param {{totalRows: number, completedRows: number, done: boolean}} details
*/
_databaseImportProgressCallback({totalRows, completedRows, done}) {
- // eslint-disable-next-line no-console
- console.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
+ log.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
/** @type {HTMLElement} */
const messageContainer = querySelectorNotNull(document, '#db-ops-progress-report');
messageContainer.style.display = 'block';
@@ -631,8 +627,7 @@ export class BackupController {
messageContainer.textContent = `Import Progress: ${completedRows} of ${totalRows} rows completed`;
if (done) {
- // eslint-disable-next-line no-console
- console.log('Done importing.');
+ log.log('Done importing.');
messageContainer.style.color = '#006633';
messageContainer.textContent = 'Done importing. You will need to re-enable the dictionaries and refresh afterward. If you run into issues, please restart the browser. If it continues to fail, reinstall Yomitan and import dictionaries one-by-one.';
}
@@ -685,8 +680,7 @@ export class BackupController {
this._settingsExportDatabaseToken = token;
await this._importDatabase(this._dictionariesDatabaseName, file);
} catch (error) {
- // eslint-disable-next-line no-console
- console.log(error);
+ log.log(error);
/** @type {HTMLElement} */
const messageContainer = querySelectorNotNull(document, '#db-ops-progress-report');
messageContainer.style.color = 'red';
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 5020dc7c..66ff0923 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -17,7 +17,7 @@
*/
import {EventListenerCollection} from '../../core/event-listener-collection.js';
-import {log} from '../../core/logger.js';
+import {log} from '../../core/log.js';
import {DictionaryWorker} from '../../dictionary/dictionary-worker.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js
index 34e21c5d..f44ef380 100644
--- a/ext/js/pages/settings/dictionary-import-controller.js
+++ b/ext/js/pages/settings/dictionary-import-controller.js
@@ -17,7 +17,7 @@
*/
import {ExtensionError} from '../../core/extension-error.js';
-import {log} from '../../core/logger.js';
+import {log} from '../../core/log.js';
import {toError} from '../../core/to-error.js';
import {DictionaryWorker} from '../../dictionary/dictionary-worker.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
diff --git a/types/ext/api.d.ts b/types/ext/api.d.ts
index 85f4c146..401cb1a5 100644
--- a/types/ext/api.d.ts
+++ b/types/ext/api.d.ts
@@ -289,7 +289,7 @@ type ApiSurface = {
};
return: DictionaryDatabase.MediaDataStringContent[];
};
- log: {
+ logGenericErrorBackend: {
params: {
error: Core.SerializedError;
level: Log.LogLevel;
diff --git a/types/ext/log.d.ts b/types/ext/log.d.ts
index 5b33b234..af906387 100644
--- a/types/ext/log.d.ts
+++ b/types/ext/log.d.ts
@@ -17,22 +17,14 @@
import type {EventNames, EventArgument as BaseEventArgument} from './core';
-export type LogLevel = 'log' | 'info' | 'debug' | 'warn' | 'error';
+export type LogLevel = 'log' | 'warn' | 'error';
export type LogContext = {
url: string;
};
-/**
- * An enum representing the log error level.
- * - `0` - _log_, _info_, _debug_ level.
- * - `1` - _warn_ level.
- * - `2` - _error_ level.
- */
-export type LogErrorLevelValue = 0 | 1 | 2;
-
export type Events = {
- log: {
+ logGenericError: {
error: unknown;
level: LogLevel;
context: LogContext;