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

base_handler_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/assert_equals.ts";import * as log from "./mod.ts";import { TestHandler } from "./_test_handler.ts";
Deno.test("BaseHandler handles default setup", function () { const cases = new Map<log.LogLevel, string[]>([ [ log.LogLevels.DEBUG, [ "DEBUG debug-test", "INFO info-test", "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], ], [ log.LogLevels.INFO, [ "INFO info-test", "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], ], [ log.LogLevels.WARN, ["WARN warn-test", "ERROR error-test", "CRITICAL critical-test"], ], [log.LogLevels.ERROR, ["ERROR error-test", "CRITICAL critical-test"]], [log.LogLevels.CRITICAL, ["CRITICAL critical-test"]], ]);
for (const [testCase, messages] of cases.entries()) { const testLevel = log.getLevelName(testCase); const handler = new TestHandler(testLevel);
for (const levelName of log.LogLevelNames) { const level = log.getLevelByName(levelName); handler.handle( new log.LogRecord({ msg: `${levelName.toLowerCase()}-test`, args: [], level: level, loggerName: "default", }), ); }
assertEquals(handler.level, testCase); assertEquals(handler.levelName, testLevel); assertEquals(handler.messages, messages); }});
Deno.test("BaseHandler handles formatter with empty msg", function () { const handler = new TestHandler("DEBUG", { formatter: ({ levelName, msg }) => `test ${levelName} ${msg}`, });
handler.handle( new log.LogRecord({ msg: "", args: [], level: log.LogLevels.DEBUG, loggerName: "default", }), );
assertEquals(handler.messages, ["test DEBUG "]);});
Deno.test("BaseHandler handles formatter", function () { const handler = new TestHandler("DEBUG", { formatter: (logRecord): string => `fn formatter ${logRecord.levelName} ${logRecord.msg}`, });
handler.handle( new log.LogRecord({ msg: "Hello, world!", args: [], level: log.LogLevels.ERROR, loggerName: "default", }), );
assertEquals(handler.messages, ["fn formatter ERROR Hello, world!"]);});
std

Version Info

Tagged at
6 months ago