Skip to main content

Built and signed on GitHub Actions

A utility to enhance the default console logging in JavaScript/TypeScript. It allows you to set logging levels and filter logs based on a query.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a month ago (0.0.9)

Garn Logger

Garn Logger is a utility to enhance the default console logging in JavaScript/TypeScript. It allows you to set logging levels and filter logs based on a query.

Installation

deno add jsr:@garn/logger

or

npx jsr add @garn/logger

Usage

Importing

import { better } from "@garn/logger";

Setting Log Level

You can set the log level to control which logs are displayed. The available levels are error, warn, info, and debug.

better(console).level("warn");

console.error("This is an error"); // Will log
console.warn("This is a warning"); // Will log
console.info("This is an info"); // Will not log
console.debug("This is a debug"); // Will not log

Setting Log Filter

You can filter logs based on a string or regular expression.

better(console).filter("test");

console.error("this is a test"); // Will log
console.warn("another test"); // Will log
console.info("not a match"); // Will not log
console.debug("test again"); // Will log

Using a regular expression:

better(console).filter(/test/i);

console.error("this is a test"); // Will log
console.warn("another test"); // Will log
console.info("not a match"); // Will not log
console.debug("test again"); // Will log

Using mutliple filters acts as an OR operation:

better(console).filter("test","another");

console.error("this is a test"); // Will log
console.warn("another"); // Will log
console.info("not a match"); // Will not log

Or use addFilter to add multiple filters:

better(console).addFilter("test").addFilter("another");
console.error("this is a test"); // Will log
console.warn("another"); // Will log
console.info("not a match"); // Will not log

Reset filter with .resetFilter():

better(console).filter("XXX");
better(console).resetFilter();
console.error("this is a test"); // Will log

Use console.only

You can use console.only to log only this log and filter every log ahead.


better(console)

console.only("logs this"); // Will log
console.error("this is filtered out"); // Will not log

It's a shortcut for:

better(console).filter("logs this");
console.debug("logs this");
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@garn/logger

Import symbol

import * as logger from "@garn/logger";

---- OR ----

Import directly with a jsr specifier

import * as logger from "jsr:@garn/logger";

Add Package

npx jsr add @garn/logger

Import symbol

import * as logger from "@garn/logger";

Add Package

yarn dlx jsr add @garn/logger

Import symbol

import * as logger from "@garn/logger";

Add Package

pnpm dlx jsr add @garn/logger

Import symbol

import * as logger from "@garn/logger";

Add Package

bunx jsr add @garn/logger

Import symbol

import * as logger from "@garn/logger";