summaryrefslogtreecommitdiff
path: root/logging/README.md
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-01-02 15:12:48 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-01-02 09:12:48 -0500
commit4659271518b71b90eb82b05b8aeb655c82a8a93e (patch)
tree629d81dad90ec6106f13901e25f2f5142e195026 /logging/README.md
parentbc4635a5938513886c7c6d1801e6ebcddf62b699 (diff)
Improve logging module (denoland/deno_std#51)
Original: https://github.com/denoland/deno_std/commit/439885c756615f4da4953460c47d58cc9cc5bd2b
Diffstat (limited to 'logging/README.md')
-rw-r--r--logging/README.md45
1 files changed, 34 insertions, 11 deletions
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