Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
lowlighter/libs📰 Simple logger
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
100%
Published
3 weeks ago (3.1.4)
📰 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
Built and signed on
GitHub Actions
Add Package
deno add jsr:@libs/logger
Import symbol
import * as logger from "@libs/logger";
Import directly with a jsr specifier
import * as logger from "jsr:@libs/logger";
Add Package
pnpm i jsr:@libs/logger
pnpm dlx jsr add @libs/logger
Import symbol
import * as logger from "@libs/logger";
Add Package
yarn add jsr:@libs/logger
yarn dlx jsr add @libs/logger
Import symbol
import * as logger from "@libs/logger";
Add Package
vlt install jsr:@libs/logger
Import symbol
import * as logger from "@libs/logger";
Add Package
npx jsr add @libs/logger
Import symbol
import * as logger from "@libs/logger";
Add Package
bunx jsr add @libs/logger
Import symbol
import * as logger from "@libs/logger";