add logger

This commit is contained in:
2020-01-13 14:27:40 +08:00
parent 09112bb506
commit 97c8aac58d
4 changed files with 95 additions and 12 deletions

View File

@ -17,7 +17,7 @@ class Extractor {
*/
load() {
if (!__EXTRACTOR_STATE__) {
console.log('No state found. \nPlease upload a saved state from the popup window first.');
logger.info('No state found. Please upload a saved state from the popup window first.');
return;
}
let state = JSON.parse(__EXTRACTOR_STATE__);
@ -63,11 +63,11 @@ class Extractor {
}
async _startTasks(from) {
if (this._running) {
console.log('The Extractor is running. Please wait..');
logger.info('The Extractor is running. Please wait..');
return;
}
if (!this._tasks.length) {
console.log('No task to run.');
logger.info('No task to run.');
return;
}
@ -80,7 +80,7 @@ class Extractor {
tab = await getActiveTab(true) || await getActiveTab(false);
let succ = await ping(tab);
if (!succ) {
console.log('Cannot contact with active tab.');
logger.error('Cannot contact with active tab.');
return;
}
}
@ -102,7 +102,7 @@ class Extractor {
}
).catch(err => {
this._running = false;
console.log(err);
logger.error(err);
});
}
/**
@ -118,7 +118,7 @@ class Extractor {
let exResults = new ExtractResult(results);
if (!results.length) {
console.log(`No result for task #${id}. Forget to call ".start()"?`);
logger.info(`No result for task #${id}. Forget to call ".start()"?`);
return;
}
let msg = `
@ -132,12 +132,12 @@ ${exResults.toString(50) || "- Empty -"}
}
_checkTaskId(id, defaultId) {
if (!this._tasks.length) {
console.log("No task found.");
logger.info("No task found.");
return -1;
}
if (!isNaN(defaultId) && id === undefined) id = defaultId;
if (isNaN(id) || id < 0 || id >= this._tasks.length) {
console.log(`Invalid task id. Rang(0-${this._tasks.length - 1})`);
logger.info(`Invalid task id. Rang(0-${this._tasks.length - 1})`);
return -1;
}
return id