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:
parent
a1852d38cf
commit
6bb5fedc69
2 changed files with 11 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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+$/);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue