@kingstack/logger
v0.1.0
Published
Structured, runtime-safe logging for KingStack applications
Maintainers
Readme
@kingstack/logger
Structured logging primitives for KingStack applications.
The package exposes separate entry points for shared types, Node.js/Pino, browser-safe logging, and tests:
import type { AppLogger } from "@kingstack/logger";
import { createNodeLogger } from "@kingstack/logger/node";
import { createBrowserLogger } from "@kingstack/logger/browser";
import { createCapturingLogger } from "@kingstack/logger/testing";Applications own service names, environment values, and extra redaction paths. The package owns the structured event contract, safe defaults, error serialization, and runtime adapters.
const runtime = createNodeLogger({
service: "worker",
environment: "production",
level: process.env.LOG_LEVEL,
format: process.env.LOG_FORMAT,
});
const logger = runtime.logger.child({ component: "InvoiceWorker" });
logger.info("invoice.processing_started", { invoiceId: "inv_123" });
logger.error("invoice.processing_failed", {
context: { invoiceId: "inv_123" },
error: new Error("Database unavailable"),
});Context values are deliberately limited to scalars and scalar arrays. Pass
errors through the tagged error field so Pino preserves their stack, and call
runtime.flush() during graceful shutdown.
Local pretty output uses compact timestamps and keeps routine records on one
line. The service and environment remain present in JSON output, but are hidden
from local presentation; component or Nest context is promoted beside the event
name. Errors remain multiline so their stack traces stay readable.
