1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

feat(std/log): Log error stack (#8401)

This commit is contained in:
Mark Tiedemann 2020-11-19 12:58:53 +01:00 committed by GitHub
parent a1852d38cf
commit 6bb5fedc69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -131,6 +131,8 @@ export class Logger {
typeof data === "symbol"
) {
return String(data);
} else if (data instanceof Error) {
return data.stack!;
} else if (typeof data === "object") {
return JSON.stringify(data);
}

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../testing/asserts.ts";
import { assert, assertEquals, assertMatch } from "../testing/asserts.ts";
import { Logger, LogRecord } from "./logger.ts";
import { LevelName, LogLevels } from "./levels.ts";
import { BaseHandler } from "./handlers.ts";
@ -243,5 +243,13 @@ Deno.test(
});
assertEquals(handler.messages[16], 'ERROR {"payload":"data","other":123}');
assertEquals(handler.messages[17], 'ERROR {"payload":"data","other":123}');
// error
const error = new RangeError("Uh-oh!");
const data19: RangeError = logger.error(error);
assertEquals(data19, error);
const messages19 = handler.messages[18].split("\n");
assertEquals(messages19[0], `ERROR ${error.name}: ${error.message}`);
assertMatch(messages19[1], /^\s+at file:.*\d+:\d+$/);
},
);