@lowlighter/logger
v3.1.1
Published
Simple logger
Downloads
28
Readme
📰 Logger
📑 Examples
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" })
✨ Features
- 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.
🕊️ Migrating from 2.x.x
to 3.x.x
Version 3.x.x
and onwards require Deno 2.x.x
or later.
🕊️ Migrating from 1.x.x
to 2.x.x
Flattened constructor options
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 })
Chainable setters for level
and options
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())
Flexible file formatting
To offer more flexibility, caller.fileformat
is now a [RegExp, string]
tuple.
- const options = { caller: { fileformat: /(?<file>.*)/ } }
+ const options = { caller: { fileformat: [/(?<file>.*)/, "$<file>"] } }
Additional stream channels
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
)
📜 License and credits
Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE