aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-18 08:01:22 -0500
committerGitHub <noreply@github.com>2024-02-18 13:01:22 +0000
commit90449bc745546f0f25bc93ee4b06d21b7c0210e8 (patch)
tree728153aaa4588a7340c3f3a45008989c0f5521b3 /ext/js/background
parentc2e3f60e51529f05284fea5f5bc1afcd1674f5ca (diff)
Log update (#701)
* Don't export Logger * Rename logger.js to log.js * Move helper function * Update extension name configuration * Simplify docs * Move issue URL to a field * Simplify context * Remove optional params that are never used * Configure backend * Update eslint * Simplify * Rename function * Simplify _api reference * Simplify docs * Remove unused log levels (except 'log') * Add log function * Rename for more clear intent * Use log.log
Diffstat (limited to 'ext/js/background')
-rw-r--r--ext/js/background/backend.js21
-rw-r--r--ext/js/background/background-main.js2
2 files changed, 13 insertions, 10 deletions
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();