/** * Structured pino logger for AstraMemory Local. * * - Default level: info. Override with LOG_LEVEL env. * - JSON emit (service mode). pino-pretty auto-activated when LOG_PRETTY=1 and * pino-pretty is installed (optional dev dep). * - Secret scrubber applied via pino's built-in redact OR serializer fallback. * * Usage: * import { logger, childLogger } from '../log/logger.js'; * * // root logger — use in top-level server code * logger.info({ event: 'server.start', port: 7777 }, 'daemon started'); * * // child logger — bind fields for a request / job / stage * const log = childLogger({ request_id, session_id }); * log.info({ status: 200, duration_ms: 12 }, 'request complete'); */ import pino from 'pino'; /** * ISO-8601 UTC timestamp for RAW console.* lines emitted during daemon * runtime (server, pipeline handlers, job worker, sync shipper/puller). * pino `logger.*` calls already carry a `time` field — this helper is only * for the raw console.log/warn/error lines that bypass pino. Shared so every * runtime call site stamps identically instead of re-declaring a local dup. */ export declare const ts: () => string; /** * Service-mode log stream: an IN-PROCESS async SonicBoom destination plus a * tiny self-rotation sweep — deliberately NOT pino.transport('pino-roll'). * * pino-roll runs in a worker thread connected via thread-stream, whose write * path blocks the MAIN thread in Atomics.wait once the shared ring buffer * fills faster than the worker drains. On this box the worker demonstrably * stalls: a prior `_flushSync took too long (10s)` FATAL, and a live-captured * 2026-07-15 incident — event loop frozen 23+ minutes, 0 CPU, inspector * unattachable (blocked in native code, not JS), onset always right after a * log burst ~80s post-boot. A memory daemon's liveness must never depend on a * log-transport worker draining. SonicBoom with `sync: false` buffers * in-process and flushes on the event loop: a stalled disk grows the buffer, * it never blocks the loop. * * Rotation (pino-roll's job, now ours): every LOG_ROTATE_CHECK_MS, if the live * file exceeds LOG_ROTATE_MAX_BYTES, rename it aside with an epoch stamp, * `reopen()` the destination (SonicBoom re-creates the live file), and prune * rotated copies beyond LOG_ROTATE_KEEP. Every step is best-effort: on * Windows the rename fails with EPERM/EBUSY while another process holds the * file open (a `tail -f`, the dashboard reader) — we keep writing to the * unrotated file and retry next sweep. Rotation failure must never take the * daemon down or block a write. * * Exported for tests. */ export interface ServiceLogStreamOpts { /** Test seams — production callers use the defaults. */ maxBytes?: number; keep?: number; checkMs?: number; } export declare function createServiceLogStream(dir: string, opts?: ServiceLogStreamOpts): pino.DestinationStream & { flushSync: () => void; reopen: () => void; }; /** * Root logger instance. Long-lived singleton shared across the process. * Service mode uses the in-process SonicBoom stream (never a worker-thread * transport — see createServiceLogStream); LOG_PRETTY keeps the pino-pretty * transport (dev-only foreground, not a daemon-stability surface). */ export declare const logger: pino.Logger; /** * Create a child logger with bound fields. * All subsequent log calls on the child will include those fields. * * Common patterns: * childLogger({ request_id, method, path }) // HTTP layer * childLogger({ request_id, session_id, transcript_id }) // ingest route * childLogger({ job_id, job_kind, attempt }) // worker * childLogger({ job_id, stage }) // distill stage * childLogger({ provider, model }) // LLM/embed provider * * Sensitive fields in bindings are filtered by isSensitiveKey. */ export declare function childLogger(bindings: Record): pino.Logger; export type { pino };