summaryrefslogtreecommitdiff
path: root/std/log/mod_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/log/mod_test.ts')
-rw-r--r--std/log/mod_test.ts52
1 files changed, 51 insertions, 1 deletions
diff --git a/std/log/mod_test.ts b/std/log/mod_test.ts
index 98ac093c8..9de5d76af 100644
--- a/std/log/mod_test.ts
+++ b/std/log/mod_test.ts
@@ -1,7 +1,24 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../testing/asserts.ts";
-import { getLogger, debug, info, warning, error, critical } from "./mod.ts";
+import {
+ getLogger,
+ debug,
+ info,
+ warning,
+ error,
+ critical,
+ setup,
+} from "./mod.ts";
import { Logger } from "./logger.ts";
+import { BaseHandler } from "./handlers.ts";
+
+class TestHandler extends BaseHandler {
+ public messages: string[] = [];
+
+ public log(str: string): void {
+ this.messages.push(str);
+ }
+}
let logger: Logger | null = null;
try {
@@ -39,3 +56,36 @@ Deno.test("default loggers work as expected", function (): void {
assertEquals(criticalData, "foo");
assertEquals(criticalResolver, "bar");
});
+
+Deno.test({
+ name: "Logging config works as expected with logger names",
+ async fn() {
+ const consoleHandler = new TestHandler("DEBUG");
+ const anotherConsoleHandler = new TestHandler("DEBUG", {
+ formatter: "[{loggerName}] {levelName} {msg}",
+ });
+ await setup({
+ handlers: {
+ console: consoleHandler,
+ anotherConsole: anotherConsoleHandler,
+ },
+
+ loggers: {
+ // configure default logger available via short-hand methods above
+ default: {
+ level: "DEBUG",
+ handlers: ["console"],
+ },
+
+ tasks: {
+ level: "ERROR",
+ handlers: ["anotherConsole"],
+ },
+ },
+ });
+ getLogger().debug("hello");
+ getLogger("tasks").error("world");
+ assertEquals(consoleHandler.messages[0], "DEBUG hello");
+ assertEquals(anotherConsoleHandler.messages[0], "[tasks] ERROR world");
+ },
+});