Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

πŸͺ“ Hatchlet

A tiny template string logger with structured output for modern JavaScript.

Features

  • Template literal syntax β€” natural logging with logger.info\Hello ${{name}}``
  • Structured output β€” extracts values into a queryable object
  • Named parameters β€” use ${{name}} to label values in output
  • Dev mode β€” full structured output in production, clean messages in development
  • Log levels β€” debug, log, info, warn, error with filtering support

Install

npm install hatchlet

Usage

import { Logger } from "hatchlet";
const logger = new Logger();
// Named parameters - extracted into values object
const name = "Thomas";
logger.info`Hello ${{name}}`;
// β†’ { message: "Hello Thomas", template: "Hello *", values: { name: "Thomas" }}
// Unnamed parameters - collected into params array
const age = 30;
logger.info`User is ${age} years old`;
// β†’ { message: "User is 30 years old", template: "User is * years old", values: { params: [30] }}
// Mixed named and unnamed
const city = "London";
logger.info`${{name}} is ${age}, lives in ${{city}}`;
// β†’ { message: "Thomas is 30, lives in London", template: "* is *, lives in *", values: { name: "Thomas", params: [30], city: "London" }}
// Arrays and objects
const items = ["apple", "banana"];
logger.info`Shopping: ${{items}}`;
// β†’ { message: "Shopping: apple, banana", template: "Shopping: *", values: { items: ["apple", "banana"] }}

Production vs Dev Mode

// Production (default) - full structured output for logging tools
const logger = new Logger();
logger.info`Hello ${{name}}`;
// β†’ { message: "Hello Thomas", template: "Hello *", values: { name: "Thomas" }}
// Dev mode - clean output for local development
const logger = new Logger({ dev: true });
logger.info`Hello ${{name}}`;
// β†’ "Hello Thomas"

Log Levels

const logger = new Logger({ level: "warn" });
logger.info`This is filtered out`;
logger.warn`This is logged`;
logger.error`This is logged`;

License

MIT

About

No description, website, or topics provided.

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /