A tiny template string logger with structured output for modern JavaScript.
- 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
npm install hatchlet
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 (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"
const logger = new Logger({ level: "warn" }); logger.info`This is filtered out`; logger.warn`This is logged`; logger.error`This is logged`;
MIT