diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-09-01 15:52:13 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-09-01 15:52:13 +0530 |
commit | 5e7149f79eeb9988a7da45ecc8573c65e9680082 (patch) | |
tree | 892889ca8231d1a238de8264e0dbf96f349ff82f /packages/taler-wallet-core/src/util/logging.ts | |
parent | 5c0ee81e26698293b1d9fc028a9080afb1779b60 (diff) | |
download | wallet-core-5e7149f79eeb9988a7da45ecc8573c65e9680082.tar.xz |
fix exception thrown during logging, include stack trace
Diffstat (limited to 'packages/taler-wallet-core/src/util/logging.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/logging.ts | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/util/logging.ts b/packages/taler-wallet-core/src/util/logging.ts index e4f3be2ff..230cb7053 100644 --- a/packages/taler-wallet-core/src/util/logging.ts +++ b/packages/taler-wallet-core/src/util/logging.ts @@ -22,18 +22,29 @@ const isNode = typeof process !== "undefined" && process.release.name === "node"; function writeNodeLog( - message: string, + message: any, tag: string, level: string, args: any[], ): void { - process.stderr.write(`${new Date().toISOString()} ${tag} ${level} `); - process.stderr.write(message); - if (args.length != 0) { - process.stderr.write(" "); - process.stderr.write(JSON.stringify(args, undefined, 2)); + try { + process.stderr.write(`${new Date().toISOString()} ${tag} ${level} `); + process.stderr.write(`${message}`); + if (args.length != 0) { + process.stderr.write(" "); + process.stderr.write(JSON.stringify(args, undefined, 2)); + } + process.stderr.write("\n"); + } catch (e) { + // This can happen when we're trying to log something that doesn't want to be + // converted to a string. + process.stderr.write(`${new Date().toISOString()} (logger) FATAL `); + if (e instanceof Error) { + process.stderr.write("failed to write log: "); + process.stderr.write(e.message); + } + process.stderr.write("\n"); } - process.stderr.write("\n"); } /** |