[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: wallet-core: native logging s
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: wallet-core: native logging support |
Date: |
Mon, 23 Oct 2023 16:16:56 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 8ba62f7e0 wallet-core: native logging support
8ba62f7e0 is described below
commit 8ba62f7e0e0e6208738ccff2c9da99e6353ec961
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Oct 23 16:16:52 2023 +0200
wallet-core: native logging support
---
packages/taler-util/src/logging.ts | 43 +++++++++++++++++++++-
packages/taler-wallet-core/src/host-impl.qtart.ts | 6 ++-
packages/taler-wallet-core/src/wallet-api-types.ts | 1 +
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;
};
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: wallet-core: native logging support,
gnunet <=