0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(std/log): print "{msg}" when log an empty line (#6381)

This commit is contained in:
Water Zheng 2020-06-30 17:29:26 +08:00 committed by GitHub
parent 971dfcf9bb
commit 6844c3ac0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -41,7 +41,7 @@ export class BaseHandler {
const value = logRecord[p1 as keyof LogRecord]; const value = logRecord[p1 as keyof LogRecord];
// do not interpolate missing values // do not interpolate missing values
if (!value) { if (value == null) {
return match; return match;
} }

View file

@ -94,6 +94,23 @@ Deno.test("testFormatterAsString", function (): void {
assertEquals(handler.messages, ["test DEBUG Hello, world!"]); 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 { Deno.test("testFormatterAsFunction", function (): void {
const handler = new TestHandler("DEBUG", { const handler = new TestHandler("DEBUG", {
formatter: (logRecord): string => formatter: (logRecord): string =>