Replace console.error with logger.error

Related https://github.com/vector-im/element-web/issues/18425
This commit is contained in:
Dariusz Niemczyk 2021-10-15 16:56:22 +02:00 committed by Dariusz Niemczyk
parent 515a8d2097
commit db01bfc0fd
9 changed files with 36 additions and 18 deletions

View file

@ -36,6 +36,8 @@ import { parseQs, parseQsFromFragment } from './url_utils';
import VectorBasePlatform from "./platform/VectorBasePlatform"; import VectorBasePlatform from "./platform/VectorBasePlatform";
import { createClient } from "matrix-js-sdk/src/matrix"; import { createClient } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
let lastLocationHashSet: string = null; let lastLocationHashSet: string = null;
console.log(`Application is running in ${process.env.NODE_ENV} mode`); console.log(`Application is running in ${process.env.NODE_ENV} mode`);
@ -256,7 +258,7 @@ async function verifyServerConfig() {
} catch (e) { } catch (e) {
const { hsUrl, isUrl, userId } = await Lifecycle.getStoredSessionVars(); const { hsUrl, isUrl, userId } = await Lifecycle.getStoredSessionVars();
if (hsUrl && userId) { 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.warn("A session was found - suppressing config error and using the session's homeserver");
console.log("Using pre-existing hsUrl and isUrl: ", { hsUrl, isUrl }); console.log("Using pre-existing hsUrl and isUrl: ", { hsUrl, isUrl });

View file

@ -38,19 +38,21 @@ require('./localstorage-fix');
import { parseQsFromFragment } from "./url_utils"; import { parseQsFromFragment } from "./url_utils";
import './modernizr'; import './modernizr';
import { logger } from "matrix-js-sdk/src/logger";
async function settled(...promises: Array<Promise<any>>) { async function settled(...promises: Array<Promise<any>>) {
for (const prom of promises) { for (const prom of promises) {
try { try {
await prom; await prom;
} catch (e) { } catch (e) {
console.error(e); logger.error(e);
} }
} }
} }
function checkBrowserFeatures() { function checkBrowserFeatures() {
if (!window.Modernizr) { if (!window.Modernizr) {
console.error("Cannot check features - Modernizr global is missing."); logger.error("Cannot check features - Modernizr global is missing.");
return false; return false;
} }
@ -77,14 +79,14 @@ function checkBrowserFeatures() {
let featureComplete = true; let featureComplete = true;
for (let i = 0; i < featureList.length; i++) { for (let i = 0; i < featureList.length; i++) {
if (window.Modernizr[featureList[i]] === undefined) { if (window.Modernizr[featureList[i]] === undefined) {
console.error( logger.error(
"Looked for feature '%s' but Modernizr has no results for this. " + "Looked for feature '%s' but Modernizr has no results for this. " +
"Has it been configured correctly?", featureList[i], "Has it been configured correctly?", featureList[i],
); );
return false; return false;
} }
if (window.Modernizr[featureList[i]] === 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. // toggle flag rather than return early so we log all missing features rather than just the first.
featureComplete = false; featureComplete = false;
} }
@ -173,7 +175,7 @@ async function start() {
// ########################## // ##########################
if (!acceptBrowser) { if (!acceptBrowser) {
await new Promise<void>(resolve => { await new Promise<void>(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 // take to a different landing page to AWOOOOOGA at the user
showIncompatibleBrowser(() => { showIncompatibleBrowser(() => {
if (window.localStorage) { if (window.localStorage) {
@ -222,7 +224,7 @@ async function start() {
// run on the components. // run on the components.
await loadApp(fragparts.params); await loadApp(fragparts.params);
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
// Like the compatibility page, AWOOOOOGA at the user // Like the compatibility page, AWOOOOOGA at the user
// This uses the default brand since the app config is unavailable. // This uses the default brand since the app config is unavailable.
await showError(_t("Your Element is misconfigured"), [ await showError(_t("Your Element is misconfigured"), [
@ -232,7 +234,7 @@ async function start() {
} }
start().catch(err => { start().catch(err => {
console.error(err); logger.error(err);
// show the static error in an iframe to not lose any context / console data // show the static error in an iframe to not lose any context / console data
// with some basic styling to make the iframe full page // with some basic styling to make the iframe full page
delete document.body.style.height; delete document.body.style.height;

View file

@ -35,6 +35,8 @@ import { setTheme } from "matrix-react-sdk/src/theme";
import { initRageshake, initRageshakeStore } from "./rageshakesetup"; import { initRageshake, initRageshakeStore } from "./rageshakesetup";
import { logger } from "matrix-js-sdk/src/logger";
export const rageshakePromise = initRageshake(); export const rageshakePromise = initRageshake();
export function preparePlatform() { export function preparePlatform() {
@ -118,7 +120,7 @@ export async function loadLanguage() {
await languageHandler.setLanguage(langs); await languageHandler.setLanguage(langs);
document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage()); document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage());
} catch (e) { } catch (e) {
console.error("Unable to set language", e); logger.error("Unable to set language", e);
} }
} }

View file

@ -26,6 +26,8 @@ import {
} from "matrix-widget-api"; } from "matrix-widget-api";
import { ElementWidgetActions } from "matrix-react-sdk/src/stores/widgets/ElementWidgetActions"; 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'; const JITSI_OPENIDTOKEN_JWT_AUTH = 'openidtoken-jwt';
// Dev note: we use raw JS without many dependencies to reduce bundle size. // 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 enableJoinButton(); // always enable the button
} catch (e) { } 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"; document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget";
} }
})(); })();

View file

@ -1,5 +1,7 @@
import { getVectorConfig } from '../getconfig'; import { getVectorConfig } from '../getconfig';
import { logger } from "matrix-js-sdk/src/logger";
function onBackToElementClick(): void { function onBackToElementClick(): void {
// Cookie should expire in 4 hours // Cookie should expire in 4 hours
document.cookie = 'element_mobile_redirect_to_guide=false;path=/;max-age=14400'; document.cookie = 'element_mobile_redirect_to_guide=false;path=/;max-age=14400';
@ -76,7 +78,7 @@ async function initPage(): Promise<void> {
} }
} }
} catch (e) { } catch (e) {
console.error(e); logger.error(e);
return renderConfigError("Unable to fetch homeserver configuration"); return renderConfigError("Unable to fetch homeserver configuration");
} }
} }

View file

@ -55,6 +55,8 @@ import { IMatrixProfile, IEventWithRoomId as IMatrixEvent, IResultRoomEvents } f
import VectorBasePlatform from './VectorBasePlatform'; import VectorBasePlatform from './VectorBasePlatform';
import { logger } from "matrix-js-sdk/src/logger";
const electron = window.electron; const electron = window.electron;
const isMac = navigator.platform.toUpperCase().includes('MAC'); const isMac = navigator.platform.toUpperCase().includes('MAC');
@ -532,7 +534,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
setSpellCheckLanguages(preferredLangs: string[]) { setSpellCheckLanguages(preferredLangs: string[]) {
this.ipcCall('setSpellCheckLanguages', preferredLangs).catch(error => { this.ipcCall('setSpellCheckLanguages', preferredLangs).catch(error => {
console.log("Failed to send setSpellCheckLanguages IPC to Electron"); console.log("Failed to send setSpellCheckLanguages IPC to Electron");
console.error(error); logger.error(error);
}); });
} }

View file

@ -16,6 +16,8 @@ limitations under the License.
import WebPlatform from "./WebPlatform"; import WebPlatform from "./WebPlatform";
import { logger } from "matrix-js-sdk/src/logger";
export default class PWAPlatform extends WebPlatform { export default class PWAPlatform extends WebPlatform {
setNotificationCount(count: number) { setNotificationCount(count: number) {
if (!navigator.setAppBadge) return super.setNotificationCount(count); if (!navigator.setAppBadge) return super.setNotificationCount(count);
@ -23,7 +25,7 @@ export default class PWAPlatform extends WebPlatform {
this.notificationCount = count; this.notificationCount = count;
navigator.setAppBadge(count).catch(e => { navigator.setAppBadge(count).catch(e => {
console.error("Failed to update PWA app badge", e); logger.error("Failed to update PWA app badge", e);
}); });
} }
} }

View file

@ -28,6 +28,8 @@ import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/Ch
import UAParser from 'ua-parser-js'; import UAParser from 'ua-parser-js';
import { logger } from "matrix-js-sdk/src/logger";
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
export default class WebPlatform extends VectorBasePlatform { export default class WebPlatform extends VectorBasePlatform {
@ -159,7 +161,7 @@ export default class WebPlatform extends VectorBasePlatform {
return { status: UpdateCheckStatus.NotAvailable }; return { status: UpdateCheckStatus.NotAvailable };
}, (err) => { }, (err) => {
console.error("Failed to poll for update", err); logger.error("Failed to poll for update", err);
return { return {
status: UpdateCheckStatus.Error, status: UpdateCheckStatus.Error,
detail: err.message || err.status ? err.status.toString() : 'Unknown Error', detail: err.message || err.status ? err.status.toString() : 'Unknown Error',

View file

@ -30,6 +30,8 @@ import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake";
import SdkConfig from "matrix-react-sdk/src/SdkConfig"; import SdkConfig from "matrix-react-sdk/src/SdkConfig";
import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake"; import sendBugReport from "matrix-react-sdk/src/rageshake/submit-rageshake";
import { logger } from "matrix-js-sdk/src/logger";
export function initRageshake() { export function initRageshake() {
// we manually check persistence for rageshakes ourselves // we manually check persistence for rageshakes ourselves
const prom = rageshake.init(/*setUpPersistence=*/false); const prom = rageshake.init(/*setUpPersistence=*/false);
@ -46,7 +48,7 @@ export function initRageshake() {
rageshake.cleanup(); rageshake.cleanup();
}, (err) => { }, (err) => {
console.error("Failed to initialise rageshake: " + err); logger.error("Failed to initialise rageshake: " + err);
}); });
return prom; return prom;
} }
@ -58,13 +60,13 @@ export function initRageshakeStore() {
window.mxSendRageshake = function(text: string, withLogs?: boolean) { window.mxSendRageshake = function(text: string, withLogs?: boolean) {
const url = SdkConfig.get().bug_report_endpoint_url; const url = SdkConfig.get().bug_report_endpoint_url;
if (!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; return;
} }
if (withLogs === undefined) withLogs = true; if (withLogs === undefined) withLogs = true;
if (!text || !text.trim()) { 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; return;
} }
sendBugReport(url, { sendBugReport(url, {
@ -74,6 +76,6 @@ window.mxSendRageshake = function(text: string, withLogs?: boolean) {
}).then(() => { }).then(() => {
console.log("Bug report sent!"); console.log("Bug report sent!");
}, (err) => { }, (err) => {
console.error(err); logger.error(err);
}); });
}; };