summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-util/src/logging.ts43
-rw-r--r--packages/taler-wallet-core/src/host-impl.qtart.ts6
-rw-r--r--packages/taler-wallet-core/src/wallet-api-types.ts1
3 files changed, 48 insertions, 2 deletions
diff --git a/packages/taler-util/src/logging.ts b/packages/taler-util/src/logging.ts
index 79fc49cdd..9e6a265b8 100644
--- a/packages/taler-util/src/logging.ts
+++ b/packages/taler-util/src/logging.ts
@@ -14,6 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
+
/**
* Check if we are running under nodejs.
*/
@@ -35,6 +36,8 @@ export enum LogLevel {
let globalLogLevel = LogLevel.Info;
const byTagLogLevel: Record<string, LogLevel> = {};
+let nativeLogging: boolean = false;
+
export function getGlobalLogLevel(): string {
return globalLogLevel;
}
@@ -47,6 +50,10 @@ export function setLogLevelFromString(tag: string, logLevelStr: string): void {
byTagLogLevel[tag] = getLevelForString(logLevelStr);
}
+export function enableNativeLogging() {
+ nativeLogging = true;
+}
+
function getLevelForString(logLevelStr: string): LogLevel {
switch (logLevelStr.toLowerCase()) {
case "trace":
@@ -70,6 +77,24 @@ function getLevelForString(logLevelStr: string): LogLevel {
}
}
+function writeNativeLog(
+ message: any,
+ tag: string,
+ level: number,
+ args: any[],
+): void {
+ const logFn = (globalThis as any).__nativeLog;
+ if (logFn) {
+ let m: string;
+ if (args.length == 0) {
+ m = message;
+ } else {
+ m = message + " " + args.toString();
+ }
+ logFn(level, tag, message);
+ }
+}
+
function writeNodeLog(
message: any,
tag: string,
@@ -102,7 +127,7 @@ function writeNodeLog(
* and uses the corresponding console.* method to log in the browser.
*/
export class Logger {
- constructor(private tag: string) { }
+ constructor(private tag: string) {}
shouldLogTrace(): boolean {
const level = byTagLogLevel[this.tag] ?? globalLogLevel;
@@ -164,6 +189,10 @@ export class Logger {
if (!this.shouldLogInfo()) {
return;
}
+ if (nativeLogging) {
+ writeNativeLog(message, this.tag, 2, args);
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "INFO", args);
} else {
@@ -178,6 +207,10 @@ export class Logger {
if (!this.shouldLogWarn()) {
return;
}
+ if (nativeLogging) {
+ writeNativeLog(message, this.tag, 3, args);
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "WARN", args);
} else {
@@ -192,6 +225,10 @@ export class Logger {
if (!this.shouldLogError()) {
return;
}
+ if (nativeLogging) {
+ writeNativeLog(message, this.tag, 4, args);
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "ERROR", args);
} else {
@@ -206,6 +243,10 @@ export class Logger {
if (!this.shouldLogTrace()) {
return;
}
+ if (nativeLogging) {
+ writeNativeLog(message, this.tag, 1, args);
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "TRACE", args);
} else {
diff --git a/packages/taler-wallet-core/src/host-impl.qtart.ts b/packages/taler-wallet-core/src/host-impl.qtart.ts
index 85f8df6e5..a2fc75e9c 100644
--- a/packages/taler-wallet-core/src/host-impl.qtart.ts
+++ b/packages/taler-wallet-core/src/host-impl.qtart.ts
@@ -38,7 +38,7 @@ import {
import { AccessStats } from "@gnu-taler/idb-bridge";
import { SynchronousCryptoWorkerFactoryPlain } from "./crypto/workers/synchronousWorkerFactoryPlain.js";
import { openTalerDatabase } from "./index.js";
-import { Logger } from "@gnu-taler/taler-util";
+import { Logger, enableNativeLogging } from "@gnu-taler/taler-util";
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { SetTimeoutTimerAPI } from "./util/timer.js";
import { Wallet } from "./wallet.js";
@@ -167,6 +167,10 @@ export async function createNativeWalletHost2(
let dbResp: MakeDbResult;
+ if (args.config?.features?.useNativeLogging) {
+ enableNativeLogging();
+ }
+
if (
args.persistentStoragePath &&
args.persistentStoragePath.endsWith(".json")
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
index b974aa4bb..daffd40ac 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -292,6 +292,7 @@ export interface WalletConfig {
*/
features: {
allowHttp: boolean;
+ useNativeLogging: boolean;
};
}