summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--std/log/logger.ts2
-rw-r--r--std/log/logger_test.ts10
2 files changed, 11 insertions, 1 deletions
diff --git a/std/log/logger.ts b/std/log/logger.ts
index c30517c59..7ef23977a 100644
--- a/std/log/logger.ts
+++ b/std/log/logger.ts
@@ -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);
}
diff --git a/std/log/logger_test.ts b/std/log/logger_test.ts
index 4ab50809f..b01d1dc5d 100644
--- a/std/log/logger_test.ts
+++ b/std/log/logger_test.ts
@@ -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+$/);
},
);