From 4659271518b71b90eb82b05b8aeb655c82a8a93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 2 Jan 2019 15:12:48 +0100 Subject: Improve logging module (denoland/deno_std#51) Original: https://github.com/denoland/deno_std/commit/439885c756615f4da4953460c47d58cc9cc5bd2b --- logging/README.md | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'logging/README.md') diff --git a/logging/README.md b/logging/README.md index 26047d9a2..4d7e95474 100644 --- a/logging/README.md +++ b/logging/README.md @@ -1,15 +1,38 @@ -# Logging module for Deno +# Basic usage -Very much work in progress. Contributions welcome. +```ts +import * as log from "https://deno.land/x/std/logging/index.ts"; -This library is heavily inspired by Python's -[logging](https://docs.python.org/3/library/logging.html#logging.Logger.log) -module, altough it's not planned to be a direct port. Having separate loggers, -handlers, formatters and filters gives developer very granular control over -logging which is most desirable for server side software. +// simple console logger +log.debug("Hello world"); +log.info("Hello world"); +log.warning("Hello world"); +log.error("Hello world"); +log.critical("500 Internal server error"); -Todo: +// configure as needed +await log.setup({ + handlers: { + console: new log.handlers.ConsoleHandler("DEBUG"), + file: new log.handlers.FileHandler("WARNING", "./log.txt"), + }, -- [ ] implement formatters -- [ ] implement `FileHandler` -- [ ] tests + loggers: { + default: { + level: "DEBUG", + handlers: ["console", "file"], + } + } +}); + +// get configured logger +const logger = log.getLogger("default"); +logger.debug("fizz") // <- logs to `console`, because `file` handler requires 'WARNING' level +logger.warning("buzz") // <- logs to both `console` and `file` handlers + +// if you try to use a logger that hasn't been configured +// you're good to go, it gets created automatically with level set to 0 +// so no message is logged +const unknownLogger = log.getLogger("mystery"); +unknownLogger.info("foobar") // no-op +``` \ No newline at end of file -- cgit v1.2.3