@lowlighter/logger

3.1.1 • Public • Published

📰 Logger

JSR JSR Score NPM Coverage

📑 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 as info)
  • wdebug (use same channel as debug)
  • trace (use same channel as debug)
  • probe (use same channel as debug)

📜 License and credits

Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE

Readme

Keywords

Package Sidebar

Install

npm i @lowlighter/logger

Weekly Downloads

58

Version

3.1.1

License

MIT

Unpacked Size

146 kB

Total Files

10

Last publish

Collaborators

  • lowlighter