diff options
author | Florian Dold <florian@dold.me> | 2021-12-01 12:22:58 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-12-01 12:22:58 +0100 |
commit | 718595a57264c1bea55db9c00dcd2e0182afa0a3 (patch) | |
tree | d4a71da0c958349d08dd88520ba8f621200305a3 /packages/taler-util | |
parent | 54d4a1efe0a55a80ed594f14698da16dfded8c47 (diff) |
write logs atomically
Diffstat (limited to 'packages/taler-util')
-rw-r--r-- | packages/taler-util/src/logging.ts | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/packages/taler-util/src/logging.ts b/packages/taler-util/src/logging.ts index 117664d8c..ca7210eaa 100644 --- a/packages/taler-util/src/logging.ts +++ b/packages/taler-util/src/logging.ts @@ -71,22 +71,23 @@ function writeNodeLog( args: any[], ): void { try { - process.stderr.write(`${new Date().toISOString()} ${tag} ${level} `); - process.stderr.write(`${message}`); + let msg = `${new Date().toISOString()} ${tag} ${level} ${message}`; if (args.length != 0) { - process.stderr.write(" "); - process.stderr.write(JSON.stringify(args, undefined, 2)); + msg += ` ${JSON.stringify(args, undefined, 2)}\n`; + } else { + msg += `\n`; } - process.stderr.write("\n"); + process.stderr.write(msg); } 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 `); + let msg = `${new Date().toISOString()} (logger) FATAL `; if (e instanceof Error) { - process.stderr.write("failed to write log: "); - process.stderr.write(e.message); + msg += `failed to write log: ${e.message}\n`; + } else { + msg += "failed to write log\n"; } - process.stderr.write("\n"); + process.stderr.write(msg); } } |