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";
|
2019-01-12 16:50:04 -05:00
|
|
|
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: {
|
2019-01-21 10:35:07 -05:00
|
|
|
test: new TestHandler("DEBUG")
|
2019-01-19 13:46:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
loggers: {
|
|
|
|
test: {
|
|
|
|
level: "DEBUG",
|
2019-01-21 10:35:07 -05:00
|
|
|
handlers: ["test"]
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 13:46:46 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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", {
|
2019-01-21 10:35:07 -05:00
|
|
|
formatter: "test {levelName} {msg}"
|
|
|
|
})
|
2019-01-19 13:46:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
loggers: {
|
|
|
|
test: {
|
|
|
|
level: "DEBUG",
|
2019-01-21 10:35:07 -05:00
|
|
|
handlers: ["test"]
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 13:46:46 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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", {
|
2019-01-21 10:35:07 -05:00
|
|
|
formatter: logRecord =>
|
|
|
|
`fn formmatter ${logRecord.levelName} ${logRecord.msg}`
|
|
|
|
})
|
2019-01-19 13:46:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
loggers: {
|
|
|
|
test: {
|
|
|
|
level: "DEBUG",
|
2019-01-21 10:35:07 -05:00
|
|
|
handlers: ["test"]
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 13:46:46 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const logger = log.getLogger("test");
|
|
|
|
const handler = log.getHandler("test");
|
|
|
|
logger.error("Hello, world!");
|
|
|
|
assertEqual(handler.testOutput, "fn formmatter ERROR Hello, world!\n");
|
2019-01-21 10:35:07 -05:00
|
|
|
});
|