Replace remaining console calls with logger calls

This commit is contained in:
hensm
2020-01-23 01:14:57 +00:00
parent 7f84b90431
commit f6e09ca687
8 changed files with 46 additions and 27 deletions

View File

@@ -69,10 +69,10 @@ async function getInfo (): Promise<BridgeInfo> {
// Print compatibility info to console
if (!isVersionCompatible) {
console.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}.`
, isVersionOlder
logger.error(`Expecting ${applicationName} v${APPLICATION_VERSION}, found v${applicationVersion}. ${
isVersionOlder
? "Try updating the native app to the latest version."
: "Try updating the extension to the latest version");
: "Try updating the extension to the latest version"}`);
}
return {

View File

@@ -3,15 +3,30 @@
export class Logger {
constructor (private prefix: string) {}
log (message: string) {
console.log(`${this.prefix} (Log): ${message}`);
log (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Log): ${message}`;
if (data) {
console.log(formattedMessage, data);
} else {
console.log(formattedMessage);
}
}
debug (message: string) {
console.debug(`${this.prefix} (Debug): ${message}`);
info (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Info): ${message}`;
if (data) {
console.info(formattedMessage, data);
} else {
console.info(formattedMessage);
}
}
error (message: string) {
error (message: string, data?: any) {
const formattedMessage = `${this.prefix} (Error): ${message}`;
console.error(formattedMessage);
if (data) {
console.error(formattedMessage, data);
} else {
console.error(formattedMessage);
}
return new Error(formattedMessage);
}
}

View File

@@ -1,5 +1,7 @@
"use strict";
import logger from "./logger";
const WEBSOCKET_DAEMON_URL = "ws://localhost:9556";
@@ -164,7 +166,7 @@ async function sendNativeMessage (
});
ws.addEventListener("error", () => {
console.error("fx_cast (Debug): No bridge application found.");
logger.error("No bridge application found.");
reject();
});
});