taler-wallet-embedded: log with logger, not console API

This commit is contained in:
Florian Dold 2022-11-07 11:49:34 +01:00
parent 661469f878
commit 5664c6c9b3
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -39,12 +39,15 @@ import {
CoreApiEnvelope, CoreApiEnvelope,
CoreApiResponse, CoreApiResponse,
CoreApiResponseSuccess, CoreApiResponseSuccess,
Logger,
WalletNotification, WalletNotification,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import fs from "fs"; import fs from "fs";
export { handleWorkerError, handleWorkerMessage }; export { handleWorkerError, handleWorkerMessage };
const logger = new Logger("taler-wallet-embedded/index.ts");
export class NativeHttpLib implements HttpRequestLibrary { export class NativeHttpLib implements HttpRequestLibrary {
useNfcTunnel = false; useNfcTunnel = false;
@ -111,7 +114,7 @@ export class NativeHttpLib implements HttpRequestLibrary {
const myId = msg.id; const myId = msg.id;
const p = this.requestMap[myId]; const p = this.requestMap[myId];
if (!p) { if (!p) {
console.error( logger.error(
`no matching request for tunneled HTTP response, id=${myId}`, `no matching request for tunneled HTTP response, id=${myId}`,
); );
} }
@ -143,7 +146,7 @@ function sendNativeMessage(ev: CoreApiEnvelope): void {
if (typeof sendMessage !== "function") { if (typeof sendMessage !== "function") {
const errMsg = const errMsg =
"FATAL: cannot install native wallet listener: native functions missing"; "FATAL: cannot install native wallet listener: native functions missing";
console.error(errMsg); logger.error(errMsg);
throw new Error(errMsg); throw new Error(errMsg);
} }
const m = JSON.stringify(ev); const m = JSON.stringify(ev);
@ -177,7 +180,7 @@ class NativeWalletMessageHandler {
let initResponse: any = {}; let initResponse: any = {};
const reinit = async () => { const reinit = async () => {
console.error("in reinit"); logger.info("in reinit");
const w = await getDefaultNodeWallet(this.walletArgs); const w = await getDefaultNodeWallet(this.walletArgs);
this.maybeWallet = w; this.maybeWallet = w;
const resp = await w.handleCoreApiRequest( const resp = await w.handleCoreApiRequest(
@ -187,7 +190,9 @@ class NativeWalletMessageHandler {
); );
initResponse = resp.type == "response" ? resp.result : resp.error; initResponse = resp.type == "response" ? resp.result : resp.error;
w.runTaskLoop().catch((e) => { 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); this.wp.resolve(w);
}; };
@ -226,7 +231,7 @@ class NativeWalletMessageHandler {
try { try {
fs.unlinkSync(oldArgs.persistentStoragePath); fs.unlinkSync(oldArgs.persistentStoragePath);
} catch (e) { } catch (e) {
console.error("Error while deleting the wallet db:", e); logger.error("Error while deleting the wallet db:", e);
} }
// Prevent further storage! // Prevent further storage!
this.walletArgs.persistentStoragePath = undefined; this.walletArgs.persistentStoragePath = undefined;
@ -250,23 +255,23 @@ export function installNativeWalletListener(): void {
const handler = new NativeWalletMessageHandler(); const handler = new NativeWalletMessageHandler();
const onMessage = async (msgStr: any): Promise<void> => { const onMessage = async (msgStr: any): Promise<void> => {
if (typeof msgStr !== "string") { if (typeof msgStr !== "string") {
console.error("expected string as message"); logger.error("expected string as message");
return; return;
} }
const msg = JSON.parse(msgStr); const msg = JSON.parse(msgStr);
const operation = msg.operation; const operation = msg.operation;
if (typeof operation !== "string") { if (typeof operation !== "string") {
console.error( logger.error(
"message to native wallet helper must contain operation of type string", "message to native wallet helper must contain operation of type string",
); );
return; return;
} }
const id = msg.id; const id = msg.id;
console.log(`native listener: got request for ${operation} (${id})`); logger.info(`native listener: got request for ${operation} (${id})`);
try { try {
const respMsg = await handler.handleMessage(operation, id, msg.args); const respMsg = await handler.handleMessage(operation, id, msg.args);
console.log( logger.info(
`native listener: sending success response for ${operation} (${id})`, `native listener: sending success response for ${operation} (${id})`,
); );
sendNativeMessage(respMsg); sendNativeMessage(respMsg);
@ -285,5 +290,5 @@ export function installNativeWalletListener(): void {
// @ts-ignore // @ts-ignore
globalThis.__native_onMessage = onMessage; globalThis.__native_onMessage = onMessage;
console.log("native wallet listener installed"); logger.info("native wallet listener installed");
} }