mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 17:19:06 -05:00
6624584dd4
Original: 25b88bcf8c
53 lines
1 KiB
TypeScript
53 lines
1 KiB
TypeScript
import { assertEqual, test } from "https://deno.land/x/testing/testing.ts";
|
|
|
|
import * as logging from "index.ts";
|
|
|
|
// TODO: establish something more sophisticated
|
|
|
|
let testOutput = "";
|
|
|
|
class TestHandler extends logging.handlers.BaseHandler {
|
|
_log(level, ...args) {
|
|
testOutput += `${level} ${args[0]}\n`;
|
|
}
|
|
}
|
|
|
|
logging.setup({
|
|
handlers: {
|
|
debug: {
|
|
level: "DEBUG",
|
|
class: TestHandler
|
|
},
|
|
|
|
info: {
|
|
level: "INFO",
|
|
class: TestHandler
|
|
}
|
|
},
|
|
|
|
loggers: {
|
|
default: {
|
|
level: "DEBUG",
|
|
handlers: ["debug"]
|
|
},
|
|
|
|
info: {
|
|
level: "INFO",
|
|
handlers: ["info"]
|
|
}
|
|
}
|
|
});
|
|
|
|
const logger = logging.getLogger("default");
|
|
const unknownLogger = logging.getLogger("info");
|
|
|
|
test(function basicTest() {
|
|
logger.debug("I should be printed.");
|
|
unknownLogger.debug("I should not be printed.");
|
|
unknownLogger.info("And I should be printed as well.");
|
|
|
|
const expectedOutput =
|
|
"10 I should be printed.\n20 And I should be printed as well.\n";
|
|
|
|
assertEqual(testOutput, expectedOutput);
|
|
});
|