fixes for logger

This commit is contained in:
Tamius Han 2020-01-27 23:20:38 +01:00
parent f3e5aeb9e6
commit f770b0dbf1

View File

@ -46,11 +46,12 @@ class Logger {
try { try {
return JSON.parse(ret.uwLogger); return JSON.parse(ret.uwLogger);
} catch(e) { } catch(e) {
return {logToFile: false, logToConsole: false, consoleOptions: {}, fileOptions: {}}; return {consoleOptions: {}, fileOptions: {}};
} }
} }
async init(conf) { async init(conf) {
console.log("init logger with conf:", conf)
if (conf && process.env.CHANNEL === 'dev') { if (conf && process.env.CHANNEL === 'dev') {
this.conf = conf; this.conf = conf;
} else { } else {
@ -59,7 +60,7 @@ class Logger {
if (this.conf.consoleOptions === undefined) { if (this.conf.consoleOptions === undefined) {
this.conf.consoleOptions = {}; this.conf.consoleOptions = {};
} }
if (!this.conf.fileOptions === undefined) { if (this.conf.fileOptions === undefined) {
this.conf.fileOptions = {}; this.conf.fileOptions = {};
} }
// this is the only property that always gets passed via conf // this is the only property that always gets passed via conf
@ -74,6 +75,7 @@ class Logger {
const ths = this; const ths = this;
const br = currentBrowser.firefox ? browser : chrome; const br = currentBrowser.firefox ? browser : chrome;
br.storage.onChanged.addListener( (changes, area) => { br.storage.onChanged.addListener( (changes, area) => {
if (Debug.debug && Debug.debugStorage) { if (Debug.debug && Debug.debugStorage) {
console.log("[Logger::<storage/on change>] Settings have been changed outside of here. Updating active settings. Changes:", changes, "storage area:", area); console.log("[Logger::<storage/on change>] Settings have been changed outside of here. Updating active settings. Changes:", changes, "storage area:", area);
@ -88,7 +90,6 @@ class Logger {
} }
clear() { clear() {
this.log = []; this.log = [];
this.startTime = performance.now(); this.startTime = performance.now();
@ -194,7 +195,7 @@ class Logger {
return; return;
} }
const error = new Error(); const error = new Error();
if (this.conf.logToFile) { if (this.conf.fileOptions.enabled) {
if (this.canLogFile(component)) { if (this.canLogFile(component)) {
let ts = performance.now(); let ts = performance.now();
if (ts <= this.history[this.history.length - 1]) { if (ts <= this.history[this.history.length - 1]) {
@ -208,9 +209,9 @@ class Logger {
}) })
} }
} }
if (this.conf.logToConsole) { if (this.conf.consoleOptions.enabled) {
if (this.canLogConsole(component)) { if (this.canLogConsole(component)) {
console.log(...message, error.stack); console.log(...message, {stack: error});
} }
} }
} }