diff --git a/src/vector/app.tsx b/src/vector/app.tsx index 35e20a083..6483af9b4 100644 --- a/src/vector/app.tsx +++ b/src/vector/app.tsx @@ -36,6 +36,8 @@ import { parseQs, parseQsFromFragment } from './url_utils'; import VectorBasePlatform from "./platform/VectorBasePlatform"; import { createClient } from "matrix-js-sdk/src/matrix"; +import { logger } from "matrix-js-sdk/src/logger"; + let lastLocationHashSet: string = null; console.log(`Application is running in ${process.env.NODE_ENV} mode`); @@ -256,7 +258,7 @@ async function verifyServerConfig() { } catch (e) { const { hsUrl, isUrl, userId } = await Lifecycle.getStoredSessionVars(); if (hsUrl && userId) { - console.error(e); + 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 }); diff --git a/src/vector/index.ts b/src/vector/index.ts index e23fc4b35..b0a79b6e9 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -38,19 +38,21 @@ require('./localstorage-fix'); import { parseQsFromFragment } from "./url_utils"; import './modernizr'; +import { logger } from "matrix-js-sdk/src/logger"; + async function settled(...promises: Array>) { for (const prom of promises) { try { await prom; } catch (e) { - console.error(e); + logger.error(e); } } } function checkBrowserFeatures() { if (!window.Modernizr) { - console.error("Cannot check features - Modernizr global is missing."); + logger.error("Cannot check features - Modernizr global is missing."); return false; } @@ -77,14 +79,14 @@ function checkBrowserFeatures() { let featureComplete = true; for (let i = 0; i < featureList.length; i++) { if (window.Modernizr[featureList[i]] === undefined) { - console.error( + logger.error( "Looked for feature '%s' but Modernizr has no results for this. " + "Has it been configured correctly?", featureList[i], ); return false; } if (window.Modernizr[featureList[i]] === false) { - console.error("Browser missing feature: '%s'", featureList[i]); + logger.error("Browser missing feature: '%s'", featureList[i]); // toggle flag rather than return early so we log all missing features rather than just the first. featureComplete = false; } @@ -173,7 +175,7 @@ async function start() { // ########################## if (!acceptBrowser) { await new Promise(resolve => { - console.error("Browser is missing required features."); + logger.error("Browser is missing required features."); // take to a different landing page to AWOOOOOGA at the user showIncompatibleBrowser(() => { if (window.localStorage) { @@ -222,7 +224,7 @@ async function start() { // run on the components. await loadApp(fragparts.params); } catch (err) { - console.error(err); + logger.error(err); // Like the compatibility page, AWOOOOOGA at the user // This uses the default brand since the app config is unavailable. await showError(_t("Your Element is misconfigured"), [ @@ -232,7 +234,7 @@ async function start() { } start().catch(err => { - console.error(err); + logger.error(err); // show the static error in an iframe to not lose any context / console data // with some basic styling to make the iframe full page delete document.body.style.height; diff --git a/src/vector/init.tsx b/src/vector/init.tsx index 66389df8a..46c076186 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -35,6 +35,8 @@ import { setTheme } from "matrix-react-sdk/src/theme"; import { initRageshake, initRageshakeStore } from "./rageshakesetup"; +import { logger } from "matrix-js-sdk/src/logger"; + export const rageshakePromise = initRageshake(); export function preparePlatform() { @@ -118,7 +120,7 @@ export async function loadLanguage() { await languageHandler.setLanguage(langs); document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage()); } catch (e) { - console.error("Unable to set language", e); + logger.error("Unable to set language", e); } } diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index c6385cc47..82e91248b 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -26,6 +26,8 @@ import { } from "matrix-widget-api"; import { ElementWidgetActions } from "matrix-react-sdk/src/stores/widgets/ElementWidgetActions"; +import { logger } from "matrix-js-sdk/src/logger"; + const JITSI_OPENIDTOKEN_JWT_AUTH = 'openidtoken-jwt'; // Dev note: we use raw JS without many dependencies to reduce bundle size. @@ -146,7 +148,7 @@ let meetApi: any; // JitsiMeetExternalAPI enableJoinButton(); // always enable the button } catch (e) { - console.error("Error setting up Jitsi widget", e); + logger.error("Error setting up Jitsi widget", e); document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget"; } })(); diff --git a/src/vector/mobile_guide/index.ts b/src/vector/mobile_guide/index.ts index f27d414f0..1eecf1dc7 100644 --- a/src/vector/mobile_guide/index.ts +++ b/src/vector/mobile_guide/index.ts @@ -1,5 +1,7 @@ import { getVectorConfig } from '../getconfig'; +import { logger } from "matrix-js-sdk/src/logger"; + function onBackToElementClick(): void { // Cookie should expire in 4 hours document.cookie = 'element_mobile_redirect_to_guide=false;path=/;max-age=14400'; @@ -76,7 +78,7 @@ async function initPage(): Promise { } } } catch (e) { - console.error(e); + logger.error(e); return renderConfigError("Unable to fetch homeserver configuration"); } } diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 287d7bab8..de9205cc8 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -55,6 +55,8 @@ import { IMatrixProfile, IEventWithRoomId as IMatrixEvent, IResultRoomEvents } f import VectorBasePlatform from './VectorBasePlatform'; +import { logger } from "matrix-js-sdk/src/logger"; + const electron = window.electron; const isMac = navigator.platform.toUpperCase().includes('MAC'); @@ -532,7 +534,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"); - console.error(error); + logger.error(error); }); } diff --git a/src/vector/platform/PWAPlatform.ts b/src/vector/platform/PWAPlatform.ts index cca3a8e7d..9ba3eaade 100644 --- a/src/vector/platform/PWAPlatform.ts +++ b/src/vector/platform/PWAPlatform.ts @@ -16,6 +16,8 @@ limitations under the License. import WebPlatform from "./WebPlatform"; +import { logger } from "matrix-js-sdk/src/logger"; + export default class PWAPlatform extends WebPlatform { setNotificationCount(count: number) { if (!navigator.setAppBadge) return super.setNotificationCount(count); @@ -23,7 +25,7 @@ export default class PWAPlatform extends WebPlatform { this.notificationCount = count; navigator.setAppBadge(count).catch(e => { - console.error("Failed to update PWA app badge", e); + logger.error("Failed to update PWA app badge", e); }); } } diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index 454c8250d..bb2a52f24 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -28,6 +28,8 @@ import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/Ch import UAParser from 'ua-parser-js'; +import { logger } from "matrix-js-sdk/src/logger"; + const POKE_RATE_MS = 10 * 60 * 1000; // 10 min export default class WebPlatform extends VectorBasePlatform { @@ -159,7 +161,7 @@ export default class WebPlatform extends VectorBasePlatform { return { status: UpdateCheckStatus.NotAvailable }; }, (err) => { - console.error("Failed to poll for update", err); + logger.error("Failed to poll for update", err); return { status: UpdateCheckStatus.Error, detail: err.message || err.status ? err.status.toString() : 'Unknown Error', diff --git a/src/vector/rageshakesetup.ts b/src/vector/rageshakesetup.ts index 02161331f..8e8029d39 100644 --- a/src/vector/rageshakesetup.ts +++ b/src/vector/rageshakesetup.ts @@ -30,6 +30,8 @@ import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake"; import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake"; +import { logger } from "matrix-js-sdk/src/logger"; + export function initRageshake() { // we manually check persistence for rageshakes ourselves const prom = rageshake.init(/*setUpPersistence=*/false); @@ -46,7 +48,7 @@ export function initRageshake() { rageshake.cleanup(); }, (err) => { - console.error("Failed to initialise rageshake: " + err); + logger.error("Failed to initialise rageshake: " + err); }); return prom; } @@ -58,13 +60,13 @@ export function initRageshakeStore() { window.mxSendRageshake = function(text: string, withLogs?: boolean) { const url = SdkConfig.get().bug_report_endpoint_url; if (!url) { - console.error("Cannot send a rageshake - no bug_report_endpoint_url configured"); + logger.error("Cannot send a rageshake - no bug_report_endpoint_url configured"); return; } if (withLogs === undefined) withLogs = true; if (!text || !text.trim()) { - console.error("Cannot send a rageshake without a message - please tell us what went wrong"); + logger.error("Cannot send a rageshake without a message - please tell us what went wrong"); return; } sendBugReport(url, { @@ -74,6 +76,6 @@ window.mxSendRageshake = function(text: string, withLogs?: boolean) { }).then(() => { console.log("Bug report sent!"); }, (err) => { - console.error(err); + logger.error(err); }); };