diff options
author | Water Zheng <1499383852@qq.com> | 2020-06-30 17:29:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 11:29:26 +0200 |
commit | 6844c3ac0ea4afcb799bba4945b400a011eb5d84 (patch) | |
tree | c417ac1e407fdfea89b0ecac3e8e3da423fc0267 | |
parent | 971dfcf9bbf469b4d21f4a614d3f825528d748f5 (diff) |
fix(std/log): print "{msg}" when log an empty line (#6381)
-rw-r--r-- | std/log/handlers.ts | 2 | ||||
-rw-r--r-- | std/log/handlers_test.ts | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/std/log/handlers.ts b/std/log/handlers.ts index 1b152c273..0efa7cc26 100644 --- a/std/log/handlers.ts +++ b/std/log/handlers.ts @@ -41,7 +41,7 @@ export class BaseHandler { const value = logRecord[p1 as keyof LogRecord]; // do not interpolate missing values - if (!value) { + if (value == null) { return match; } diff --git a/std/log/handlers_test.ts b/std/log/handlers_test.ts index 7ff4c4c90..ef4b69000 100644 --- a/std/log/handlers_test.ts +++ b/std/log/handlers_test.ts @@ -94,6 +94,23 @@ Deno.test("testFormatterAsString", function (): void { assertEquals(handler.messages, ["test DEBUG Hello, world!"]); }); +Deno.test("testFormatterWithEmptyMsg", function () { + const handler = new TestHandler("DEBUG", { + formatter: "test {levelName} {msg}", + }); + + handler.handle( + new LogRecord({ + msg: "", + args: [], + level: LogLevels.DEBUG, + loggerName: "default", + }) + ); + + assertEquals(handler.messages, ["test DEBUG "]); +}); + Deno.test("testFormatterAsFunction", function (): void { const handler = new TestHandler("DEBUG", { formatter: (logRecord): string => |