diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2018-12-19 19:16:45 +0100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-19 13:16:45 -0500 |
| commit | 6624584dd476f0f261376e7c625a318049d2bd83 (patch) | |
| tree | ea59dade4e002f69e28df6ec696a86a37fc95821 /logging/test.ts | |
| parent | 700b4ce0d99dca02fe192c8722ab1bb7a33dc709 (diff) | |
Add logging module (denoland/deno_std#33)
Original: https://github.com/denoland/deno_std/commit/25b88bcf8c260865d2b6b68f539c4772bac095ee
Diffstat (limited to 'logging/test.ts')
| -rw-r--r-- | logging/test.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/logging/test.ts b/logging/test.ts new file mode 100644 index 000000000..365064cbf --- /dev/null +++ b/logging/test.ts @@ -0,0 +1,53 @@ +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); +}); |
