1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-03 17:08:35 -05:00
denoland-deno/log/test.ts

94 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-01-02 09:12:48 -05:00
import { remove, open, readAll } from "deno";
2019-01-01 22:46:17 -05:00
import { assertEqual, test } from "../testing/mod.ts";
import * as log from "./mod.ts";
2019-01-02 09:12:48 -05:00
import { FileHandler } from "./handlers.ts";
2018-12-19 13:16:45 -05:00
2019-01-19 13:46:46 -05:00
// constructor(levelName: string, options: HandlerOptions = {}) {
// this.level = getLevelByName(levelName);
// this.levelName = levelName;
// this.formatter = options.formatter || DEFAULT_FORMATTER;
// }
2018-12-19 13:16:45 -05:00
2019-01-02 09:12:48 -05:00
class TestHandler extends log.handlers.BaseHandler {
2019-01-19 13:46:46 -05:00
testOutput = "";
2019-01-02 09:12:48 -05:00
log(msg: string) {
2019-01-19 13:46:46 -05:00
this.testOutput += `${msg}\n`;
2018-12-19 13:16:45 -05:00
}
}
2019-01-02 09:12:48 -05:00
test(function testDefaultlogMethods() {
log.debug("Foobar");
log.info("Foobar");
log.warning("Foobar");
log.error("Foobar");
log.critical("Foobar");
2018-12-19 13:16:45 -05:00
2019-01-06 14:19:15 -05:00
const logger = log.getLogger("");
2019-01-02 09:12:48 -05:00
console.log(logger);
});
2019-01-19 13:46:46 -05:00
test(async function testDefaultFormatter() {
await log.setup({
handlers: {
test: new TestHandler("DEBUG"),
},
loggers: {
test: {
level: "DEBUG",
handlers: ["test"],
},
},
});
const logger = log.getLogger("test");
const handler = log.getHandler("test");
logger.debug("Hello, world!");
assertEqual(handler.testOutput, "DEBUG Hello, world!\n");
});
test(async function testFormatterAsString() {
await log.setup({
handlers: {
test: new TestHandler("DEBUG", {
formatter: "test {levelName} {msg}",
}),
},
loggers: {
test: {
level: "DEBUG",
handlers: ["test"],
},
},
});
const logger = log.getLogger("test");
const handler = log.getHandler("test");
logger.debug("Hello, world!");
assertEqual(handler.testOutput, "test DEBUG Hello, world!\n");
});
test(async function testFormatterAsFunction() {
await log.setup({
handlers: {
test: new TestHandler("DEBUG", {
formatter: logRecord => `fn formmatter ${logRecord.levelName} ${logRecord.msg}`,
}),
},
loggers: {
test: {
level: "DEBUG",
handlers: ["test"],
},
},
});
const logger = log.getLogger("test");
const handler = log.getHandler("test");
logger.error("Hello, world!");
assertEqual(handler.testOutput, "fn formmatter ERROR Hello, world!\n");
});