2019-01-02 09:12:48 -05:00
|
|
|
# Basic usage
|
2018-12-19 13:16:45 -05:00
|
|
|
|
2019-01-02 09:12:48 -05:00
|
|
|
```ts
|
2019-01-14 01:46:00 -05:00
|
|
|
import * as log from "https://deno.land/x/std/log/mod.ts";
|
2018-12-19 13:16:45 -05:00
|
|
|
|
2019-01-02 09:12:48 -05:00
|
|
|
// 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");
|
2018-12-19 13:16:45 -05:00
|
|
|
|
2019-01-02 09:12:48 -05:00
|
|
|
// configure as needed
|
|
|
|
await log.setup({
|
2019-01-01 22:46:17 -05:00
|
|
|
handlers: {
|
|
|
|
console: new log.handlers.ConsoleHandler("DEBUG"),
|
|
|
|
file: new log.handlers.FileHandler("WARNING", "./log.txt")
|
|
|
|
},
|
2018-12-24 10:28:01 -05:00
|
|
|
|
2019-01-01 22:46:17 -05:00
|
|
|
loggers: {
|
|
|
|
default: {
|
|
|
|
level: "DEBUG",
|
|
|
|
handlers: ["console", "file"]
|
2019-01-02 09:12:48 -05:00
|
|
|
}
|
2019-01-01 22:46:17 -05:00
|
|
|
}
|
2019-01-02 09:12:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// get configured logger
|
|
|
|
const logger = log.getLogger("default");
|
2019-01-01 22:46:17 -05:00
|
|
|
logger.debug("fizz"); // <- logs to `console`, because `file` handler requires 'WARNING' level
|
|
|
|
logger.warning("buzz"); // <- logs to both `console` and `file` handlers
|
2019-01-02 09:12:48 -05:00
|
|
|
|
|
|
|
// 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");
|
2019-01-01 22:46:17 -05:00
|
|
|
unknownLogger.info("foobar"); // no-op
|
|
|
|
```
|