@orveth/logger
Structured logging contracts plus a reference ConsoleLogger that prints JSON lines to process.stdout. Swap the implementation in larger deployments while keeping the Logger interface stable across services.
LogLevel ordering
Levels follow ascending severity:
tracedebuginfowarnerrorfatal
The logger's configured minimum level filters outbound records. Messages below the threshold are discarded without side effects.
Logger interface
| Method | Signature highlights |
|---|---|
child(attributes) | Returns a new logger merging baseline attributes into each record. |
trace/debug/info/warn | (message, attributes?) |
error/fatal | (message, attributes?, error?) — optional Error capture for stack metadata. |
LogAttributes
Attributes are string-keyed maps whose values must be JSON-serializable primitives (string | number | boolean | null | undefined). Avoid embedding class instances or circular structures.
Example
import { ConsoleLogger } from "@orveth/logger";
export const log = new ConsoleLogger("info", {
service: "payments",
environment: process.env.NODE_ENV ?? "development",
});
export function logCheckout(durationMs: number) {
log.info("checkout.completed", { durationMs });
}
export function logFailure(err: Error) {
log.error("checkout.failed", { stage: "capture" }, err);
}