Implement finish logging and connect things to export
This commit is contained in:
parent
1cdf246919
commit
d2fdbe178c
@ -166,20 +166,20 @@ class Logger {
|
||||
}
|
||||
|
||||
// this should be used mostly in background page instance of logger, btw
|
||||
//
|
||||
addToGlobalHistory(key, log) {
|
||||
this.globalHistory[key] = log;
|
||||
}
|
||||
|
||||
finish() {
|
||||
this.allowLogging = false;
|
||||
this.conf.allowLogging = false;
|
||||
if (!this.isBackgroundScript) {
|
||||
const logJson = JSON.stringify(this.history);
|
||||
for(const f of this.onLogEndCallbacks) {
|
||||
f(logJson);
|
||||
}
|
||||
} else {
|
||||
this.globalHistory['uw-bg'] = this.history;
|
||||
return this.globalHistory;
|
||||
this.exportLogToFile();
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,6 +324,7 @@ class Logger {
|
||||
if (!this.conf || !this.conf.allowLogging) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stackInfo = this.parseStack();
|
||||
|
||||
// skip all checks if we force log
|
||||
@ -411,6 +412,10 @@ class Logger {
|
||||
|
||||
// export log file — only works on background page
|
||||
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}))};
|
||||
exportObject['logger-settings'] = this.conf.fileOptions;
|
||||
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;
|
||||
|
@ -4,6 +4,7 @@ import BrowserDetect from '../../conf/BrowserDetect';
|
||||
class CommsClient {
|
||||
constructor(name, settings, logger) {
|
||||
this.logger = logger;
|
||||
|
||||
if (BrowserDetect.firefox) {
|
||||
this.port = browser.runtime.connect({name: name});
|
||||
} else if (BrowserDetect.chrome) {
|
||||
@ -12,6 +13,10 @@ class CommsClient {
|
||||
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;
|
||||
this._listener = m => ths.processReceivedMessage(m);
|
||||
this.port.onMessage.addListener(this._listener);
|
||||
@ -176,6 +181,7 @@ class CommsClient {
|
||||
this.registerVideo()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default CommsClient;
|
||||
|
Loading…
Reference in New Issue
Block a user