/** * Structured logging, to stderr, one JSON object per line. * * Two constraints shape this file, and both are absolute. * * **stdout is the protocol channel.** index.ts already says so where it logs * the startup banner. A stray console.log anywhere in a request path writes * non-JSON-RPC bytes into the stream a client is parsing, and the client's * failure mode is "the server is broken" with nothing pointing at the cause. * Everything here writes to stderr and nothing in this module can be configured * to do otherwise. * * **Code mode needs an audit record.** A classic tool call is one request and * the client's own transcript is the record of it. A dispatched call can issue * sixty, and a script can call operations nobody wrote down, so "what did this * server actually do with my credential" stops being answerable from the * transcript alone. One `info` line per invocation — operations, counts, * duration, and a hash of the script — is what makes it answerable again. * * What is deliberately NOT logged at `info`: script source, request bodies and * response bodies. Alert messages, descriptions and notes are written by * whatever integration fired them, so they are untrusted input that may contain * anything, and a log file is a place people forget to treat as sensitive. * Script source is available at `debug`, which an operator turns on knowingly. */ /** Ordered least to most verbose; a level enables itself and everything above it. */ export declare const LOG_LEVELS: readonly ["error", "warn", "info", "debug"]; export type LogLevel = (typeof LOG_LEVELS)[number]; export declare const DEFAULT_LOG_LEVEL: LogLevel; export type LogFields = Record; export interface Logger { error(event: string, fields?: LogFields): void; warn(event: string, fields?: LogFields): void; info(event: string, fields?: LogFields): void; debug(event: string, fields?: LogFields): void; /** Whether a level would be emitted, so a caller can skip building the fields. */ enabled(level: LogLevel): boolean; } export interface LoggerOptions { level?: LogLevel; /** * Where a finished line goes. Defaults to stderr. * * Injectable for tests only — there is no environment variable for it, so no * configuration can redirect these lines to stdout. */ write?: (line: string) => void; /** Clock, for tests that assert on the timestamp. */ now?: () => Date; } /** Parses JSM_LOG_LEVEL, falling back rather than failing: a typo should not stop the server. */ export declare function parseLogLevel(raw: string | undefined): LogLevel; export declare function createLogger(options?: LoggerOptions): Logger; /** * The process-wide logger, configured from the environment at import time. * * Read once rather than per call for the same reason resolveSelection is read * once at startup: a value that can change between two lines of the same * invocation is a value nobody can reason about. */ export declare const log: Logger; //# sourceMappingURL=log.d.ts.map