diff options
| author | Chris Knight <cknight1234@gmail.com> | 2020-06-18 11:50:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 12:50:18 +0200 |
| commit | 940f8e8433ae5ec74b2642438849089a0433e512 (patch) | |
| tree | 7611524db839edc816c5c77fdfeb711cfce6a757 /std/log/mod_test.ts | |
| parent | 78a311aa5f6c56a750aaf3a7d3e8f911acf348d1 (diff) | |
feat(std/log): expose logger name to LogRecord (#6316)
Diffstat (limited to 'std/log/mod_test.ts')
| -rw-r--r-- | std/log/mod_test.ts | 52 |
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"); + }, +}); |
