Further logging fixes
This commit is contained in:
parent
a89eb8e857
commit
b2cd96982e
@ -44,13 +44,6 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async created() {
|
async created() {
|
||||||
this.logger = new Logger();
|
|
||||||
|
|
||||||
// this prolly needs to be taken out
|
|
||||||
await this.logger.init({
|
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup the "companion" onMouseMove handler to the one in the content script.
|
* Setup the "companion" onMouseMove handler to the one in the content script.
|
||||||
* We can handle events with the same function we use to handle events from
|
* We can handle events with the same function we use to handle events from
|
||||||
|
@ -213,6 +213,8 @@ import CommsMixin from '@csui/src/utils/CommsMixin';
|
|||||||
import SupportLevelIndicator from '@csui/src/components/SupportLevelIndicator.vue';
|
import SupportLevelIndicator from '@csui/src/components/SupportLevelIndicator.vue';
|
||||||
import TriggerZoneEditor from '@csui/src/components/TriggerZoneEditor.vue';
|
import TriggerZoneEditor from '@csui/src/components/TriggerZoneEditor.vue';
|
||||||
import ZoomControl from '@csui/src/popup/player-menu/ZoomControl.vue';
|
import ZoomControl from '@csui/src/popup/player-menu/ZoomControl.vue';
|
||||||
|
import { LogAggregator } from '@src/ext/lib/logging/LogAggregator';
|
||||||
|
import { ComponentLogger } from '@src/ext/lib/logging/ComponentLogger';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -329,11 +331,6 @@ export default {
|
|||||||
this.logAggregator = new LogAggregator('player-overlay');
|
this.logAggregator = new LogAggregator('player-overlay');
|
||||||
this.logger = new ComponentLogger(this.logAggregator, 'PlayerOverlay.vue');
|
this.logger = new ComponentLogger(this.logAggregator, 'PlayerOverlay.vue');
|
||||||
|
|
||||||
// this prolly needs to be taken out
|
|
||||||
await this.logger.init({
|
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings = new Settings({afterSettingsSaved: this.updateConfig, logger: this.logger});
|
this.settings = new Settings({afterSettingsSaved: this.updateConfig, logger: this.logger});
|
||||||
this.settings.listenAfterChange(() => this.updateTriggerZones());
|
this.settings.listenAfterChange(() => this.updateTriggerZones());
|
||||||
|
|
||||||
|
@ -176,11 +176,8 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.logAggregator = new LogAggregator('🔵ext-popup🔵');
|
this.logAggregator = new LogAggregator('🔵ext-popup🔵');
|
||||||
this.logger = new ComponentLogger(this.logAggregator, 'Popup');
|
this.logger = new ComponentLogger(this.logAggregator, 'Popup');
|
||||||
await this.logger.init({
|
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings = new Settings({afterSettingsSaved: () => this.updateConfig(), logger: this.logger});
|
this.settings = new Settings({afterSettingsSaved: () => this.updateConfig(), logAggregator: this.logAggregator});
|
||||||
await this.settings.init();
|
await this.settings.init();
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { LogAggregator } from '@src/ext/lib/logging/LogAggregator';
|
import { LogAggregator, BLANK_LOGGER_CONFIG } from '@src/ext/lib/logging/LogAggregator';
|
||||||
import JsonEditor from '@csui/src/components/JsonEditor';
|
import JsonEditor from '@csui/src/components/JsonEditor';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -79,21 +79,23 @@ export default {
|
|||||||
...this.loggerPanelRotation[Math.floor(Math.random() * this.loggerPanelRotation.length)],
|
...this.loggerPanelRotation[Math.floor(Math.random() * this.loggerPanelRotation.length)],
|
||||||
pasteConfMode: false,
|
pasteConfMode: false,
|
||||||
};
|
};
|
||||||
this.loadDefaultConfig();
|
this.getLoggerSettings();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadDefaultConfig() {
|
loadDefaultConfig() {
|
||||||
this.lastSettings = baseLoggingOptions;
|
this.lastSettings = JSON.parse(JSON.stringify(BLANK_LOGGER_CONFIG));
|
||||||
},
|
},
|
||||||
async getLoggerSettings() {
|
async getLoggerSettings() {
|
||||||
this.lastSettings = await LogAggregator.getConfig() || baseLoggingOptions;
|
this.lastSettings = await LogAggregator.getConfig() || BLANK_LOGGER_CONFIG;
|
||||||
},
|
},
|
||||||
saveLoggerSettings() {
|
async saveLoggerSettings() {
|
||||||
LogAggregator.saveConfig({...this.lastSettings});
|
console.log('Saving logger settings', this.lastSettings);
|
||||||
|
await LogAggregator.saveConfig({...this.lastSettings});
|
||||||
|
console.log('[ok] logger settings saved');
|
||||||
},
|
},
|
||||||
async startLogging(){
|
async startLogging(){
|
||||||
this.logStringified = undefined;
|
this.logStringified = undefined;
|
||||||
await LogAggregator.saveConfig({...this.lastSettings, allowLogging: true});
|
await LogAggregator.saveConfig({...this.lastSettings});
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export class ComponentLogger {
|
|||||||
private handleLog(logLevel: LogLevel, sourceFunction: string | LogSourceOptions, ...message: any) {
|
private handleLog(logLevel: LogLevel, sourceFunction: string | LogSourceOptions, ...message: any) {
|
||||||
let functionSource = typeof sourceFunction === 'string' ? sourceFunction : sourceFunction?.src;
|
let functionSource = typeof sourceFunction === 'string' ? sourceFunction : sourceFunction?.src;
|
||||||
|
|
||||||
let consoleMessageString = `[${this.component}${functionSource ? `::${functionSource}` : ''}] `;
|
let consoleMessageString = `[${this.component}${functionSource ? `::${functionSource}` : ''}]`;
|
||||||
const consoleMessageData = []
|
const consoleMessageData = []
|
||||||
|
|
||||||
for (const m of message) {
|
for (const m of message) {
|
||||||
@ -35,10 +35,13 @@ export class ComponentLogger {
|
|||||||
consoleMessageString = `${consoleMessageString} ${m}`;
|
consoleMessageString = `${consoleMessageString} ${m}`;
|
||||||
} else if (typeof m === 'number') {
|
} else if (typeof m === 'number') {
|
||||||
consoleMessageString = `${consoleMessageString} %f`;
|
consoleMessageString = `${consoleMessageString} %f`;
|
||||||
} else if (m instanceof HTMLElement) {
|
consoleMessageData.unshift(m);
|
||||||
|
} else if (typeof HTMLElement !== 'undefined' && m instanceof HTMLElement) { // HTMLElement does not exist in background script, but this class may
|
||||||
consoleMessageString = `${consoleMessageString} %o`;
|
consoleMessageString = `${consoleMessageString} %o`;
|
||||||
|
consoleMessageData.unshift(m);
|
||||||
} else {
|
} else {
|
||||||
consoleMessageString = `${consoleMessageString} %O`;
|
consoleMessageString = `${consoleMessageString} %O`;
|
||||||
|
consoleMessageData.unshift(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,6 @@ export const BLANK_LOGGER_CONFIG: LogConfig = {
|
|||||||
logToConsole: false,
|
logToConsole: false,
|
||||||
logToFile: false,
|
logToFile: false,
|
||||||
component: {
|
component: {
|
||||||
aard: { enabled: false },
|
|
||||||
resizer: { enabled: false },
|
|
||||||
comms: { enabled: false },
|
|
||||||
settings: { enabled: false },
|
|
||||||
eventBus: { enabled: false },
|
|
||||||
},
|
},
|
||||||
origins: {
|
origins: {
|
||||||
videoRescan: { disabled: true},
|
videoRescan: { disabled: true},
|
||||||
@ -36,6 +31,7 @@ export interface LogConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STORAGE_LOG_SETTINGS_KEY = 'uw-log-config';
|
||||||
|
|
||||||
export class LogAggregator {
|
export class LogAggregator {
|
||||||
private segment: string;
|
private segment: string;
|
||||||
@ -46,29 +42,34 @@ export class LogAggregator {
|
|||||||
history: any[];
|
history: any[];
|
||||||
|
|
||||||
static async getConfig() {
|
static async getConfig() {
|
||||||
let ret = await chrome.storage.local.get('uw-log-config');
|
let ret = await chrome.storage.local.get(STORAGE_LOG_SETTINGS_KEY);
|
||||||
|
|
||||||
if (process.env.CHANNEL === 'dev') {
|
if (process.env.CHANNEL === 'dev') {
|
||||||
try {
|
try {
|
||||||
console.info("[Logger::getSaved] Got settings:", JSON.parse(ret.uwLogger));
|
console.info("[LogAggregator::getSaved] Got settings:", JSON.parse(ret[STORAGE_LOG_SETTINGS_KEY]));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.info("[Logger::getSaved] No settings.")
|
console.info("[LogAggregator::getSaved] No settings.", ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return JSON.parse(ret['uw-log-config']);
|
return JSON.parse(ret[STORAGE_LOG_SETTINGS_KEY]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return JSON.parse(JSON.stringify(BLANK_LOGGER_CONFIG));
|
return JSON.parse(JSON.stringify(BLANK_LOGGER_CONFIG));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static saveConfig(conf: LogConfig) {
|
static async saveConfig(conf: LogConfig) {
|
||||||
if (process.env.CHANNEL === 'dev') {
|
try {
|
||||||
console.info('Saving logger conf:', conf)
|
const confCp = JSON.parse(JSON.stringify(conf));
|
||||||
}
|
if (process.env.CHANNEL === 'dev') {
|
||||||
|
console.info('Saving logger conf:', confCp)
|
||||||
|
}
|
||||||
|
|
||||||
chrome.storage.local.set( {'uw-log-config': JSON.stringify(conf)});
|
await chrome.storage.local.set({[STORAGE_LOG_SETTINGS_KEY]: JSON.stringify(confCp)} );
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[LogAggregator::saveConfig] Error while trying to save logger config:', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static syncConfig(callback: (x) => void) {
|
static syncConfig(callback: (x) => void) {
|
||||||
@ -89,26 +90,35 @@ export class LogAggregator {
|
|||||||
chrome.storage.onChanged.addListener((changes, area) => {
|
chrome.storage.onChanged.addListener((changes, area) => {
|
||||||
this.storageChangeListener(changes, area)
|
this.storageChangeListener(changes, area)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private canLog(component: string, sourceOptions?: LogSourceOptions): boolean {
|
private canLog(component: string, sourceOptions?: LogSourceOptions): boolean {
|
||||||
|
// component is not in config, so we add a blank entry
|
||||||
|
if (this.config && !this.config.component[component]) {
|
||||||
|
this.config.component[component] = {enabled: false};
|
||||||
|
LogAggregator.saveConfig(this.config);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (this.config?.component?.[component]?.enabled) {
|
if (this.config?.component?.[component]?.enabled) {
|
||||||
if (sourceOptions?.origin && this.config?.origins?.[sourceOptions.origin]?.disabled) {
|
if (sourceOptions?.origin && this.config?.origins?.[sourceOptions.origin]?.disabled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private storageChangeListener(changes, area) {
|
private storageChangeListener(changes, area) {
|
||||||
if (!changes.uwLogger) {
|
if (!changes[STORAGE_LOG_SETTINGS_KEY]) {
|
||||||
console.info('We dont have any logging settings, not processing frther');
|
console.info('We dont have any logging settings, not processing frther', changes);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.config = JSON.parse(changes['uw-log-config'].newValue);
|
this.config = JSON.parse(changes[STORAGE_LOG_SETTINGS_KEY].newValue);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[uwLogger] Error while trying to parse new conf for logger:', e, '\nWe received the following changes:', changes, 'for area:', area);
|
console.warn('[uwLogger] Error while trying to parse new conf for logger:', e, '\nWe received the following changes:', changes, 'for area:', area);
|
||||||
}
|
}
|
||||||
@ -188,7 +198,11 @@ export class LogAggregator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(config: LogConfig) {
|
async init(config?: LogConfig) {
|
||||||
|
if (!config) {
|
||||||
|
config = await LogAggregator.getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.startTime = performance.now();
|
this.startTime = performance.now();
|
||||||
|
|
||||||
@ -211,7 +225,7 @@ export class LogAggregator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.logToConsole) {
|
if (this.config.logToConsole){
|
||||||
console[logLevel](`[${this.segment}]>>${message}`, ...data, {stack: this.parseStack()});
|
console[logLevel](`[${this.segment}]>>${message}`, ...data, {stack: this.parseStack()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ class PlayerData {
|
|||||||
constructor(videoData) {
|
constructor(videoData) {
|
||||||
try {
|
try {
|
||||||
// set all our helper objects
|
// set all our helper objects
|
||||||
this.logger = new ComponentLogger(videoData.logAggregator, 'PlayerData', {styles: Debug.getLoggingStyles()});
|
this.logger = new ComponentLogger(videoData.logAggregator, 'PlayerData', {styles: {}});
|
||||||
this.videoData = videoData;
|
this.videoData = videoData;
|
||||||
this.videoElement = videoData.video;
|
this.videoElement = videoData.video;
|
||||||
this.pageInfo = videoData.pageInfo;
|
this.pageInfo = videoData.pageInfo;
|
||||||
|
@ -85,11 +85,8 @@ export default {
|
|||||||
async created() {
|
async created() {
|
||||||
this.logAggregator = new LogAggregator('');
|
this.logAggregator = new LogAggregator('');
|
||||||
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
||||||
await this.logger.init({
|
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings = new Settings({updateCallback: () => this.updateConfig(), logger: this.logger});
|
this.settings = new Settings({updateCallback: () => this.updateConfig(), logAggregator: this.logAggregator });
|
||||||
await this.settings.init();
|
await this.settings.init();
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
},
|
},
|
||||||
|
@ -87,11 +87,7 @@ export default {
|
|||||||
this.logAggregator = new LogAggregator('');
|
this.logAggregator = new LogAggregator('');
|
||||||
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
||||||
|
|
||||||
await this.logger.init({
|
this.settings = new Settings({updateCallback: () => this.updateConfig(), logAggregator: this.logAggregator});
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings = new Settings({updateCallback: () => this.updateConfig(), logger: this.logger});
|
|
||||||
await this.settings.init();
|
await this.settings.init();
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
},
|
},
|
||||||
|
@ -111,10 +111,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import Donate from '../common/misc/Donate.vue';
|
import Donate from '../common/misc/Donate.vue';
|
||||||
import SuperAdvancedSettings from './SuperAdvancedSettings.vue';
|
import SuperAdvancedSettings from './SuperAdvancedSettings.vue';
|
||||||
import Debug from '../ext/conf/Debug';
|
|
||||||
import BrowserDetect from '../ext/conf/BrowserDetect';
|
|
||||||
import ExtensionConf from '../ext/conf/ExtensionConf';
|
|
||||||
import ObjectCopy from '../ext/lib/ObjectCopy';
|
|
||||||
import Settings from '../ext/lib/Settings';
|
import Settings from '../ext/lib/Settings';
|
||||||
import GeneralSettings from './GeneralSettings';
|
import GeneralSettings from './GeneralSettings';
|
||||||
import ControlsSettings from './controls-settings/ControlsSettings';
|
import ControlsSettings from './controls-settings/ControlsSettings';
|
||||||
@ -122,7 +118,6 @@ import AddEditActionPopup from './controls-settings/AddEditActionPopup';
|
|||||||
import ConfirmPopup from './common/ConfirmationPopup';
|
import ConfirmPopup from './common/ConfirmationPopup';
|
||||||
import About from './about'
|
import About from './about'
|
||||||
import AutodetectionSettings from './AutodetectionSettings';
|
import AutodetectionSettings from './AutodetectionSettings';
|
||||||
// import SuperAdvancedSettings from './'
|
|
||||||
import { LogAggregator } from '@src/ext/lib/logging/LogAggregator';
|
import { LogAggregator } from '@src/ext/lib/logging/LogAggregator';
|
||||||
import { ComponentLogger } from '@src/ext/lib/logging/ComponentLogger';
|
import { ComponentLogger } from '@src/ext/lib/logging/ComponentLogger';
|
||||||
|
|
||||||
@ -149,11 +144,8 @@ export default {
|
|||||||
async created () {
|
async created () {
|
||||||
this.logAggregator = new LogAggregator('');
|
this.logAggregator = new LogAggregator('');
|
||||||
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
this.logger = new ComponentLogger(this.logAggregator, 'App.vue');
|
||||||
await this.logger.init({
|
|
||||||
allowLogging: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings = new Settings({updateCallback: this.updateSettings, logger: this.logger});
|
this.settings = new Settings({updateCallback: this.updateSettings, logAggregator: this.logAggregator});
|
||||||
await this.settings.init();
|
await this.settings.init();
|
||||||
|
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user