From dc9f77a5097906484de0b2175770a9ebe79cec10 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk Date: Fri, 15 Oct 2021 16:59:13 +0200 Subject: [PATCH] Replace console.log with logger.log Related https://github.com/vector-im/element-web/issues/18425 --- src/vector/app.tsx | 26 ++++++++++++------------ src/vector/index.ts | 2 +- src/vector/init.tsx | 18 ++++++++-------- src/vector/jitsi/index.ts | 2 +- src/vector/platform/ElectronPlatform.tsx | 4 ++-- src/vector/rageshakesetup.ts | 10 ++++----- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/vector/app.tsx b/src/vector/app.tsx index 6483af9b4b..fc168cb117 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -40,7 +40,7 @@ import { logger } from "matrix-js-sdk/src/logger"; let lastLocationHashSet: string = null; -console.log(`Application is running in ${process.env.NODE_ENV} mode`); +logger.log(`Application is running in ${process.env.NODE_ENV} mode`); // Parse the given window.location and return parameters that can be used when calling // MatrixChat.showScreen(screen, params) @@ -57,7 +57,7 @@ function getScreenFromLocation(location: Location) { function routeUrl(location: Location) { if (!window.matrixChat) return; - console.log("Routing URL ", location.href); + logger.log("Routing URL ", location.href); const s = getScreenFromLocation(location); (window.matrixChat as MatrixChatType).showScreen(s.screen, s.params); } @@ -73,7 +73,7 @@ function onHashChange(ev: HashChangeEvent) { // This will be called whenever the SDK changes screens, // so a web page can update the URL bar appropriately. function onNewScreen(screen: string, replaceLast = false) { - console.log("newscreen " + screen); + logger.log("newscreen " + screen); const hash = '#/' + screen; lastLocationHashSet = hash; @@ -135,7 +135,7 @@ function onTokenLoginCompleted() { url.searchParams.delete("loginToken"); - console.log(`Redirecting to ${url.href} to drop loginToken from queryparams`); + logger.log(`Redirecting to ${url.href} to drop loginToken from queryparams`); window.history.replaceState(null, "", url.href); } @@ -147,7 +147,7 @@ export async function loadApp(fragParams: {}) { const params = parseQs(window.location); const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname; - console.log("Vector starting at " + urlWithoutQuery); + logger.log("Vector starting at " + urlWithoutQuery); (platform as VectorBasePlatform).startUpdater(); @@ -160,7 +160,7 @@ export async function loadApp(fragParams: {}) { const isReturningFromSso = !!params.loginToken; const autoRedirect = config['sso_immediate_redirect'] === true; if (!hasPossibleToken && !isReturningFromSso && autoRedirect) { - console.log("Bypassing app load to redirect to SSO"); + logger.log("Bypassing app load to redirect to SSO"); const tempCli = createClient({ baseUrl: config['validated_server_config'].hsUrl, idBaseUrl: config['validated_server_config'].isUrl, @@ -190,7 +190,7 @@ export async function loadApp(fragParams: {}) { async function verifyServerConfig() { let validatedConfig; try { - console.log("Verifying homeserver configuration"); + logger.log("Verifying homeserver configuration"); // Note: the query string may include is_url and hs_url - we only respect these in the // context of email validation. Because we don't respect them otherwise, we do not need @@ -221,7 +221,7 @@ async function verifyServerConfig() { } if (hsUrl) { - console.log("Config uses a default_hs_url - constructing a default_server_config using this information"); + logger.log("Config uses a default_hs_url - constructing a default_server_config using this information"); console.warn( "DEPRECATED CONFIG OPTION: In the future, default_hs_url will not be accepted. Please use " + "default_server_config instead.", @@ -241,12 +241,12 @@ async function verifyServerConfig() { let discoveryResult = null; if (wkConfig) { - console.log("Config uses a default_server_config - validating object"); + logger.log("Config uses a default_server_config - validating object"); discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig); } if (serverName) { - console.log("Config uses a default_server_name - doing .well-known lookup"); + logger.log("Config uses a default_server_name - doing .well-known lookup"); console.warn( "DEPRECATED CONFIG OPTION: In the future, default_server_name will not be accepted. Please " + "use default_server_config instead.", @@ -261,7 +261,7 @@ async function verifyServerConfig() { logger.error(e); console.warn("A session was found - suppressing config error and using the session's homeserver"); - console.log("Using pre-existing hsUrl and isUrl: ", { hsUrl, isUrl }); + logger.log("Using pre-existing hsUrl and isUrl: ", { hsUrl, isUrl }); validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl, true); } else { // the user is not logged in, so scream @@ -272,10 +272,10 @@ async function verifyServerConfig() { validatedConfig.isDefault = true; // Just in case we ever have to debug this - console.log("Using homeserver config:", validatedConfig); + logger.log("Using homeserver config:", validatedConfig); // Add the newly built config to the actual config for use by the app - console.log("Updating SdkConfig with validated discovery information"); + logger.log("Updating SdkConfig with validated discovery information"); SdkConfig.add({ "validated_server_config": validatedConfig }); return SdkConfig.get(); diff --git a/src/vector/index.ts b/src/vector/index.ts index b0a79b6e93..98e692606f 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -181,7 +181,7 @@ async function start() { if (window.localStorage) { window.localStorage.setItem('mx_accepts_unsupported_browser', String(true)); } - console.log("User accepts the compatibility risks."); + logger.log("User accepts the compatibility risks."); resolve(); }); }); diff --git a/src/vector/init.tsx b/src/vector/init.tsx index 46c076186f..9ad9787dd6 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -41,13 +41,13 @@ export const rageshakePromise = initRageshake(); export function preparePlatform() { if (window.electron) { - console.log("Using Electron platform"); + logger.log("Using Electron platform"); PlatformPeg.set(new ElectronPlatform()); } else if (window.matchMedia('(display-mode: standalone)').matches) { - console.log("Using PWA platform"); + logger.log("Using PWA platform"); PlatformPeg.set(new PWAPlatform()); } else { - console.log("Using Web platform"); + logger.log("Using Web platform"); PlatformPeg.set(new WebPlatform()); } } @@ -84,9 +84,9 @@ export function loadOlm(): Promise { return Olm.init({ locateFile: () => olmWasmPath, }).then(() => { - console.log("Using WebAssembly Olm"); + logger.log("Using WebAssembly Olm"); }).catch((e) => { - console.log("Failed to load Olm: trying legacy version", e); + logger.log("Failed to load Olm: trying legacy version", e); return new Promise((resolve, reject) => { const s = document.createElement('script'); s.src = 'olm_legacy.js'; // XXX: This should be cache-busted too @@ -98,9 +98,9 @@ export function loadOlm(): Promise { // not 'Olm' which is still the failed wasm version. return window.Olm.init(); }).then(() => { - console.log("Using legacy Olm"); + logger.log("Using legacy Olm"); }).catch((e) => { - console.log("Both WebAssembly and asm.js Olm failed!", e); + logger.log("Both WebAssembly and asm.js Olm failed!", e); }); }); } @@ -127,7 +127,7 @@ export async function loadLanguage() { export async function loadSkin() { // Ensure the skin is the very first thing to load for the react-sdk. We don't even want to reference // the SDK until we have to in imports. - console.log("Loading skin..."); + logger.log("Loading skin..."); // load these async so that its code is not executed immediately and we can catch any exceptions const [sdk, skin] = await Promise.all([ import( @@ -142,7 +142,7 @@ export async function loadSkin() { "../component-index"), ]); sdk.loadSkin(skin); - console.log("Skin loaded!"); + logger.log("Skin loaded!"); } export async function loadTheme() { diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 82e91248b1..e0fbeb8d75 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -117,7 +117,7 @@ let meetApi: any; // JitsiMeetExternalAPI if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) { // Request credentials, give callback to continue when received openIdToken = await widgetApi.requestOpenIDConnectToken(); - console.log("Got OpenID Connect token"); + logger.log("Got OpenID Connect token"); } // TODO: register widgetApi listeners for PTT controls (https://github.com/vector-im/element-web/issues/12795) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index de9205cc82..1e416f4636 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -247,7 +247,7 @@ export default class ElectronPlatform extends VectorBasePlatform { // try to flush the rageshake logs to indexeddb before quit. electron.on('before-quit', function() { - console.log('element-desktop closing'); + logger.log('element-desktop closing'); rageshake.flush(); }); @@ -533,7 +533,7 @@ export default class ElectronPlatform extends VectorBasePlatform { setSpellCheckLanguages(preferredLangs: string[]) { this.ipcCall('setSpellCheckLanguages', preferredLangs).catch(error => { - console.log("Failed to send setSpellCheckLanguages IPC to Electron"); + logger.log("Failed to send setSpellCheckLanguages IPC to Electron"); logger.error(error); }); } diff --git a/src/vector/rageshakesetup.ts b/src/vector/rageshakesetup.ts index 8e8029d396..8f90182de4 100644 --- a/src/vector/rageshakesetup.ts +++ b/src/vector/rageshakesetup.ts @@ -36,12 +36,12 @@ export function initRageshake() { // we manually check persistence for rageshakes ourselves const prom = rageshake.init(/*setUpPersistence=*/false); prom.then(() => { - console.log("Initialised rageshake."); - console.log("To fix line numbers in Chrome: " + + logger.log("Initialised rageshake."); + logger.log("To fix line numbers in Chrome: " + "Meatball menu → Settings → Ignore list → Add /rageshake\\.js$"); window.addEventListener('beforeunload', (e) => { - console.log('element-web closing'); + logger.log('element-web closing'); // try to flush the logs to indexeddb rageshake.flush(); }); @@ -72,9 +72,9 @@ window.mxSendRageshake = function(text: string, withLogs?: boolean) { sendBugReport(url, { userText: text, sendLogs: withLogs, - progressCallback: console.log.bind(console), + progressCallback: logger.log.bind(console), }).then(() => { - console.log("Bug report sent!"); + logger.log("Bug report sent!"); }, (err) => { logger.error(err); });