Implement finish logging and connect things to export
This commit is contained in:
parent
1cdf246919
commit
d2fdbe178c
@ -100,7 +100,7 @@ class Logger {
|
|||||||
console.log("[Logger::<storage/on change>] new settings object:", JSON.parse(changes.uwLogger.newValue));
|
console.log("[Logger::<storage/on change>] new settings object:", JSON.parse(changes.uwLogger.newValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(changes['uwLogger'] && changes['uwLogger'].newValue) {
|
if (changes['uwLogger'] && changes['uwLogger'].newValue) {
|
||||||
ths.conf = JSON.parse(changes.uwLogger.newValue);
|
ths.conf = JSON.parse(changes.uwLogger.newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -166,20 +166,20 @@ class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this should be used mostly in background page instance of logger, btw
|
// this should be used mostly in background page instance of logger, btw
|
||||||
|
//
|
||||||
addToGlobalHistory(key, log) {
|
addToGlobalHistory(key, log) {
|
||||||
this.globalHistory[key] = log;
|
this.globalHistory[key] = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
finish() {
|
finish() {
|
||||||
this.allowLogging = false;
|
this.conf.allowLogging = false;
|
||||||
if (!this.isBackgroundScript) {
|
if (!this.isBackgroundScript) {
|
||||||
const logJson = JSON.stringify(this.history);
|
const logJson = JSON.stringify(this.history);
|
||||||
for(const f of this.onLogEndCallbacks) {
|
for(const f of this.onLogEndCallbacks) {
|
||||||
f(logJson);
|
f(logJson);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.globalHistory['uw-bg'] = this.history;
|
this.exportLogToFile();
|
||||||
return this.globalHistory;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,6 +324,7 @@ class Logger {
|
|||||||
if (!this.conf || !this.conf.allowLogging) {
|
if (!this.conf || !this.conf.allowLogging) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stackInfo = this.parseStack();
|
const stackInfo = this.parseStack();
|
||||||
|
|
||||||
// skip all checks if we force log
|
// skip all checks if we force log
|
||||||
@ -411,6 +412,10 @@ class Logger {
|
|||||||
|
|
||||||
// export log file — only works on background page
|
// export log file — only works on background page
|
||||||
async exportLogToFile() {
|
async exportLogToFile() {
|
||||||
|
// don't export log if logging to file is not enabled
|
||||||
|
if (!this.conf.fileOptions?.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const exportObject = {'pageLogs': JSON.parse(JSON.stringify({...this.globalHistory}))};
|
const exportObject = {'pageLogs': JSON.parse(JSON.stringify({...this.globalHistory}))};
|
||||||
exportObject['logger-settings'] = this.conf.fileOptions;
|
exportObject['logger-settings'] = this.conf.fileOptions;
|
||||||
exportObject['backgroundLog'] = JSON.parse(JSON.stringify(this.history));
|
exportObject['backgroundLog'] = JSON.parse(JSON.stringify(this.history));
|
||||||
@ -444,12 +449,7 @@ class Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for instances where logging is limited to a single page and is timed
|
|
||||||
addLogAndExport(host, pageHistory) {
|
|
||||||
this.globalHistory = {};
|
|
||||||
this.globalHistory[host || 'no-host-provided'] = pageHistory;
|
|
||||||
this.exportLogToFile();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Logger;
|
export default Logger;
|
||||||
|
@ -4,6 +4,7 @@ import BrowserDetect from '../../conf/BrowserDetect';
|
|||||||
class CommsClient {
|
class CommsClient {
|
||||||
constructor(name, settings, logger) {
|
constructor(name, settings, logger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
if (BrowserDetect.firefox) {
|
if (BrowserDetect.firefox) {
|
||||||
this.port = browser.runtime.connect({name: name});
|
this.port = browser.runtime.connect({name: name});
|
||||||
} else if (BrowserDetect.chrome) {
|
} else if (BrowserDetect.chrome) {
|
||||||
@ -12,6 +13,10 @@ class CommsClient {
|
|||||||
this.port = browser.runtime.connect({name: name})
|
this.port = browser.runtime.connect({name: name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.onLogEnd(
|
||||||
|
(history) => this.port.postMessage({cmd: 'logging-stop-and-save', host: window.location.host, history})
|
||||||
|
);
|
||||||
|
|
||||||
var ths = this;
|
var ths = this;
|
||||||
this._listener = m => ths.processReceivedMessage(m);
|
this._listener = m => ths.processReceivedMessage(m);
|
||||||
this.port.onMessage.addListener(this._listener);
|
this.port.onMessage.addListener(this._listener);
|
||||||
@ -176,6 +181,7 @@ class CommsClient {
|
|||||||
this.registerVideo()
|
this.registerVideo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CommsClient;
|
export default CommsClient;
|
||||||
|
Loading…
Reference in New Issue
Block a user