hatchlet
v0.0.4
Published
A tiny template string logger with structured output
Readme
🪓 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 hatchletUsage
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
