deno.land / std@0.224.0 / log / get_logger_test.ts

get_logger_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assert, assertEquals, assertThrows } from "../assert/mod.ts";import * as log from "./mod.ts";import { TestHandler } from "./_test_handler.ts";
let logger: log.Logger | null = null;try { // Need to initialize it here // otherwise it will be already initialized on Deno.test logger = log.getLogger();} catch { // Pass}
Deno.test("getLogger() initializes logger", function () { assert(logger instanceof log.Logger);});
Deno.test("getLogger()", async function () { const handler = new TestHandler("DEBUG");
await log.setup({ handlers: { default: handler, }, loggers: { default: { level: "DEBUG", handlers: ["default"], }, }, });
const logger = log.getLogger();
assertEquals(logger.levelName, "DEBUG"); assertEquals(logger.handlers, [handler]);});
Deno.test("getLogger() handles name", async function () { const fooHandler = new TestHandler("DEBUG");
await log.setup({ handlers: { foo: fooHandler, }, loggers: { bar: { level: "INFO", handlers: ["foo"], }, }, });
const logger = log.getLogger("bar");
assertEquals(logger.levelName, "INFO"); assertEquals(logger.handlers, [fooHandler]);});
Deno.test("getLogger() habndles unknown", async function () { await log.setup({ handlers: {}, loggers: {}, });
const logger = log.getLogger("nonexistent");
assertEquals(logger.levelName, "NOTSET"); assertEquals(logger.handlers, []);});
Deno.test("getLogger() handles invalid level", function () { assertThrows(() => log.getLevelByName("FAKE_LOG_LEVEL" as log.LevelName)); assertThrows(() => log.getLevelName(5000 as log.LogLevel));});
std

Version Info

Tagged at
6 months ago