1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -05:00
denoland-deno/log
2019-01-21 09:35:07 -06:00
..
handlers.ts fix format (denoland/deno_std#140) 2019-01-21 09:35:07 -06:00
levels.ts Reorgnanize repos, examples and tests (denoland/deno_std#105) 2019-01-12 16:50:04 -05:00
logger.ts Reorgnanize repos, examples and tests (denoland/deno_std#105) 2019-01-12 16:50:04 -05:00
mod.ts Implement formatters for log (denoland/deno_std#127) 2019-01-19 13:46:46 -05:00
README.md Fix wrong links (denoland/deno_std#106) 2019-01-14 01:45:59 -05:00
test.ts fix format (denoland/deno_std#140) 2019-01-21 09:35:07 -06:00

Basic usage

import * as log from "https://deno.land/x/std/log/mod.ts";

// 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");

// configure as needed
await log.setup({
  handlers: {
    console: new log.handlers.ConsoleHandler("DEBUG"),
    file: new log.handlers.FileHandler("WARNING", "./log.txt")
  },

  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