import { Logger } from "./mod.ts"
// Configure logger
const tags = { foo: "bar" }
const log = new Logger({ level: "trace", tags, date: true, time: true, delta: true, caller: true })
// Print logs
log
.error("🍱 bento")
.warn("🍜 ramen")
.ok("🍚 gohan")
.info("🍣 sushi")
.log("🍥 narutomaki")
.debug("🍡 dango")
.wdebug("🍵 matcha")
.trace("🍙 onigiri")
.probe("🥟 gyoza")
//
log
.censor({ keys: ["password", /^api_/], values: [/offensive-word/] })
.log({ user: "foo", password: "bar", api_key: "foobar", message: "offensive-word content" })
- Has no external dependencies.
- Support for colored output.
- Support for log levels.
- Support for tags.
- Support for timestamps (date, time, delta).
- Support for displaying caller information (file, function name, line and column).
- Support for multiple log formatters (text, JSON).
- Support censorship of sensitive data.
Version 3.x.x
and onwards require Deno 2.x.x
or later.
All fields from options
are now located at the root of the constructor argument.
- new Logger({ options: { date: true, time: true } })
+ new Logger({ date: true, time: true })
Instead of properties, level()
and options()
are now chainable setters when called with arguments and getters when called without.
- log.level = Logger.level.log
- log.options = {...}
- console.log(log.level, log.options)
+ log.level(Logger.level.log).options({...})
+ console.log(log.level(), log.options())
To offer more flexibility, caller.fileformat
is now a [RegExp, string]
tuple.
- const options = { caller: { fileformat: /(?<file>.*)/ } }
+ const options = { caller: { fileformat: [/(?<file>.*)/, "$<file>"] } }
The following new stream channels are available:
-
ok
(use same channel asinfo
) -
wdebug
(use same channel asdebug
) -
trace
(use same channel asdebug
) -
probe
(use same channel asdebug
)
Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE