A tiny template string logger with structured output
npm install hatchletA tiny template string logger with structured output for modern JavaScript.
- Template literal syntax — natural logging with logger.info\Hello ${{name}}\`${{name}}
- Structured output — extracts values into a queryable object
- Named parameters — use 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
`bash`
npm install hatchlet
`ts
import { Logger } from "hatchlet";
const logger = new Logger();
// Named parameters - extracted into values object
const name = "Thomas";
logger.infoHello ${{name}};
// → { message: "Hello Thomas", template: "Hello *", values: { name: "Thomas" } }
// Unnamed parameters - collected into params array
const age = 30;
logger.infoUser 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.infoShopping: ${{items}};`
// → { message: "Shopping: apple, banana", template: "Shopping: *", values: { items: ["apple", "banana"] } }
`tsHello ${{name}}
// Production (default) - full structured output for logging tools
const logger = new Logger();
logger.info;
// → { message: "Hello Thomas", template: "Hello *", values: { name: "Thomas" } }
// Dev mode - clean output for local development
const logger = new Logger({ dev: true });
logger.infoHello ${{name}};`
// → "Hello Thomas"
`ts
const logger = new Logger({ level: "warn" });
logger.infoThis is filtered out;This is logged
logger.warn;This is logged
logger.error;``
MIT