diff options
Diffstat (limited to 'packages/taler-util/src/logging.ts')
-rw-r--r-- | packages/taler-util/src/logging.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/packages/taler-util/src/logging.ts b/packages/taler-util/src/logging.ts index 9e6a265b8..17bb184f7 100644 --- a/packages/taler-util/src/logging.ts +++ b/packages/taler-util/src/logging.ts @@ -14,7 +14,6 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * Check if we are running under nodejs. */ @@ -38,6 +37,26 @@ const byTagLogLevel: Record<string, LogLevel> = {}; let nativeLogging: boolean = false; +// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString +Error.prototype.toString = function () { + if ( + this === null || + (typeof this !== "object" && typeof this !== "function") + ) { + throw new TypeError(); + } + let name = this.name; + name = name === undefined ? "Error" : `${name}`; + let msg = this.message; + msg = msg === undefined ? "" : `${msg}`; + + let cause = ""; + if ("cause" in this) { + cause = `\n Caused by: ${this.cause}`; + } + return `${name}: ${msg}${cause}`; +}; + export function getGlobalLogLevel(): string { return globalLogLevel; } |