taler-wallet: implement log level, use new wallet for every benchmark iteration
This commit is contained in:
parent
e627f65f3c
commit
6fc3aa0b31
@ -23,6 +23,47 @@ const isNode =
|
|||||||
typeof process.release !== "undefined" &&
|
typeof process.release !== "undefined" &&
|
||||||
process.release.name === "node";
|
process.release.name === "node";
|
||||||
|
|
||||||
|
export enum LogLevel {
|
||||||
|
Trace = "trace",
|
||||||
|
Message = "message",
|
||||||
|
Info = "info",
|
||||||
|
Warn = "warn",
|
||||||
|
Error = "error",
|
||||||
|
None = "none",
|
||||||
|
}
|
||||||
|
|
||||||
|
export let globalLogLevel = LogLevel.Info;
|
||||||
|
|
||||||
|
export function setGlobalLogLevelFromString(logLevelStr: string) {
|
||||||
|
let level: LogLevel;
|
||||||
|
switch (logLevelStr.toLowerCase()) {
|
||||||
|
case "trace":
|
||||||
|
level = LogLevel.Trace;
|
||||||
|
break;
|
||||||
|
case "info":
|
||||||
|
level = LogLevel.Info;
|
||||||
|
break;
|
||||||
|
case "warn":
|
||||||
|
case "warning":
|
||||||
|
level = LogLevel.Warn;
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
level = LogLevel.Error;
|
||||||
|
break;
|
||||||
|
case "none":
|
||||||
|
level = LogLevel.None;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (isNode) {
|
||||||
|
process.stderr.write(`Invalid log level, defaulting to WARNING`);
|
||||||
|
} else {
|
||||||
|
console.warn(`Invalid log level, defaulting to WARNING`);
|
||||||
|
}
|
||||||
|
level = LogLevel.Warn;
|
||||||
|
}
|
||||||
|
globalLogLevel = level;
|
||||||
|
}
|
||||||
|
|
||||||
function writeNodeLog(
|
function writeNodeLog(
|
||||||
message: any,
|
message: any,
|
||||||
tag: string,
|
tag: string,
|
||||||
@ -57,21 +98,60 @@ export class Logger {
|
|||||||
constructor(private tag: string) {}
|
constructor(private tag: string) {}
|
||||||
|
|
||||||
shouldLogTrace() {
|
shouldLogTrace() {
|
||||||
// FIXME: Implement logic to check loglevel
|
switch (globalLogLevel) {
|
||||||
|
case LogLevel.Trace:
|
||||||
return true;
|
return true;
|
||||||
|
case LogLevel.Message:
|
||||||
|
case LogLevel.Info:
|
||||||
|
case LogLevel.Warn:
|
||||||
|
case LogLevel.Error:
|
||||||
|
case LogLevel.None:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldLogInfo() {
|
shouldLogInfo() {
|
||||||
// FIXME: Implement logic to check loglevel
|
switch (globalLogLevel) {
|
||||||
|
case LogLevel.Trace:
|
||||||
|
case LogLevel.Message:
|
||||||
|
case LogLevel.Info:
|
||||||
return true;
|
return true;
|
||||||
|
case LogLevel.Warn:
|
||||||
|
case LogLevel.Error:
|
||||||
|
case LogLevel.None:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldLogWarn() {
|
shouldLogWarn() {
|
||||||
// FIXME: Implement logic to check loglevel
|
switch (globalLogLevel) {
|
||||||
|
case LogLevel.Trace:
|
||||||
|
case LogLevel.Message:
|
||||||
|
case LogLevel.Info:
|
||||||
|
case LogLevel.Warn:
|
||||||
return true;
|
return true;
|
||||||
|
case LogLevel.Error:
|
||||||
|
case LogLevel.None:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldLogError() {
|
||||||
|
switch (globalLogLevel) {
|
||||||
|
case LogLevel.Trace:
|
||||||
|
case LogLevel.Message:
|
||||||
|
case LogLevel.Info:
|
||||||
|
case LogLevel.Warn:
|
||||||
|
case LogLevel.Error:
|
||||||
|
case LogLevel.None:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info(message: string, ...args: any[]): void {
|
info(message: string, ...args: any[]): void {
|
||||||
|
if (!this.shouldLogInfo()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
writeNodeLog(message, this.tag, "INFO", args);
|
writeNodeLog(message, this.tag, "INFO", args);
|
||||||
} else {
|
} else {
|
||||||
@ -83,6 +163,9 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
warn(message: string, ...args: any[]): void {
|
warn(message: string, ...args: any[]): void {
|
||||||
|
if (!this.shouldLogWarn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
writeNodeLog(message, this.tag, "WARN", args);
|
writeNodeLog(message, this.tag, "WARN", args);
|
||||||
} else {
|
} else {
|
||||||
@ -94,6 +177,9 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
error(message: string, ...args: any[]): void {
|
error(message: string, ...args: any[]): void {
|
||||||
|
if (!this.shouldLogError()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
writeNodeLog(message, this.tag, "ERROR", args);
|
writeNodeLog(message, this.tag, "ERROR", args);
|
||||||
} else {
|
} else {
|
||||||
@ -105,6 +191,9 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trace(message: any, ...args: any[]): void {
|
trace(message: any, ...args: any[]): void {
|
||||||
|
if (!this.shouldLogTrace()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
writeNodeLog(message, this.tag, "TRACE", args);
|
writeNodeLog(message, this.tag, "TRACE", args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,6 +40,10 @@ export async function runBench1(configJson: any): Promise<void> {
|
|||||||
const b1conf = codecForBench1Config().decode(configJson);
|
const b1conf = codecForBench1Config().decode(configJson);
|
||||||
|
|
||||||
const myHttpLib = new NodeHttpLib();
|
const myHttpLib = new NodeHttpLib();
|
||||||
|
|
||||||
|
const numIter = b1conf.iterations ?? 1;
|
||||||
|
|
||||||
|
for (let i = 0; i < numIter; i++) {
|
||||||
const wallet = await getDefaultNodeWallet({
|
const wallet = await getDefaultNodeWallet({
|
||||||
// No persistent DB storage.
|
// No persistent DB storage.
|
||||||
persistentStoragePath: undefined,
|
persistentStoragePath: undefined,
|
||||||
@ -47,9 +51,6 @@ export async function runBench1(configJson: any): Promise<void> {
|
|||||||
});
|
});
|
||||||
await wallet.client.call(WalletApiOperation.InitWallet, {});
|
await wallet.client.call(WalletApiOperation.InitWallet, {});
|
||||||
|
|
||||||
const numIter = b1conf.iterations ?? 1;
|
|
||||||
|
|
||||||
for (let i = 0; i < numIter; i++) {
|
|
||||||
await wallet.client.call(WalletApiOperation.WithdrawFakebank, {
|
await wallet.client.call(WalletApiOperation.WithdrawFakebank, {
|
||||||
amount: "TESTKUDOS:10",
|
amount: "TESTKUDOS:10",
|
||||||
bank: b1conf.bank,
|
bank: b1conf.bank,
|
||||||
@ -68,10 +69,10 @@ export async function runBench1(configJson: any): Promise<void> {
|
|||||||
await wallet.runTaskLoop({
|
await wallet.runTaskLoop({
|
||||||
stopWhenDone: true,
|
stopWhenDone: true,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
wallet.stop();
|
wallet.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format of the configuration file passed to the benchmark
|
* Format of the configuration file passed to the benchmark
|
||||||
|
@ -43,6 +43,8 @@ import {
|
|||||||
Configuration,
|
Configuration,
|
||||||
decodeCrock,
|
decodeCrock,
|
||||||
rsaBlind,
|
rsaBlind,
|
||||||
|
LogLevel,
|
||||||
|
setGlobalLogLevelFromString,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
NodeHttpLib,
|
NodeHttpLib,
|
||||||
@ -161,6 +163,12 @@ export const walletCli = clk
|
|||||||
setDangerousTimetravel(x / 1000);
|
setDangerousTimetravel(x / 1000);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
.maybeOption("log", ["-L", "--log"], clk.STRING, {
|
||||||
|
help: "configure log level (NONE, ..., TRACE)",
|
||||||
|
onPresentHandler: (x) => {
|
||||||
|
setGlobalLogLevelFromString(x);
|
||||||
|
},
|
||||||
|
})
|
||||||
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
||||||
help:
|
help:
|
||||||
"Inhibit running certain operations, useful for debugging and testing.",
|
"Inhibit running certain operations, useful for debugging and testing.",
|
||||||
|
Loading…
Reference in New Issue
Block a user