[MM-41999] Add additional logging for debugging, allow users to change log level (#2031)

* Add debug logging switch

* Add tests

* Mock electron-log globally in jest

* New logs for debugging

* Switch to a dropdown to choose log levels

* Fix tests

* Update wording
This commit is contained in:
Devin Binnie
2022-03-31 16:46:57 -04:00
committed by GitHub
parent 7c1fa2c78d
commit 626fea84a5
49 changed files with 261 additions and 108 deletions

View File

@@ -29,11 +29,6 @@ jest.mock('electron', () => ({
},
}));
jest.mock('electron-log', () => ({
info: jest.fn(),
error: jest.fn(),
}));
jest.mock('../windows/windowManager', () => ({
sendToRenderer: jest.fn(),
focusThreeDotMenu: jest.fn(),

View File

@@ -101,6 +101,8 @@ export class MattermostView extends EventEmitter {
}
this.view.webContents.on('did-finish-load', () => {
log.debug('MattermostView.did-finish-load', this.tab.name);
// wait for screen to truly finish loading before sending the message down
const timeout = setInterval(() => {
if (!this.view.webContents.isLoading()) {
@@ -327,6 +329,8 @@ export class MattermostView extends EventEmitter {
};
handleInputEvents = (_: Event, input: Input) => {
log.silly('MattermostView.handleInputEvents', {tabName: this.tab.name, input});
this.registerAltKeyPressed(input);
if (this.isAltKeyReleased(input)) {
@@ -335,6 +339,8 @@ export class MattermostView extends EventEmitter {
}
handleDidNavigate = (event: Event, url: string) => {
log.debug('MattermostView.handleDidNavigate', {tabName: this.tab.name, url});
const isUrlTeamUrl = urlUtils.isTeamUrl(this.tab.url || '', url) || urlUtils.isAdminUrl(this.tab.url || '', url);
if (isUrlTeamUrl) {
this.setBounds(getWindowBoundaries(this.window));
@@ -348,6 +354,7 @@ export class MattermostView extends EventEmitter {
}
handleUpdateTarget = (e: Event, url: string) => {
log.silly('MattermostView.handleUpdateTarget', {tabName: this.tab.name, url});
if (url && !urlUtils.isInternalURL(urlUtils.parseURL(url), this.tab.server.url)) {
this.emit(UPDATE_TARGET_URL, url);
}
@@ -356,6 +363,8 @@ export class MattermostView extends EventEmitter {
titleParser = /(\((\d+)\) )?(\* )?/g
handleTitleUpdate = (e: Event, title: string) => {
log.debug('MattermostView.handleTitleUpdate', {tabName: this.tab.name, title});
this.updateMentionsFromTitle(title);
}
@@ -379,6 +388,8 @@ export class MattermostView extends EventEmitter {
}
handleFaviconUpdate = (e: Event, favicons: string[]) => {
log.silly('MattermostView.handleFaviconUpdate', {tabName: this.tab.name, favicons});
if (!this.usesAsteriskForUnreads) {
// if unread state is stored for that favicon, retrieve value.
// if not, get related info from preload and store it for future changes
@@ -400,6 +411,8 @@ export class MattermostView extends EventEmitter {
// if favicon is null, it means it is the initial load,
// so don't memoize as we don't have the favicons and there is no rush to find out.
handleFaviconIsUnread = (e: Event, favicon: string, viewName: string, result: boolean) => {
log.silly('MattermostView.handleFaviconIsUnread', {favicon, viewName, result});
if (this.tab && viewName === this.tab.name) {
appState.updateUnreads(viewName, result);
}

View File

@@ -15,8 +15,6 @@ jest.mock('electron', () => ({
},
}));
jest.mock('electron-log', () => ({}));
jest.mock('./modalView', () => ({
ModalView: jest.fn(),
}));

View File

@@ -4,6 +4,8 @@
import {BrowserWindow, ipcMain} from 'electron';
import {IpcMainEvent, IpcMainInvokeEvent} from 'electron/main';
import log from 'electron-log';
import {CombinedConfig} from 'types/config';
import {
@@ -70,6 +72,8 @@ export class ModalManager {
}
handleInfoRequest = (event: IpcMainInvokeEvent) => {
log.debug('ModalManager.handleInfoRequest');
const requestModal = this.findModalByCaller(event);
if (requestModal) {
return requestModal.handleInfoRequest();
@@ -91,6 +95,8 @@ export class ModalManager {
}
handleModalFinished = (mode: 'resolve' | 'reject', event: IpcMainEvent, data: unknown) => {
log.debug('ModalManager.handleModalFinished', {mode, data});
const requestModal = this.findModalByCaller(event);
if (requestModal) {
if (mode === 'resolve') {
@@ -122,6 +128,8 @@ export class ModalManager {
}
handleResizeModal = (event: IpcMainEvent, bounds: Electron.Rectangle) => {
log.debug('ModalManager.handleResizeModal', bounds);
if (this.modalQueue.length) {
const currentModal = this.modalQueue[0];
currentModal.view.setBounds(getAdjustedWindowBoundaries(bounds.width, bounds.height));
@@ -135,6 +143,10 @@ export class ModalManager {
}
handleEmitConfiguration = (event: IpcMainEvent, config: CombinedConfig) => {
if (this.modalQueue.length) {
log.debug('ModalManager.handleEmitConfiguration');
}
this.modalQueue.forEach((modal) => {
modal.view.webContents.send(DARK_MODE_CHANGE, config.darkMode);
});

View File

@@ -22,10 +22,6 @@ jest.mock('electron', () => ({
})),
}));
jest.mock('electron-log', () => ({
info: jest.fn(),
}));
jest.mock('../contextMenu', () => jest.fn());
jest.mock('../utils', () => ({

View File

@@ -2,6 +2,9 @@
// See LICENSE.txt for license information.
import {BrowserView, BrowserWindow, ipcMain, IpcMainEvent} from 'electron';
import log from 'electron-log';
import {CombinedConfig, TeamWithTabs} from 'types/config';
import {
@@ -66,6 +69,8 @@ export default class TeamDropdownView {
}
updateConfig = (event: IpcMainEvent, config: CombinedConfig) => {
log.silly('TeamDropdownView.config', {config});
this.teams = config.teams;
this.darkMode = config.darkMode;
this.enableServerManagement = config.enableServerManagement;
@@ -74,11 +79,15 @@ export default class TeamDropdownView {
}
updateActiveTeam = (event: IpcMainEvent, name: string) => {
log.silly('TeamDropdownView.updateActiveTeam', {name});
this.activeTeam = name;
this.updateDropdown();
}
updateMentions = (expired: Map<string, boolean>, mentions: Map<string, number>, unreads: Map<string, boolean>) => {
log.silly('TeamDropdownView.updateMentions', {expired, mentions, unreads});
this.unreads = unreads;
this.mentions = mentions;
this.expired = expired;
@@ -91,6 +100,8 @@ export default class TeamDropdownView {
}
updateDropdown = () => {
log.silly('TeamDropdownView.updateDropdown');
this.view.webContents.send(
UPDATE_TEAMS_DROPDOWN,
this.teams,
@@ -106,6 +117,8 @@ export default class TeamDropdownView {
}
handleOpen = () => {
log.debug('TeamDropdownView.handleOpen');
if (!this.bounds) {
return;
}
@@ -117,12 +130,16 @@ export default class TeamDropdownView {
}
handleClose = () => {
log.debug('TeamDropdownView.handleClose');
this.view.setBounds(this.getBounds(0, 0));
WindowManager.sendToRenderer(CLOSE_TEAMS_DROPDOWN);
this.isOpen = false;
}
handleReceivedMenuSize = (event: IpcMainEvent, width: number, height: number) => {
log.silly('TeamDropdownView.handleReceivedMenuSize', {width, height});
this.bounds = this.getBounds(width, height);
if (this.isOpen) {
this.view.setBounds(this.bounds);

View File

@@ -27,11 +27,6 @@ jest.mock('electron', () => ({
},
}));
jest.mock('electron-log', () => ({
warn: jest.fn(),
error: jest.fn(),
}));
jest.mock('common/tabs/TabView', () => ({
getServerView: jest.fn(),
getTabViewName: jest.fn(),

View File

@@ -173,6 +173,8 @@ export class ViewManager {
}
showByName = (name: string) => {
log.debug('viewManager.showByName', name);
const newView = this.views.get(name);
if (newView) {
if (newView.isVisible) {
@@ -218,6 +220,8 @@ export class ViewManager {
}
activateView = (viewName: string) => {
log.debug('viewManager.activateView', viewName);
if (this.currentView === viewName) {
this.showByName(this.currentView);
}
@@ -230,6 +234,8 @@ export class ViewManager {
}
finishLoading = (server: string) => {
log.debug('viewManager.finishLoading', server);
const view = this.views.get(server);
if (view && this.getCurrentView() === view) {
this.showByName(this.currentView!);
@@ -255,6 +261,8 @@ export class ViewManager {
}
failLoading = (tabName: string) => {
log.debug('viewManager.failLoading', tabName);
this.fadeLoadingScreen();
if (this.currentView === tabName) {
this.getCurrentView()?.hide();
@@ -293,6 +301,8 @@ export class ViewManager {
}
showURLView = (url: URL | string) => {
log.silly('viewManager.showURLView', url);
if (this.urlViewCancel) {
this.urlViewCancel();
}
@@ -326,6 +336,8 @@ export class ViewManager {
};
const adjustWidth = (event: IpcMainEvent, width: number) => {
log.silly('showURLView.adjustWidth', width);
urlView.setBounds({
x: 0,
y: boundaries.height - URL_VIEW_HEIGHT,
@@ -422,6 +434,8 @@ export class ViewManager {
}
deeplinkSuccess = (viewName: string) => {
log.debug('viewManager.deeplinkSuccess', viewName);
const view = this.views.get(viewName);
if (!view) {
return;

View File

@@ -27,11 +27,6 @@ jest.mock('electron', () => ({
})),
}));
jest.mock('electron-log', () => ({
info: jest.fn(),
warn: jest.fn(),
}));
jest.mock('../allowProtocolDialog', () => ({}));
jest.mock('../windows/windowManager', () => ({
showMainWindow: jest.fn(),

View File

@@ -47,6 +47,8 @@ export class WebContentsEventManager {
generateWillNavigate = (getServersFunction: () => TeamWithTabs[]) => {
return (event: Event & {sender: WebContents}, url: string) => {
log.debug('webContentEvents.will-navigate', {webContentsId: event.sender.id, url});
const contentID = event.sender.id;
const parsedURL = urlUtils.parseURL(url)!;
const configServers = getServersFunction();
@@ -77,6 +79,8 @@ export class WebContentsEventManager {
generateDidStartNavigation = (getServersFunction: () => TeamWithTabs[]) => {
return (event: Event & {sender: WebContents}, url: string) => {
log.debug('webContentEvents.did-start-navigation', {webContentsId: event.sender.id, url});
const serverList = getServersFunction();
const contentID = event.sender.id;
const parsedURL = urlUtils.parseURL(url)!;
@@ -103,6 +107,8 @@ export class WebContentsEventManager {
generateNewWindowListener = (getServersFunction: () => TeamWithTabs[], spellcheck?: boolean) => {
return (details: Electron.HandlerDetails): {action: 'deny' | 'allow'} => {
log.debug('webContentEvents.new-window', details.url);
const parsedURL = urlUtils.parseURL(details.url);
if (!parsedURL) {
log.warn(`Ignoring non-url ${details.url}`);