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 { 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 });

View File

@ -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<Promise<any>>) {
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<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
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;

View File

@ -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);
}
}

View File

@ -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";
}
})();

View File

@ -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<void> {
}
}
} catch (e) {
console.error(e);
logger.error(e);
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 { 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);
});
}

View File

@ -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);
});
}
}

View File

@ -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',

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 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);
});
};