aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-11-05 13:10:15 +0100
committerFlorian Dold <florian@dold.me>2021-11-05 13:10:15 +0100
commit6fc3aa0b31021f02d10e5a2efb12879aa64774fd (patch)
tree587b4add7ef5ec4f94499fe7622f1b65ea9f09f1 /packages/taler-util
parente627f65f3cf61428202e47e9e68a5baf4a9abfae (diff)
taler-wallet: implement log level, use new wallet for every benchmark iteration
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/src/logging.ts101
1 files changed, 95 insertions, 6 deletions
diff --git a/packages/taler-util/src/logging.ts b/packages/taler-util/src/logging.ts
index 0037d95a3..8b9de1ab0 100644
--- a/packages/taler-util/src/logging.ts
+++ b/packages/taler-util/src/logging.ts
@@ -23,6 +23,47 @@ const isNode =
typeof process.release !== "undefined" &&
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(
message: any,
tag: string,
@@ -57,21 +98,60 @@ export class Logger {
constructor(private tag: string) {}
shouldLogTrace() {
- // FIXME: Implement logic to check loglevel
- return true;
+ switch (globalLogLevel) {
+ case LogLevel.Trace:
+ return true;
+ case LogLevel.Message:
+ case LogLevel.Info:
+ case LogLevel.Warn:
+ case LogLevel.Error:
+ case LogLevel.None:
+ return false;
+ }
}
shouldLogInfo() {
- // FIXME: Implement logic to check loglevel
- return true;
+ switch (globalLogLevel) {
+ case LogLevel.Trace:
+ case LogLevel.Message:
+ case LogLevel.Info:
+ return true;
+ case LogLevel.Warn:
+ case LogLevel.Error:
+ case LogLevel.None:
+ return false;
+ }
}
shouldLogWarn() {
- // FIXME: Implement logic to check loglevel
- return true;
+ switch (globalLogLevel) {
+ case LogLevel.Trace:
+ case LogLevel.Message:
+ case LogLevel.Info:
+ case LogLevel.Warn:
+ 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 {
+ if (!this.shouldLogInfo()) {
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "INFO", args);
} else {
@@ -83,6 +163,9 @@ export class Logger {
}
warn(message: string, ...args: any[]): void {
+ if (!this.shouldLogWarn()) {
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "WARN", args);
} else {
@@ -94,6 +177,9 @@ export class Logger {
}
error(message: string, ...args: any[]): void {
+ if (!this.shouldLogError()) {
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "ERROR", args);
} else {
@@ -105,6 +191,9 @@ export class Logger {
}
trace(message: any, ...args: any[]): void {
+ if (!this.shouldLogTrace()) {
+ return;
+ }
if (isNode) {
writeNodeLog(message, this.tag, "TRACE", args);
} else {