Add pino-based logger module for production observability: - JSON output to stdout for log aggregators (Loki, ELK) - Configurable via LOG_LEVEL environment variable (defaults to "info") - Log levels: error, warn, info, debug - Error objects serialized with type, message, and stack trace - Child logger support for bound context - ISO 8601 timestamps in all log entries Test coverage: 16 tests covering JSON format, log levels, error serialization, and child loggers. Total tests now: 553 passing across 31 test files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
27 lines
783 B
TypeScript
27 lines
783 B
TypeScript
// ABOUTME: Structured logging module using pino for JSON output to stdout.
|
|
// ABOUTME: Configurable via LOG_LEVEL env var, outputs parseable logs for aggregators.
|
|
|
|
import pino from "pino";
|
|
|
|
/**
|
|
* PhaseFlow logger configured per observability spec.
|
|
*
|
|
* Log levels: error, warn, info, debug
|
|
* Output: JSON to stdout
|
|
* Configuration: LOG_LEVEL env var (defaults to "info")
|
|
*
|
|
* Usage:
|
|
* logger.info({ userId: "123" }, "User logged in");
|
|
* logger.error({ err: error, userId: "123" }, "Operation failed");
|
|
*/
|
|
export const logger = pino({
|
|
level: process.env.LOG_LEVEL || "info",
|
|
formatters: {
|
|
level: (label) => ({ level: label }),
|
|
},
|
|
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
|
|
messageKey: "message",
|
|
});
|
|
|
|
export type Logger = typeof logger;
|