aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-11-07 11:49:34 +0100
committerFlorian Dold <florian@dold.me>2022-11-07 11:49:44 +0100
commit5664c6c9b3493f0e44ce065514c51964f9d5b8ba (patch)
tree71f4c8bc397f40821ce452ee8116136a91a69a48
parent661469f878271a9a8f0f90c5f067dec669f47a36 (diff)
taler-wallet-embedded: log with logger, not console API
-rw-r--r--packages/taler-wallet-embedded/src/index.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/taler-wallet-embedded/src/index.ts b/packages/taler-wallet-embedded/src/index.ts
index 00716d998..ab8fdd32b 100644
--- a/packages/taler-wallet-embedded/src/index.ts
+++ b/packages/taler-wallet-embedded/src/index.ts
@@ -39,12 +39,15 @@ import {
CoreApiEnvelope,
CoreApiResponse,
CoreApiResponseSuccess,
+ Logger,
WalletNotification,
} from "@gnu-taler/taler-util";
import fs from "fs";
export { handleWorkerError, handleWorkerMessage };
+const logger = new Logger("taler-wallet-embedded/index.ts");
+
export class NativeHttpLib implements HttpRequestLibrary {
useNfcTunnel = false;
@@ -111,7 +114,7 @@ export class NativeHttpLib implements HttpRequestLibrary {
const myId = msg.id;
const p = this.requestMap[myId];
if (!p) {
- console.error(
+ logger.error(
`no matching request for tunneled HTTP response, id=${myId}`,
);
}
@@ -143,7 +146,7 @@ function sendNativeMessage(ev: CoreApiEnvelope): void {
if (typeof sendMessage !== "function") {
const errMsg =
"FATAL: cannot install native wallet listener: native functions missing";
- console.error(errMsg);
+ logger.error(errMsg);
throw new Error(errMsg);
}
const m = JSON.stringify(ev);
@@ -177,7 +180,7 @@ class NativeWalletMessageHandler {
let initResponse: any = {};
const reinit = async () => {
- console.error("in reinit");
+ logger.info("in reinit");
const w = await getDefaultNodeWallet(this.walletArgs);
this.maybeWallet = w;
const resp = await w.handleCoreApiRequest(
@@ -187,7 +190,9 @@ class NativeWalletMessageHandler {
);
initResponse = resp.type == "response" ? resp.result : resp.error;
w.runTaskLoop().catch((e) => {
- console.error("Error during wallet retry loop", e);
+ logger.error(
+ `Error during wallet retry loop: ${e.stack ?? e.toString()}`,
+ );
});
this.wp.resolve(w);
};
@@ -226,7 +231,7 @@ class NativeWalletMessageHandler {
try {
fs.unlinkSync(oldArgs.persistentStoragePath);
} catch (e) {
- console.error("Error while deleting the wallet db:", e);
+ logger.error("Error while deleting the wallet db:", e);
}
// Prevent further storage!
this.walletArgs.persistentStoragePath = undefined;
@@ -250,23 +255,23 @@ export function installNativeWalletListener(): void {
const handler = new NativeWalletMessageHandler();
const onMessage = async (msgStr: any): Promise<void> => {
if (typeof msgStr !== "string") {
- console.error("expected string as message");
+ logger.error("expected string as message");
return;
}
const msg = JSON.parse(msgStr);
const operation = msg.operation;
if (typeof operation !== "string") {
- console.error(
+ logger.error(
"message to native wallet helper must contain operation of type string",
);
return;
}
const id = msg.id;
- console.log(`native listener: got request for ${operation} (${id})`);
+ logger.info(`native listener: got request for ${operation} (${id})`);
try {
const respMsg = await handler.handleMessage(operation, id, msg.args);
- console.log(
+ logger.info(
`native listener: sending success response for ${operation} (${id})`,
);
sendNativeMessage(respMsg);
@@ -285,5 +290,5 @@ export function installNativeWalletListener(): void {
// @ts-ignore
globalThis.__native_onMessage = onMessage;
- console.log("native wallet listener installed");
+ logger.info("native wallet listener installed");
}