Skip to content

Tiny logging utility for all JavaScript runtimes.

License

Notifications You must be signed in to change notification settings

grammyjs/wiretap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

wiretap

Extremely tiny debug logging utility for all JavaScript runtimes.

Inspired by debug, but very small and portable.

example

Installation

# npm
npm install w

# yarn
yarn add w

# pnpm
pnpm add w

# bun
bun add w

# deno
deno add jsr:@mkr/wiretap

Quick Start

import { w } from "w";
const log = w("app:main");
log("Creating new user", { email: req.body.email });
const log = w("app:auth");
log("User authentication failed", { email: req.body.email });

If you're a library author, we recommend using your library's name as part of your namespace.

Usage

All debug logs are disabled by default, and can be enabled by setting the DEBUG environment variable.

> DEBUG=app:main node index.js
app:main Creating new user { email: '[email protected]' }

To enable all logs at any level, use *. Naturally DEBUG=* will enable all logs at all levels.

> DEBUG=app:* node index.js
app:main Creating new user { email: '[email protected]' }
app:auth User authentication failed { email: '[email protected]' }

Multiple namespaces can be specified by separating them with commas:

> DEBUG=app:main,app:auth node index.js
app:main Creating new user { email: '[email protected]' }
app:auth User authentication failed { email: '[email protected]' }

To disable a specific level, prefix the spec with a -:

# all "app" enabled except "app:auth"
> DEBUG=app:*,-app:auth node index.js
app:main Creating new user { email: '[email protected]' }

🔔 The most specific rule always wins.

Example: app:*,-app:auth,app:auth:warning

Explanation:

  • all namespaces under app are enabled
  • but app:auth is disabled
  • but app:auth:warning is enabled
# notice that we didn't get app:auth, but we did get app:auth:warning
> DEBUG=app:*,-app:auth,app:auth:warning node index.js
app:main Creating new user { email: '[email protected]' }
app:auth:warning User authentication failed { email: '[email protected]' }

Programmatic Control

An individual logger instance can also be enabled or disabled programmatically:

const log = w("app:feature");

// Enable this logger regardless of DEBUG environment
log.enabled = true;

// Disable this logger regardless of DEBUG environment
log.enabled = false;

By default, wiretap will log to stderr. You can customise the logger function used:

const log = w("app:custom");
// Replace the default logger with your own
log.logger = console.log.bind(console); // or
log.logger = (...args) => console.log("[CUSTOM]", ...args);

Supported Environments:

  • Node.js
  • Bun
  • Deno
  • Cloudflare Workers
  • Browsers (by default, you may need to turn on the "debug", "verbose", or similar setting in the console to see the logs in your browser to see debug logs)

About

Tiny logging utility for all JavaScript runtimes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%