loggily 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-B3pox577.mjs","names":["_process","pc","_withMetrics","_createMetricsCollector"],"sources":["../src/colors.ts","../src/file-writer.ts","../src/tracing.ts","../src/pipeline.ts","../src/core.ts"],"sourcesContent":["/**\n * Vendored ANSI color functions — replaces picocolors dependency.\n * Supports NO_COLOR, FORCE_COLOR, and TTY detection.\n */\n\nconst _process = typeof process !== \"undefined\" ? process : undefined\n\nconst enabled =\n _process?.env?.[\"FORCE_COLOR\"] !== undefined && _process?.env?.[\"FORCE_COLOR\"] !== \"0\"\n ? true\n : _process?.env?.[\"NO_COLOR\"] !== undefined\n ? false\n : (_process?.stdout?.isTTY ?? false)\n\nfunction wrap(open: string, close: string): (str: string) => string {\n if (!enabled) return (str) => str\n return (str) => open + str + close\n}\n\nexport const colors = {\n dim: wrap(\"\\x1b[2m\", \"\\x1b[22m\"),\n blue: wrap(\"\\x1b[34m\", \"\\x1b[39m\"),\n yellow: wrap(\"\\x1b[33m\", \"\\x1b[39m\"),\n red: wrap(\"\\x1b[31m\", \"\\x1b[39m\"),\n magenta: wrap(\"\\x1b[35m\", \"\\x1b[39m\"),\n cyan: wrap(\"\\x1b[36m\", \"\\x1b[39m\"),\n}\n","/**\n * File writer for loggily — Node.js/Bun only.\n *\n * Separated from core logger to allow tree-shaking in browser bundles.\n * Uses dynamic import(\"node:fs\") to avoid static dependency on Node APIs.\n */\n\nimport { openSync, writeSync, closeSync } from \"node:fs\"\n\n/** Options for creating an async buffered file writer */\nexport interface FileWriterOptions {\n /** Buffer size threshold in bytes before flushing (default: 4096) */\n bufferSize?: number\n /** Flush interval in milliseconds (default: 100) */\n flushInterval?: number\n}\n\n/** An async buffered file writer with automatic flushing */\nexport interface FileWriter {\n /** Write a line to the buffer (appends newline) */\n write(line: string): void\n /** Flush the buffer immediately */\n flush(): void\n /** Close the writer and flush remaining buffer */\n close(): void\n}\n\n/**\n * Create an async buffered file writer for log output.\n * Buffers writes and flushes on size threshold or interval.\n * Registers a process.on('exit') handler to flush remaining buffer.\n *\n * **Node.js/Bun only** — not available in browser environments.\n *\n * @param filePath - Path to the log file (opened in append mode)\n * @param options - Buffer size and flush interval configuration\n * @returns FileWriter with write, flush, and close methods\n *\n * @example\n * const writer = createFileWriter('/tmp/app.log')\n * const unsubscribe = addWriter((formatted) => writer.write(formatted))\n *\n * // On shutdown:\n * unsubscribe()\n * writer.close()\n */\nexport function createFileWriter(filePath: string, options: FileWriterOptions = {}): FileWriter {\n const bufferSize = options.bufferSize ?? 4096\n const flushInterval = options.flushInterval ?? 100\n\n let buffer = \"\"\n let fd: number | null = null\n let timer: ReturnType<typeof setInterval> | null = null\n let closed = false\n\n // Open file in append mode\n fd = openSync(filePath, \"a\")\n\n /** Flush buffer contents to disk synchronously */\n function flush(): void {\n if (buffer.length === 0 || fd === null) return\n const data = buffer\n writeSync(fd, data)\n buffer = \"\"\n }\n\n // Set up periodic flush\n timer = setInterval(flush, flushInterval)\n // Don't let the timer keep the process alive\n if (timer && typeof timer === \"object\" && \"unref\" in timer) {\n ;(timer as { unref(): void }).unref()\n }\n\n // Flush on process exit to avoid data loss\n const exitHandler = (): void => flush()\n process.on(\"exit\", exitHandler)\n\n return {\n write(line: string): void {\n if (closed) return\n buffer += line + \"\\n\"\n if (buffer.length >= bufferSize) {\n flush()\n }\n },\n\n flush,\n\n close(): void {\n if (closed) return\n closed = true\n if (timer !== null) {\n clearInterval(timer)\n timer = null\n }\n try {\n flush()\n } catch {\n // Swallow flush errors during close — data loss is unavoidable\n // at this point, but we must still release the fd and exit handler.\n } finally {\n if (fd !== null) {\n closeSync(fd)\n fd = null\n }\n process.removeListener(\"exit\", exitHandler)\n }\n },\n }\n}\n","/**\n * Distributed tracing utilities for loggily.\n *\n * Provides W3C-compatible trace/span ID generation, traceparent header formatting,\n * and head-based sampling. All features are opt-in and don't break the existing API.\n */\n\nimport type { SpanData } from \"./core.js\"\n\n// ============ ID Format ============\n\n/** Supported ID formats */\nexport type IdFormat = \"simple\" | \"w3c\"\n\nlet currentIdFormat: IdFormat = \"simple\"\n\n/**\n * Set the ID format for new spans and traces.\n * - \"simple\": sp_1, sp_2, tr_1, tr_2 (default, lightweight)\n * - \"w3c\": 32-char hex trace ID, 16-char hex span ID (W3C Trace Context compatible)\n *\n * @deprecated Use the `TRACE_ID_FORMAT` env var or `{ idFormat: \"w3c\" }` in the config array instead.\n */\nexport function setIdFormat(format: IdFormat): void {\n currentIdFormat = format\n}\n\n/**\n * Get the current ID format.\n *\n * @deprecated Use the `TRACE_ID_FORMAT` env var or `{ idFormat: \"w3c\" }` in the config array instead.\n */\nexport function getIdFormat(): IdFormat {\n return currentIdFormat\n}\n\n// Simple format counters (used by core.ts via the generator functions)\nlet simpleSpanCounter = 0\nlet simpleTraceCounter = 0\n\n/** Generate a hex string of the given byte length using crypto.randomUUID */\nfunction randomHex(bytes: number): string {\n // crypto.randomUUID() gives us 32 hex chars (128 bits) after removing dashes\n // For 16 bytes (32 hex chars) we use one UUID, for 8 bytes (16 hex chars) we take a slice\n const uuid = crypto.randomUUID().replace(/-/g, \"\")\n return uuid.slice(0, bytes * 2)\n}\n\n/** Generate a span ID according to the current format */\nexport function generateSpanId(): string {\n if (currentIdFormat === \"w3c\") {\n return randomHex(8) // 16-char hex\n }\n return `sp_${(++simpleSpanCounter).toString(36)}`\n}\n\n/** Generate a trace ID according to the current format */\nexport function generateTraceId(): string {\n if (currentIdFormat === \"w3c\") {\n return randomHex(16) // 32-char hex\n }\n return `tr_${(++simpleTraceCounter).toString(36)}`\n}\n\n/** Reset ID counters (for testing) */\nexport function resetIdCounters(): void {\n simpleSpanCounter = 0\n simpleTraceCounter = 0\n}\n\n// ============ W3C Traceparent ============\n\n/** Options for traceparent header formatting */\nexport interface TraceparentOptions {\n /** Whether this span is sampled. Defaults to true for backwards compatibility. */\n sampled?: boolean\n}\n\n/**\n * Format a W3C traceparent header from span data.\n *\n * Format: `{version}-{trace-id}-{span-id}-{trace-flags}`\n * - version: \"00\" (current W3C spec version)\n * - trace-id: 32 hex chars (128 bits)\n * - span-id: 16 hex chars (64 bits)\n * - trace-flags: \"01\" (sampled) or \"00\" (not sampled)\n *\n * Works with both simple and W3C ID formats. Simple IDs are zero-padded to spec length.\n *\n * @param spanData - Span data with id and traceId\n * @param options - Optional settings (sampled flag). Defaults to sampled=true.\n * @returns W3C traceparent header string\n *\n * @example\n * ```typescript\n * const span = log.span(\"http-request\")\n * const header = traceparent(span.spanData)\n * // → \"00-a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6-1a2b3c4d5e6f7a8b-01\"\n * fetch(url, { headers: { traceparent: header } })\n * ```\n */\nexport function traceparent(spanData: SpanData, options?: TraceparentOptions): string {\n const traceId = padHex(spanData.traceId, 32)\n const spanId = padHex(spanData.id, 16)\n const flags = (options?.sampled ?? true) ? \"01\" : \"00\"\n return `00-${traceId}-${spanId}-${flags}`\n}\n\n/** Pad or hash an ID to the specified hex length */\nfunction padHex(id: string, length: number): string {\n // If it's already the right length and looks like hex, use as-is\n if (id.length === length && /^[0-9a-f]+$/.test(id)) {\n return id\n }\n\n // For simple IDs (sp_1, tr_1), create a deterministic hex representation\n // by encoding the string as hex bytes, zero-padded to the target length\n let hex = \"\"\n for (let i = 0; i < id.length; i++) {\n hex += id.charCodeAt(i).toString(16).padStart(2, \"0\")\n }\n // Pad or truncate to target length\n return hex.padStart(length, \"0\").slice(-length)\n}\n\n// ============ Sampling ============\n\nlet sampleRate = 1.0\n\n/**\n * Set the head-based sampling rate for new traces.\n * Applied at trace creation — all spans within a sampled trace are kept.\n *\n * @deprecated Use the `TRACE_SAMPLE_RATE` env var or `{ sampleRate: 0.1 }` in the config array instead.\n * @param rate - Sampling rate from 0.0 (sample nothing) to 1.0 (sample everything, default)\n */\nexport function setSampleRate(rate: number): void {\n if (rate < 0 || rate > 1) {\n throw new Error(`Sample rate must be between 0.0 and 1.0, got ${rate}`)\n }\n sampleRate = rate\n}\n\n/**\n * Get the current sampling rate.\n *\n * @deprecated Use the `TRACE_SAMPLE_RATE` env var or `{ sampleRate: 0.1 }` in the config array instead.\n */\nexport function getSampleRate(): number {\n return sampleRate\n}\n\n/**\n * Determine whether a new trace should be sampled.\n * Called at trace creation time (head-based sampling).\n */\nexport function shouldSample(): boolean {\n if (sampleRate >= 1.0) return true\n if (sampleRate <= 0.0) return false\n return Math.random() < sampleRate\n}\n","import { colors as pc } from \"./colors.js\"\nimport { createFileWriter } from \"./file-writer.js\"\nimport { setIdFormat, setSampleRate } from \"./tracing.js\"\nimport type { IdFormat } from \"./tracing.js\"\n\n// ============ Types ============\n\nexport type OutputLogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\"\nexport type LogLevel = OutputLogLevel | \"silent\"\nexport type LogFormat = \"console\" | \"json\"\n\nexport type LogEvent = {\n kind: \"log\"\n time: number\n namespace: string\n level: OutputLogLevel\n message: string\n props?: Record<string, unknown>\n}\n\nexport type SpanEvent = {\n kind: \"span\"\n time: number\n namespace: string\n name: string\n duration: number\n props?: Record<string, unknown>\n spanId: string\n traceId: string\n parentId: string | null\n}\n\nexport type Event = LogEvent | SpanEvent\nexport type Stage = (event: Event) => Event | null | void\n\n// ============ Level Priority ============\n\nexport const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {\n trace: 0,\n debug: 1,\n info: 2,\n warn: 3,\n error: 4,\n silent: 5,\n}\n\n// ============ Runtime Detection ============\n\nconst _process = typeof process !== \"undefined\" ? process : undefined\n\nfunction getEnv(key: string): string | undefined {\n return _process?.env?.[key]\n}\n\nfunction writeStderr(text: string): void {\n if (_process?.stderr?.write) {\n _process.stderr.write(text + \"\\n\")\n } else {\n console.error(text)\n }\n}\n\n// ============ Formatting ============\n\n/** Serialize Error.cause chains up to a max depth */\nexport function serializeCause(cause: unknown, maxDepth: number = 3): unknown {\n if (maxDepth <= 0 || cause === undefined || cause === null) return undefined\n if (cause instanceof Error) {\n const result: Record<string, unknown> = {\n name: cause.name,\n message: cause.message,\n stack: cause.stack,\n }\n if ((cause as { code?: string }).code) result.code = (cause as { code?: string }).code\n if (cause.cause !== undefined) {\n result.cause = serializeCause(cause.cause, maxDepth - 1)\n }\n return result\n }\n // Non-Error cause (spec allows any value)\n return cause\n}\n\nexport function safeStringify(value: unknown): string {\n const seen = new WeakSet()\n return JSON.stringify(value, (_key, val) => {\n if (typeof val === \"bigint\") return val.toString()\n if (typeof val === \"symbol\") return val.toString()\n if (val instanceof Error) {\n const result: Record<string, unknown> = { message: val.message, stack: val.stack, name: val.name }\n if ((val as { code?: string }).code) result.code = (val as { code?: string }).code\n if (val.cause !== undefined) result.cause = serializeCause(val.cause)\n return result\n }\n if (typeof val === \"object\" && val !== null) {\n if (seen.has(val)) return \"[Circular]\"\n seen.add(val)\n }\n return val\n })\n}\n\nexport function formatConsoleEvent(event: Event): string {\n const time = pc.dim(new Date(event.time).toISOString().split(\"T\")[1]?.split(\".\")[0] || \"\")\n const ns = pc.cyan(event.namespace)\n\n if (event.kind === \"span\") {\n const message = `(${event.duration}ms)`\n let output = `${time} ${pc.magenta(\"SPAN\")} ${ns} ${message}`\n if (event.props && Object.keys(event.props).length > 0) {\n output += ` ${pc.dim(safeStringify(event.props))}`\n }\n return output\n }\n\n let levelStr: string\n switch (event.level) {\n case \"trace\":\n levelStr = pc.dim(\"TRACE\")\n break\n case \"debug\":\n levelStr = pc.dim(\"DEBUG\")\n break\n case \"info\":\n levelStr = pc.blue(\"INFO\")\n break\n case \"warn\":\n levelStr = pc.yellow(\"WARN\")\n break\n case \"error\":\n levelStr = pc.red(\"ERROR\")\n break\n }\n\n let output = `${time} ${levelStr} ${ns} ${event.message}`\n if (event.props && Object.keys(event.props).length > 0) {\n output += ` ${pc.dim(safeStringify(event.props))}`\n }\n return output\n}\n\nexport function formatJSONEvent(event: Event): string {\n if (event.kind === \"span\") {\n return safeStringify({\n time: new Date(event.time).toISOString(),\n level: \"span\",\n name: event.namespace,\n msg: `(${event.duration}ms)`,\n duration: event.duration,\n span_id: event.spanId,\n trace_id: event.traceId,\n parent_id: event.parentId,\n ...event.props,\n })\n }\n\n return safeStringify({\n time: new Date(event.time).toISOString(),\n level: event.level,\n name: event.namespace,\n msg: event.message,\n ...event.props,\n })\n}\n\n// ============ Namespace Filter ============\n\nexport type NsFilter = (namespace: string) => boolean\n\nfunction matchesPattern(namespace: string, pattern: string): boolean {\n if (pattern === \"*\") return true\n if (pattern.endsWith(\":*\")) {\n const prefix = pattern.slice(0, -2)\n return namespace === prefix || namespace.startsWith(prefix + \":\")\n }\n return namespace === pattern || namespace.startsWith(pattern + \":\")\n}\n\nexport function parseNsFilter(ns: string | string[]): NsFilter {\n const patterns = typeof ns === \"string\" ? ns.split(\",\").map((s) => s.trim()) : ns\n const includes: string[] = []\n const excludes: string[] = []\n\n for (const p of patterns) {\n if (p.startsWith(\"-\")) {\n excludes.push(p.slice(1))\n } else {\n includes.push(p)\n }\n }\n\n return (namespace: string): boolean => {\n for (const exc of excludes) {\n if (matchesPattern(namespace, exc)) return false\n }\n if (includes.length > 0) {\n for (const inc of includes) {\n if (matchesPattern(namespace, inc)) return true\n }\n return false\n }\n return true\n }\n}\n\n// ============ Console Output ============\n\n/**\n * Write formatted text to console using the appropriate log level.\n *\n * IMPORTANT: We use Function.bind() to preserve caller source locations in\n * browser DevTools. When you click a log line in DevTools, it shows where\n * YOUR code called log.info?.(), not where pipeline.ts called console.info().\n * DO NOT replace bind() with direct console.info(text) calls — it breaks\n * source location tracking in browsers.\n */\nexport function writeToConsole(text: string, event: Event): void {\n if (event.kind === \"span\") {\n writeStderr(text)\n return\n }\n // bind() preserves the call site in browser DevTools source maps.\n // The bound function is immediately invoked — bind() just ensures the\n // DevTools stack trace points to the user's code, not this file.\n switch (event.level) {\n case \"trace\":\n case \"debug\":\n Function.prototype.bind.call(console.debug, console, text)()\n break\n case \"info\":\n Function.prototype.bind.call(console.info, console, text)()\n break\n case \"warn\":\n Function.prototype.bind.call(console.warn, console, text)()\n break\n case \"error\":\n Function.prototype.bind.call(console.error, console, text)()\n break\n }\n}\n\n// ============ Sinks ============\n\nfunction createConsoleSink(format: LogFormat): (event: Event) => void {\n const formatter = format === \"json\" ? formatJSONEvent : formatConsoleEvent\n return (event: Event) => writeToConsole(formatter(event), event)\n}\n\nfunction createFileSink(path: string, format: LogFormat): { write: (event: Event) => void; dispose: () => void } {\n const writer = createFileWriter(path)\n const formatter = format === \"json\" ? formatJSONEvent : formatConsoleEvent\n return {\n write: (event: Event) => writer.write(formatter(event)),\n dispose: () => writer.close(),\n }\n}\n\nfunction isNodeStream(obj: unknown): boolean {\n return typeof obj === \"object\" && obj !== null && (\"_write\" in obj || \"writable\" in obj || \"fd\" in obj)\n}\n\nfunction createWritableSink(writable: Writable, format: LogFormat): (event: Event) => void {\n // Node.js streams (process.stderr, fs streams) default to string mode\n // Plain { write } objects default to object mode (raw Events)\n const useObjectMode = writable.objectMode ?? !isNodeStream(writable)\n if (!useObjectMode) {\n const formatter = format === \"json\" ? formatJSONEvent : formatConsoleEvent\n return (event: Event) => writable.write(formatter(event) + \"\\n\")\n }\n return (event: Event) => writable.write(event)\n}\n\n// ============ Pipeline ============\n\nexport interface Pipeline {\n dispatch: (event: Event) => void\n level: LogLevel\n dispose: () => void\n}\n\ninterface Output {\n levelPriority: number\n nsFilter: NsFilter | null\n write: (event: Event) => void\n dispose?: () => void\n}\n\n// ============ Discrimination ============\n\nconst VALID_CONFIG_KEYS = new Set([\"level\", \"ns\", \"format\", \"spans\", \"metrics\", \"idFormat\", \"sampleRate\"])\nconst SINK_KEYS = new Set([\"file\", \"otel\"])\n\nfunction isPojo(obj: unknown): obj is Record<string, unknown> {\n if (typeof obj !== \"object\" || obj === null) return false\n const proto = Object.getPrototypeOf(obj)\n return proto === Object.prototype || proto === null\n}\n\nfunction isWritable(obj: unknown): obj is Writable {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n \"write\" in obj &&\n typeof (obj as Record<string, unknown>).write === \"function\"\n )\n}\n\nfunction isValidLogLevel(val: unknown): val is LogLevel {\n return typeof val === \"string\" && val in LOG_LEVEL_PRIORITY\n}\n\n// ============ Config Types ============\n\n/** A writable sink — any object with a write method. Receives raw Event objects by default. */\nexport interface Writable {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n write: (data: any) => any\n /** Set to false to receive formatted strings instead of raw Event objects (default: true) */\n objectMode?: boolean\n}\n\n/** Config keys that set scope for subsequent siblings */\nexport interface ConfigObject {\n level?: LogLevel\n ns?: string | string[]\n format?: LogFormat\n spans?: boolean\n /** Enable per-logger metrics collection. Creates a MetricsCollector accessible via `log.metrics`. */\n metrics?: boolean\n /** ID format for trace/span IDs: \"simple\" (default) or \"w3c\" (W3C Trace Context) */\n idFormat?: \"simple\" | \"w3c\"\n /** Head-based sampling rate for new traces: 0.0 (none) to 1.0 (all, default) */\n sampleRate?: number\n}\n\n/** File output descriptor */\nexport interface FileDescriptor extends ConfigObject {\n file: string\n}\n\n/** OTEL output descriptor (Phase 4) */\nexport interface OtelDescriptor extends ConfigObject {\n otel: Record<string, unknown>\n}\n\n/** A single element in a createLogger config array */\nexport type ConfigElement =\n | ConfigObject\n | FileDescriptor\n | OtelDescriptor\n | Console\n | \"console\"\n | \"stderr\"\n | Stage\n | Writable\n | ConfigElement[]\n\n// ============ Build Pipeline ============\n\ninterface ScopeConfig {\n level: LogLevel\n ns: NsFilter | null\n format: LogFormat\n}\n\nexport function buildPipeline(elements: ConfigElement[], parentConfig?: Partial<ScopeConfig>): Pipeline {\n const config: ScopeConfig = {\n level: parentConfig?.level ?? readEnvLevel(),\n ns: parentConfig?.ns ?? readEnvNs(),\n format: parentConfig?.format ?? readEnvFormat(),\n }\n // Spans always pass through explicit pipelines. { spans: false } to opt out.\n // The defaultPipeline handles TRACE env var gating separately.\n let spansEnabled = true\n\n const stages: Stage[] = []\n const outputs: Output[] = []\n const branches: Pipeline[] = []\n const disposables: (() => void)[] = []\n\n for (const element of elements) {\n // 1. Array → branch\n if (Array.isArray(element)) {\n const branch = buildPipeline(element as ConfigElement[], { ...config })\n branches.push(branch)\n disposables.push(() => branch.dispose())\n continue\n }\n\n // 2. console (literal or \"console\" string) → console sink (check before function — console is function-like)\n if (element === console || element === \"console\") {\n outputs.push({\n levelPriority: LOG_LEVEL_PRIORITY[config.level],\n nsFilter: config.ns,\n write: createConsoleSink(config.format),\n })\n continue\n }\n\n // 3. Function → stage\n if (typeof element === \"function\") {\n stages.push(element as Stage)\n continue\n }\n\n // 4. Writable ({ write }) → writable sink (checked BEFORE POJO so { write: fn } works)\n if (isWritable(element)) {\n outputs.push({\n levelPriority: LOG_LEVEL_PRIORITY[config.level],\n nsFilter: config.ns,\n write: createWritableSink(element, config.format),\n })\n continue\n }\n\n // 5. POJO → scope config or output descriptor\n if (isPojo(element)) {\n const obj = element\n const keys = Object.keys(obj)\n\n const hasSinkKey = keys.some((k) => SINK_KEYS.has(k))\n const hasUnknownKey = keys.some((k) => !VALID_CONFIG_KEYS.has(k) && !SINK_KEYS.has(k))\n\n if (hasUnknownKey) {\n const unknown = keys.find((k) => !VALID_CONFIG_KEYS.has(k) && !SINK_KEYS.has(k))\n throw new Error(\n `loggily: unknown config key \"${unknown}\" in config object. Valid keys: ${[...VALID_CONFIG_KEYS, ...SINK_KEYS].join(\", \")}`,\n )\n }\n\n if (hasSinkKey) {\n if (typeof obj.file === \"string\") {\n const outputLevel = isValidLogLevel(obj.level) ? obj.level : config.level\n const outputNs = obj.ns ? parseNsFilter(obj.ns as string | string[]) : config.ns\n const outputFormat = (obj.format as LogFormat) ?? config.format\n const sink = createFileSink(obj.file, outputFormat)\n disposables.push(sink.dispose)\n outputs.push({\n levelPriority: LOG_LEVEL_PRIORITY[outputLevel],\n nsFilter: outputNs,\n write: sink.write,\n dispose: sink.dispose,\n })\n }\n if (obj.otel !== undefined) {\n throw new Error(\"loggily: OTEL sink is not yet implemented. See loggily/otel for the planned bridge.\")\n }\n continue\n }\n\n // Scope config — update inherited config\n if (isValidLogLevel(obj.level)) config.level = obj.level\n if (obj.ns !== undefined) config.ns = parseNsFilter(obj.ns as string | string[])\n if (obj.format === \"console\" || obj.format === \"json\") config.format = obj.format\n if (obj.spans === true) spansEnabled = true\n if (obj.spans === false) spansEnabled = false\n if (obj.idFormat === \"simple\" || obj.idFormat === \"w3c\") setIdFormat(obj.idFormat)\n if (typeof obj.sampleRate === \"number\") setSampleRate(obj.sampleRate)\n continue\n }\n\n // 6. String \"stderr\" → stderr sink\n if (element === \"stderr\" && typeof process !== \"undefined\") {\n outputs.push({\n levelPriority: LOG_LEVEL_PRIORITY[config.level],\n nsFilter: config.ns,\n write: createWritableSink(process.stderr as unknown as Writable, config.format),\n })\n continue\n }\n\n throw new Error(\n `loggily: unsupported config element of type \"${typeof element}\". ` +\n 'Config arrays accept: objects (config), arrays (branches), functions (stages), console, \"console\", or writables ({ write }).',\n )\n }\n\n const dispatch = (event: Event): void => {\n // Span gate: { spans: false } disables span output for this pipeline\n if (event.kind === \"span\" && !spansEnabled) return\n\n let e: Event = event\n for (const stage of stages) {\n const result = stage(e)\n if (result === null) return\n if (result !== undefined) e = result\n }\n for (const output of outputs) {\n if (e.kind === \"log\" && LOG_LEVEL_PRIORITY[e.level] < output.levelPriority) continue\n if (output.nsFilter && !output.nsFilter(e.namespace)) continue\n output.write(e)\n }\n for (const branch of branches) {\n branch.dispatch(e)\n }\n }\n\n return {\n dispatch,\n level: config.level,\n dispose: () => {\n for (const d of disposables) d()\n },\n }\n}\n\n// ============ Env Var Readers (exported for withEnvDefaults plugin) ============\n\nexport function readEnvLevel(): LogLevel {\n const env = getEnv(\"LOG_LEVEL\")?.toLowerCase()\n let level: LogLevel =\n env === \"trace\" || env === \"debug\" || env === \"info\" || env === \"warn\" || env === \"error\" || env === \"silent\"\n ? env\n : \"info\"\n\n const debugEnv = getEnv(\"DEBUG\")\n if (debugEnv && LOG_LEVEL_PRIORITY[level] > LOG_LEVEL_PRIORITY.debug) {\n level = \"debug\"\n }\n\n return level\n}\n\n/**\n * Namespace-aware level: only bumps to debug if the namespace matches the DEBUG filter.\n * This enables zero-overhead conditional gating — `log.debug?.()` returns undefined\n * for namespaces outside the DEBUG filter, skipping argument evaluation entirely.\n */\nexport function readEnvLevelForNamespace(namespace: string): LogLevel {\n const env = getEnv(\"LOG_LEVEL\")?.toLowerCase()\n const baseLevel: LogLevel =\n env === \"trace\" || env === \"debug\" || env === \"info\" || env === \"warn\" || env === \"error\" || env === \"silent\"\n ? env\n : \"info\"\n\n const debugEnv = getEnv(\"DEBUG\")\n if (debugEnv && LOG_LEVEL_PRIORITY[baseLevel] > LOG_LEVEL_PRIORITY.debug) {\n // DEBUG is set and would bump level — check if this namespace matches\n const nsFilter = readEnvNs()\n if (nsFilter && nsFilter(namespace)) {\n return \"debug\" // namespace matches DEBUG filter — bump to debug\n }\n // Namespace doesn't match — keep the configured level\n return baseLevel\n }\n\n return baseLevel\n}\n\nexport function readEnvNs(): NsFilter | null {\n const debugEnv = getEnv(\"DEBUG\")\n if (!debugEnv) return null\n\n const parts = debugEnv.split(\",\").map((s) => s.trim())\n return parseNsFilter(parts)\n}\n\nexport function readEnvFormat(): LogFormat {\n const envFormat = getEnv(\"LOG_FORMAT\")?.toLowerCase()\n if (envFormat === \"json\") return \"json\"\n if (envFormat === \"console\") return \"console\"\n if (getEnv(\"TRACE_FORMAT\") === \"json\") return \"json\"\n if (getEnv(\"NODE_ENV\") === \"production\") return \"json\"\n return \"console\"\n}\n\nexport function readEnvTrace(): { enabled: boolean; filter: NsFilter | null } {\n const traceEnv = getEnv(\"TRACE\")\n if (!traceEnv) return { enabled: false, filter: null }\n if (traceEnv === \"1\" || traceEnv === \"true\") return { enabled: true, filter: null }\n const prefixes = traceEnv.split(\",\").map((s) => s.trim())\n return {\n enabled: true,\n filter: (namespace: string) => {\n for (const prefix of prefixes) {\n if (matchesPattern(namespace, prefix)) return true\n }\n return false\n },\n }\n}\n","/**\n * loggily v2 — Structured logging with spans\n *\n * One import. Objects configure. Arrays branch. Values write.\n *\n * @example\n * const log = createLogger('myapp')\n * log.info?.('starting')\n *\n * @example\n * const log = createLogger('myapp', [\n * { level: 'debug', ns: '-sql' },\n * console,\n * { file: '/tmp/app.log', level: 'info', format: 'json' },\n * ])\n * log.info?.('server started', { port: 3000 })\n */\n\nimport {\n type Event,\n type LogEvent,\n type SpanEvent,\n type Pipeline,\n type Stage,\n type LogLevel,\n type OutputLogLevel,\n type LogFormat,\n type NsFilter,\n type ConfigElement,\n LOG_LEVEL_PRIORITY,\n buildPipeline,\n safeStringify,\n serializeCause,\n readEnvLevel,\n readEnvLevelForNamespace,\n readEnvNs,\n readEnvFormat,\n readEnvTrace,\n writeToConsole,\n formatConsoleEvent,\n formatJSONEvent,\n} from \"./pipeline.js\"\n\nimport { createMetricsCollector as _createMetricsCollector, withMetrics as _withMetrics } from \"./metrics.js\"\n\nexport type { Event, LogEvent, SpanEvent, Stage, LogLevel, OutputLogLevel, LogFormat, ConfigElement }\nexport { LOG_LEVEL_PRIORITY, safeStringify }\n\n// ============ Metrics ============\n\nexport interface SpanRecord {\n readonly name: string\n readonly durationMs: number\n}\n\nexport interface SpanRecorder {\n recordSpan(data: SpanRecord): void\n}\n\n// ============ Types ============\n\nexport type LazyMessage = string | (() => string)\nexport type LazyProps = Record<string, unknown> | (() => Record<string, unknown>)\n\nexport interface SpanData {\n readonly id: string\n readonly traceId: string\n readonly parentId: string | null\n readonly startTime: number\n readonly endTime: number | null\n readonly duration: number | null\n [key: string]: unknown\n}\n\nexport interface Logger extends Disposable {\n readonly name: string\n readonly props: Readonly<Record<string, unknown>>\n readonly level: LogLevel\n\n dispatch(event: Event): void\n\n trace(message: LazyMessage, data?: Record<string, unknown>): void\n debug(message: LazyMessage, data?: Record<string, unknown>): void\n info(message: LazyMessage, data?: Record<string, unknown>): void\n warn(message: LazyMessage, data?: Record<string, unknown>): void\n error(message: LazyMessage, data?: Record<string, unknown>): void\n error(error: Error, data?: Record<string, unknown>): void\n error(error: Error, message: string, data?: Record<string, unknown>): void\n\n /** @deprecated Use .child() */\n logger(namespace?: string, props?: Record<string, unknown>): ConditionalLogger\n span(namespace?: string, props?: LazyProps): SpanLogger\n child(namespace: string, props?: Record<string, unknown>): ConditionalLogger\n child(context: Record<string, unknown>): ConditionalLogger\n end(): void\n}\n\nexport interface SpanLogger extends ConditionalLogger, Disposable {\n readonly spanData: SpanData & { [key: string]: unknown }\n}\n\n// ============ ConditionalLogger ============\n\nexport interface ConditionalLogger extends Disposable {\n readonly name: string\n readonly props: Readonly<Record<string, unknown>>\n readonly level: LogLevel\n\n /** Metrics collector, present when `{ metrics: true }` is in config or `withMetrics()` was applied */\n readonly metrics?: import(\"./metrics.js\").MetricsCollector\n\n dispatch(event: Event): void\n\n trace?: (message: LazyMessage, data?: Record<string, unknown>) => void\n debug?: (message: LazyMessage, data?: Record<string, unknown>) => void\n info?: (message: LazyMessage, data?: Record<string, unknown>) => void\n warn?: (message: LazyMessage, data?: Record<string, unknown>) => void\n error?: {\n (message: LazyMessage, data?: Record<string, unknown>): void\n (error: Error, data?: Record<string, unknown>): void\n (error: Error, message: string, data?: Record<string, unknown>): void\n }\n\n /** @deprecated Use .child() */\n logger(namespace?: string, props?: Record<string, unknown>): ConditionalLogger\n span?(namespace?: string, props?: LazyProps): SpanLogger\n child(namespace: string, props?: Record<string, unknown>): ConditionalLogger\n child(context: Record<string, unknown>): ConditionalLogger\n end(): void\n}\n\n// ============ ID Generation ============\n\nimport {\n generateSpanId,\n generateTraceId,\n resetIdCounters,\n shouldSample,\n setIdFormat,\n setSampleRate,\n} from \"./tracing.js\"\nimport type { IdFormat } from \"./tracing.js\"\n\nexport function resetIds(): void {\n resetIdCounters()\n}\n\n// ============ Context Propagation Hooks ============\n\nlet _getContextTags: (() => Record<string, string>) | null = null\nlet _getContextParent: (() => { spanId: string; traceId: string } | null) | null = null\nlet _enterContext: ((spanId: string, traceId: string, parentId: string | null) => void) | null = null\nlet _exitContext: ((spanId: string) => void) | null = null\n\n/** @internal */\nexport function _setContextHooks(hooks: {\n getContextTags: () => Record<string, string>\n getContextParent: () => { spanId: string; traceId: string } | null\n enterContext: (spanId: string, traceId: string, parentId: string | null) => void\n exitContext: (spanId: string) => void\n}): void {\n _getContextTags = hooks.getContextTags\n _getContextParent = hooks.getContextParent\n _enterContext = hooks.enterContext\n _exitContext = hooks.exitContext\n}\n\n/** @internal */\nexport function _clearContextHooks(): void {\n _getContextTags = null\n _getContextParent = null\n _enterContext = null\n _exitContext = null\n}\n\n// ============ SpanData Proxy ============\n\ninterface SpanDataFields {\n id: string\n traceId: string\n parentId: string | null\n startTime: number\n endTime: number | null\n duration: number | null\n}\n\nexport function createSpanDataProxy(getFields: () => SpanDataFields, attrs: Record<string, unknown>): SpanData {\n const READONLY_KEYS = new Set([\"id\", \"traceId\", \"parentId\", \"startTime\", \"endTime\", \"duration\"])\n return new Proxy(attrs, {\n get(_target, prop) {\n if (READONLY_KEYS.has(prop as string)) {\n return getFields()[prop as keyof SpanDataFields]\n }\n return attrs[prop as string]\n },\n set(_target, prop, value) {\n if (READONLY_KEYS.has(prop as string)) {\n return false\n }\n attrs[prop as string] = value\n return true\n },\n }) as SpanData\n}\n\n// ============ Span Collection ============\n\nconst collectedSpans: SpanData[] = []\nlet collectSpans = false\n\nexport function startCollecting(): void {\n collectSpans = true\n collectedSpans.length = 0\n}\n\nexport function stopCollecting(): SpanData[] {\n collectSpans = false\n return [...collectedSpans]\n}\n\nexport function getCollectedSpans(): SpanData[] {\n return [...collectedSpans]\n}\n\nexport function clearCollectedSpans(): void {\n collectedSpans.length = 0\n}\n\n// ============ Implementation ============\n\nfunction resolveMessage(msg: LazyMessage): string {\n return typeof msg === \"function\" ? msg() : msg\n}\n\ninterface MutableSpanData {\n id: string\n traceId: string\n parentId: string | null\n startTime: number\n endTime: number | null\n duration: number | null\n attrs: Record<string, unknown>\n}\n\nfunction createLoggerImpl(name: string, props: Record<string, unknown>, pipeline: Pipeline): Logger {\n const emitLog = (\n level: OutputLogLevel,\n msgOrError: LazyMessage | Error,\n dataOrMsg?: Record<string, unknown> | string,\n extraData?: Record<string, unknown>,\n ): void => {\n let message: string\n let data: Record<string, unknown> | undefined\n\n if (msgOrError instanceof Error) {\n const err = msgOrError\n const contextTags = _getContextTags?.() ?? {}\n if (typeof dataOrMsg === \"string\") {\n message = dataOrMsg\n data = {\n ...contextTags,\n ...props,\n ...extraData,\n error_type: err.name,\n error_message: err.message,\n error_stack: err.stack,\n error_code: (err as { code?: string }).code,\n error_cause: err.cause !== undefined ? serializeCause(err.cause) : undefined,\n }\n } else {\n message = err.message\n data = {\n ...contextTags,\n ...props,\n ...(dataOrMsg as Record<string, unknown>),\n error_type: err.name,\n error_stack: err.stack,\n error_code: (err as { code?: string }).code,\n error_cause: err.cause !== undefined ? serializeCause(err.cause) : undefined,\n }\n }\n } else {\n message = resolveMessage(msgOrError)\n const contextTags = _getContextTags?.()\n data =\n contextTags && Object.keys(contextTags).length > 0\n ? { ...contextTags, ...props, ...(dataOrMsg as Record<string, unknown>) }\n : Object.keys(props).length > 0 || dataOrMsg\n ? { ...props, ...(dataOrMsg as Record<string, unknown>) }\n : undefined\n }\n\n const event: LogEvent = {\n kind: \"log\",\n time: Date.now(),\n namespace: name,\n level,\n message,\n props: data,\n }\n pipeline.dispatch(event)\n }\n\n const logger: Logger = {\n name,\n props: Object.freeze({ ...props }),\n\n get level(): LogLevel {\n return pipeline.level\n },\n\n dispatch(event: Event): void {\n pipeline.dispatch(event)\n },\n\n [Symbol.dispose](): void {\n pipeline.dispose()\n },\n\n trace: (msg, data) => emitLog(\"trace\", msg, data),\n debug: (msg, data) => emitLog(\"debug\", msg, data),\n info: (msg, data) => emitLog(\"info\", msg, data),\n warn: (msg, data) => emitLog(\"warn\", msg, data),\n error: (\n msgOrError: LazyMessage | Error,\n dataOrMsg?: Record<string, unknown> | string,\n extraData?: Record<string, unknown>,\n ) => emitLog(\"error\", msgOrError, dataOrMsg, extraData),\n\n /** @deprecated Use .child() instead */\n logger(namespace?: string, childProps?: Record<string, unknown>): ConditionalLogger {\n return this.child(namespace ?? \"\", childProps)\n },\n\n span(_namespace?: string, _childProps?: LazyProps): SpanLogger {\n throw new Error(\n \"loggily: span() requires the withSpans() plugin. Use pipe(baseCreateLogger, withSpans()) or the default createLogger.\",\n )\n },\n\n child(\n namespaceOrContext?: string | Record<string, unknown>,\n childProps?: Record<string, unknown>,\n ): ConditionalLogger {\n if (typeof namespaceOrContext === \"string\") {\n const childName = namespaceOrContext ? `${name}:${namespaceOrContext}` : name\n const mergedProps = { ...props, ...childProps }\n return wrapConditional(createLoggerImpl(childName, mergedProps, pipeline), () => pipeline.level)\n }\n // Object -> context fields, same namespace\n return wrapConditional(\n createLoggerImpl(name, { ...props, ...namespaceOrContext }, pipeline),\n () => pipeline.level,\n )\n },\n\n end(): void {\n // no-op for non-span loggers\n },\n }\n\n return logger\n}\n\n// ============ ConditionalLogger Proxy ============\n\nfunction wrapConditional(logger: Logger, getLevel: () => LogLevel): ConditionalLogger {\n return new Proxy(logger as ConditionalLogger, {\n get(target, prop: string | symbol) {\n if (typeof prop === \"string\" && prop in LOG_LEVEL_PRIORITY && prop !== \"silent\") {\n if (LOG_LEVEL_PRIORITY[prop as keyof typeof LOG_LEVEL_PRIORITY] < LOG_LEVEL_PRIORITY[getLevel()]) {\n return undefined\n }\n }\n // span is optional on ConditionalLogger: return undefined if base impl is the error-thrower\n if (prop === \"span\") {\n const val = (target as unknown as Record<string | symbol, unknown>)[prop]\n // If span is the default error-throwing stub, return undefined (making it optional)\n if (val === baseSpanStub) return undefined\n return val\n }\n return (target as unknown as Record<string | symbol, unknown>)[prop]\n },\n })\n}\n\n// Sentinel reference for detecting the base span stub\nconst baseSpanStub = function baseSpanStub(_namespace?: string, _childProps?: LazyProps): SpanLogger {\n throw new Error(\n \"loggily: span() requires the withSpans() plugin. Use pipe(baseCreateLogger, withSpans()) or the default createLogger.\",\n )\n}\n\n// ============ withSpans Plugin ============\n\n/**\n * Plugin: adds span creation capability to loggers.\n * Without this plugin, `.span` is undefined on ConditionalLogger.\n * Included by default in `createLogger`.\n */\nexport function withSpans(): LoggerPlugin {\n return (factory, _ctx) => {\n return (name, configOrProps?) => {\n const logger = factory(name, configOrProps)\n return augmentWithSpans(logger, null, null, true)\n }\n }\n}\n\ninterface SpanState {\n parentSpanId: string | null\n traceId: string | null\n traceSampled: boolean\n}\n\nfunction augmentWithSpans(\n logger: ConditionalLogger,\n parentSpanId: string | null,\n traceId: string | null,\n traceSampled: boolean,\n): ConditionalLogger {\n const spanState: SpanState = { parentSpanId, traceId, traceSampled }\n\n return new Proxy(logger, {\n get(target, prop: string | symbol) {\n if (prop === \"span\") {\n return createSpanMethod(target, spanState)\n }\n if (prop === \"child\") {\n return function child(\n namespaceOrContext?: string | Record<string, unknown>,\n childProps?: Record<string, unknown>,\n ): ConditionalLogger {\n const childLogger = target.child(namespaceOrContext as string, childProps)\n // Child loggers inherit span state (parent/trace context)\n return augmentWithSpans(childLogger, spanState.parentSpanId, spanState.traceId, spanState.traceSampled)\n }\n }\n if (prop === \"logger\") {\n return function logger(namespace?: string, childProps?: Record<string, unknown>): ConditionalLogger {\n const childLogger = target.logger(namespace, childProps)\n return augmentWithSpans(childLogger, spanState.parentSpanId, spanState.traceId, spanState.traceSampled)\n }\n }\n return (target as unknown as Record<string | symbol, unknown>)[prop]\n },\n })\n}\n\nfunction createSpanMethod(\n logger: ConditionalLogger,\n spanState: SpanState,\n): (namespace?: string, childProps?: LazyProps) => SpanLogger {\n return (namespace?: string, childProps?: LazyProps): SpanLogger => {\n const childName = namespace ? `${logger.name}:${namespace}` : logger.name\n const resolvedChildProps = typeof childProps === \"function\" ? childProps() : childProps\n const mergedProps = { ...logger.props, ...resolvedChildProps }\n const newSpanId = generateSpanId()\n\n let resolvedParentId = spanState.parentSpanId\n let resolvedTraceId = spanState.traceId\n\n if (!resolvedParentId && _getContextParent) {\n const ctxParent = _getContextParent()\n if (ctxParent) {\n resolvedParentId = ctxParent.spanId\n resolvedTraceId = resolvedTraceId || ctxParent.traceId\n }\n }\n\n const isNewTrace = !resolvedTraceId\n const finalTraceId = resolvedTraceId || generateTraceId()\n const sampled = isNewTrace ? shouldSample() : spanState.traceSampled\n\n const newSpanData: MutableSpanData = {\n id: newSpanId,\n traceId: finalTraceId,\n parentId: resolvedParentId,\n startTime: Date.now(),\n endTime: null,\n duration: null,\n attrs: {},\n }\n\n // Create a child logger for the span to emit logs through\n const childLogger = logger.child(namespace ?? \"\", resolvedChildProps)\n // Augment the child with span capability, setting this span as parent\n const spanAugmented = augmentWithSpans(childLogger, newSpanId, finalTraceId, sampled)\n\n _enterContext?.(newSpanId, finalTraceId, resolvedParentId)\n\n const disposeSpan = () => {\n if (newSpanData.endTime !== null) return\n\n newSpanData.endTime = Date.now()\n newSpanData.duration = newSpanData.endTime - newSpanData.startTime\n\n if (collectSpans) {\n collectedSpans.push(\n createSpanDataProxy(\n () => ({\n id: newSpanData.id,\n traceId: newSpanData.traceId,\n parentId: newSpanData.parentId,\n startTime: newSpanData.startTime,\n endTime: newSpanData.endTime,\n duration: newSpanData.duration,\n }),\n { ...newSpanData.attrs },\n ),\n )\n }\n\n _exitContext?.(newSpanId)\n if (sampled) {\n const spanEvent: SpanEvent = {\n kind: \"span\",\n time: newSpanData.endTime,\n namespace: childName,\n name: childName,\n duration: newSpanData.duration,\n props: {\n ...mergedProps,\n ...newSpanData.attrs,\n },\n spanId: newSpanData.id,\n traceId: newSpanData.traceId,\n parentId: newSpanData.parentId,\n }\n logger.dispatch(spanEvent)\n }\n }\n\n const spanDataProxy = createSpanDataProxy(\n () => ({\n id: newSpanData.id,\n traceId: newSpanData.traceId,\n parentId: newSpanData.parentId,\n startTime: newSpanData.startTime,\n endTime: newSpanData.endTime,\n duration:\n newSpanData.endTime !== null\n ? newSpanData.endTime - newSpanData.startTime\n : Date.now() - newSpanData.startTime,\n }),\n newSpanData.attrs,\n )\n\n // Build the SpanLogger by overlaying span-specific properties onto the augmented child.\n // Allow Symbol.dispose to be overridden (withMetrics wraps it).\n let currentDispose = disposeSpan\n const spanLogger = new Proxy(spanAugmented as unknown as SpanLogger, {\n get(target, prop: string | symbol) {\n if (prop === \"spanData\") return spanDataProxy\n if (prop === Symbol.dispose) return currentDispose\n if (prop === \"end\") {\n return () => {\n if (newSpanData.endTime === null) {\n currentDispose()\n }\n }\n }\n if (prop === \"name\") return childName\n if (prop === \"props\") return Object.freeze({ ...mergedProps })\n return (target as unknown as Record<string | symbol, unknown>)[prop]\n },\n set(_target, prop: string | symbol, value: unknown) {\n if (prop === Symbol.dispose) {\n currentDispose = value as () => void\n return true\n }\n return false\n },\n })\n\n return spanLogger\n }\n}\n\n// ============ Public API ============\n\n// ============ Base createLogger ============\n\n/**\n * Base createLogger — requires a config array.\n * Use the default `createLogger` export (with `withEnvDefaults`) for zero-config.\n *\n * Note: loggers from baseCreateLogger do NOT have `.span()` capability.\n * Use `pipe(baseCreateLogger, withSpans())` or the default `createLogger` for spans.\n */\nexport function baseCreateLogger(\n name: string,\n configOrProps?: ConfigElement[] | Record<string, unknown>,\n): ConditionalLogger {\n let pipeline: Pipeline\n let props: Record<string, unknown> = {}\n\n if (Array.isArray(configOrProps)) {\n pipeline = buildPipeline(configOrProps)\n } else if (configOrProps && typeof configOrProps === \"object\") {\n props = configOrProps as Record<string, unknown>\n pipeline = buildPipeline([\"console\"])\n } else {\n pipeline = buildPipeline([\"console\"])\n }\n\n const logger = createLoggerImpl(name, props, pipeline)\n // Replace the span method with the sentinel stub so wrapConditional can detect it\n ;(logger as unknown as Record<string, unknown>).span = baseSpanStub\n return wrapConditional(logger, () => pipeline.level)\n}\n\n// ============ Compose ============\n\nexport type LoggerFactory = (\n name: string,\n configOrProps?: ConfigElement[] | Record<string, unknown>,\n) => ConditionalLogger\n\nexport interface PluginCtx {\n [key: string]: unknown\n}\n\nexport type LoggerPlugin = (factory: LoggerFactory, ctx: PluginCtx) => LoggerFactory\n\nexport function pipe(base: LoggerFactory, ...plugins: LoggerPlugin[]): LoggerFactory {\n const ctx: PluginCtx = {}\n return plugins.reduce((factory, plugin) => plugin(factory, ctx), base)\n}\n\n// ============ withEnvDefaults Plugin ============\n\nconst _process = typeof process !== \"undefined\" ? process : undefined\nconst _env = _process?.env ?? ({} as Record<string, string | undefined>)\n\n// Env config — read fresh each dispatch (process.env access is ~ns, parsing is trivial)\nfunction currentLevel(): LogLevel {\n return readEnvLevel()\n}\nfunction currentNs(): NsFilter | null {\n return readEnvNs()\n}\nfunction currentFormat(): LogFormat {\n return readEnvFormat()\n}\nfunction currentTrace(): { enabled: boolean; filter: NsFilter | null } {\n return readEnvTrace()\n}\n\n// Runtime state for legacy addWriter/setSuppressConsole\nconst _writers: Array<(formatted: string, level: string) => void> = []\nlet _suppressConsole = false\n\n// File writer factory — set by index.ts (avoids node:fs in core.ts for browser compat)\nlet _logFileWriterFactory: ((path: string) => { write: (s: string) => void; close: () => void }) | null = null\n/** @internal */\nexport function _setLogFileWriterFactory(factory: typeof _logFileWriterFactory): void {\n _logFileWriterFactory = factory\n}\n\n/**\n * Plugin: read defaults from environment variables (LOG_LEVEL, DEBUG, LOG_FORMAT, TRACE, LOG_FILE).\n * Included by default. Omit to disable env-var behavior entirely.\n *\n * When no config array is given, provides console output + env-var-based config.\n * When a config array IS given, env vars are already used as defaults by buildPipeline.\n * Legacy setters (setLogLevel, addWriter, etc.) affect loggers created without explicit config.\n */\nexport function withEnvDefaults(): LoggerPlugin {\n return (factory, _ctx) => (name, configOrProps?) => {\n // Apply tracing env vars (once per logger creation, idempotent)\n const envIdFormat = _env.TRACE_ID_FORMAT?.toLowerCase()\n if (envIdFormat === \"simple\" || envIdFormat === \"w3c\") {\n setIdFormat(envIdFormat as IdFormat)\n }\n const envSampleRate = _env.TRACE_SAMPLE_RATE\n if (envSampleRate !== undefined) {\n const rate = Number.parseFloat(envSampleRate)\n if (!Number.isNaN(rate) && rate >= 0 && rate <= 1) {\n setSampleRate(rate)\n }\n }\n\n // Explicit config array — pass through, buildPipeline reads env defaults\n if (Array.isArray(configOrProps)) return factory(name, configOrProps)\n\n // No config array — use env-dynamic pipeline.\n // Pass a config array through the factory so all upstream plugins get applied,\n // with a stage that delegates to the env pipeline for dynamic dispatch.\n const envPipeline = createEnvPipeline()\n const envStage: ConfigElement = (event: Event) => {\n envPipeline.dispatch(event)\n return null // consume the event (env pipeline handles all output)\n }\n\n // Props are passed as the first config element to include them in log output\n if (configOrProps && typeof configOrProps === \"object\") {\n // Object props — create logger with props + env pipeline\n // We need to pass props AND a config array. But factory only accepts one or the other.\n // Solution: create via factory with config array, then the child() with props.\n const logger = factory(name, [{ level: \"trace\" as LogLevel }, envStage])\n return applyNamespaceGating(logger.child(configOrProps as Record<string, unknown>))\n }\n\n return applyNamespaceGating(factory(name, [{ level: \"trace\" as LogLevel }, envStage]))\n }\n}\n\n/**\n * Wrap a logger so that conditional method gating is namespace-aware.\n * When DEBUG=myapp:db, only loggers whose namespace matches get debug enabled.\n * Without this, all loggers get debug because readEnvLevel() bumps globally.\n */\nfunction applyNamespaceGating(logger: ConditionalLogger): ConditionalLogger {\n return new Proxy(logger, {\n get(target, prop: string | symbol) {\n if (typeof prop === \"string\" && prop in LOG_LEVEL_PRIORITY && prop !== \"silent\") {\n const nsLevel = readEnvLevelForNamespace(target.name)\n if (LOG_LEVEL_PRIORITY[prop as keyof typeof LOG_LEVEL_PRIORITY] < LOG_LEVEL_PRIORITY[nsLevel]) {\n return undefined\n }\n }\n return (target as unknown as Record<string | symbol, unknown>)[prop]\n },\n })\n}\n\nfunction createEnvPipeline(): Pipeline {\n const disposables: (() => void)[] = []\n const logFile = _env.LOG_FILE\n let fileSink: ((event: Event) => void) | null = null\n if (logFile && _logFileWriterFactory) {\n const writer = _logFileWriterFactory(logFile)\n fileSink = (event: Event) => {\n const fmt = currentFormat() === \"json\" ? formatJSONEvent : formatConsoleEvent\n writer.write(fmt(event))\n }\n disposables.push(() => writer.close())\n }\n\n const dispatch = (event: Event): void => {\n if (event.kind === \"log\" && LOG_LEVEL_PRIORITY[event.level] < LOG_LEVEL_PRIORITY[currentLevel()]) return\n if (event.kind === \"span\") {\n const trace = currentTrace()\n if (!trace.enabled) return\n if (trace.filter && !trace.filter(event.namespace)) return\n }\n const ns = currentNs()\n if (ns && !ns(event.namespace)) return\n\n const formatter = currentFormat() === \"json\" ? formatJSONEvent : formatConsoleEvent\n const text = formatter(event)\n const lvl = event.kind === \"log\" ? event.level : \"span\"\n\n for (const w of _writers) w(text, lvl)\n if (!_suppressConsole) writeToConsole(text, event)\n fileSink?.(event)\n }\n\n return {\n dispatch,\n get level() {\n return currentLevel()\n },\n dispose: () => {\n for (const d of disposables) d()\n },\n }\n}\n\n// ============ withConfigMetrics Plugin ============\n\n/**\n * Plugin: when `{ metrics: true }` appears in the config array, automatically\n * creates a MetricsCollector and applies withMetrics to the logger.\n * The collector is accessible via `logger.metrics`.\n */\nexport function withConfigMetrics(): LoggerPlugin {\n return (factory, _ctx) => {\n return (name, configOrProps?) => {\n const logger = factory(name, configOrProps)\n\n // Only scan config arrays, not props objects\n if (!Array.isArray(configOrProps)) return logger\n\n // Check if any config object has metrics: true (flat scan, not into branches)\n const hasMetrics = configOrProps.some(\n (el) =>\n typeof el === \"object\" &&\n el !== null &&\n !Array.isArray(el) &&\n \"metrics\" in el &&\n (el as Record<string, unknown>).metrics === true,\n )\n\n if (!hasMetrics) return logger\n\n const collector = _createMetricsCollector()\n return _withMetrics(collector)(logger)\n }\n }\n}\n\n/** Default createLogger — includes withEnvDefaults + withSpans + withConfigMetrics. */\nexport const createLogger: LoggerFactory = pipe(baseCreateLogger, withEnvDefaults(), withSpans(), withConfigMetrics())\n\n/** Test helper — all levels, console output. */\nexport function createTestLogger(name: string): ConditionalLogger {\n return pipe(baseCreateLogger, withSpans())(name, [{ level: \"trace\" }, \"console\"])\n}\n\n// ============ Legacy Setters ============\n\n/** @deprecated Use config array */\nexport function setLogLevel(level: LogLevel): void {\n _env.LOG_LEVEL = level\n}\nexport function getLogLevel(): LogLevel {\n return currentLevel()\n}\nexport function enableSpans(): void {\n _env.TRACE = \"1\"\n}\nexport function disableSpans(): void {\n delete _env.TRACE\n}\nexport function spansAreEnabled(): boolean {\n return !!_env.TRACE\n}\nexport function setTraceFilter(namespaces: string[] | null): void {\n if (!namespaces || namespaces.length === 0) delete _env.TRACE\n else _env.TRACE = namespaces.join(\",\")\n}\nexport function getTraceFilter(): string[] | null {\n return _env.TRACE ? _env.TRACE.split(\",\") : null\n}\nexport function setDebugFilter(namespaces: string[] | null): void {\n if (!namespaces || namespaces.length === 0) delete _env.DEBUG\n else _env.DEBUG = namespaces.join(\",\")\n}\nexport function getDebugFilter(): string[] | null {\n return _env.DEBUG ? _env.DEBUG.split(\",\") : null\n}\nexport function setLogFormat(format: LogFormat): void {\n _env.LOG_FORMAT = format\n}\nexport function getLogFormat(): LogFormat {\n return currentFormat()\n}\nexport function setSuppressConsole(value: boolean): void {\n _suppressConsole = value\n}\nexport type OutputMode = \"console\" | \"stderr\" | \"writers-only\"\nexport function setOutputMode(_mode: OutputMode): void {\n throw new Error(\n 'loggily: setOutputMode() is removed in v2. Use config arrays: omit console from array for writers-only, use \"stderr\" for stderr mode.',\n )\n}\nexport function getOutputMode(): OutputMode {\n return \"console\"\n}\nexport function addWriter(writer: (formatted: string, level: string) => void): () => void {\n _writers.push(writer)\n return () => {\n const i = _writers.indexOf(writer)\n if (i !== -1) _writers.splice(i, 1)\n }\n}\nexport function writeSpan(namespace: string, duration: number, attrs: Record<string, unknown>): void {\n createEnvPipeline().dispatch({\n kind: \"span\",\n time: Date.now(),\n namespace,\n name: namespace,\n duration,\n props: attrs,\n spanId: (attrs.span_id as string) ?? \"\",\n traceId: (attrs.trace_id as string) ?? \"\",\n parentId: (attrs.parent_id as string | null) ?? null,\n })\n}\n"],"mappings":";;;;;;;AAKA,MAAMA,aAAW,OAAO,YAAY,cAAc,UAAU,KAAA;AAE5D,MAAM,UACJA,YAAU,MAAM,mBAAmB,KAA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AAkB,OAAsC;AACnG,oBAAmB,CAAC,SAAS;EAC3B,MAAM;EACN,MAAM,KAAK,KAAK;EAChB;EACA,MAAM;EACN;EACA,OAAO;EACP,QAAS,MAAM,WAAsB;EACrC,SAAU,MAAM,YAAuB;EACvC,UAAW,MAAM,aAA+B;EACjD,CAAC"}
@@ -0,0 +1,191 @@
1
+ import { c as LogLevel, r as Event, s as LogFormat, t as ConfigElement } from "./pipeline-Cl9-wCmt.mjs";
2
+
3
+ //#region src/metrics.d.ts
4
+ interface SpanStats {
5
+ count: number;
6
+ min: number;
7
+ max: number;
8
+ mean: number;
9
+ p50: number;
10
+ p95: number;
11
+ p99: number;
12
+ total: number;
13
+ }
14
+ interface MetricsCollector extends SpanRecorder {
15
+ /** Get stats for a specific span namespace */
16
+ stats(name: string): SpanStats | undefined;
17
+ /** Get stats for all recorded namespaces */
18
+ all(): Map<string, SpanStats>;
19
+ /** Format a human-readable summary */
20
+ summary(): string;
21
+ /** Reset all collected data */
22
+ reset(): void;
23
+ }
24
+ declare function createMetricsCollector(maxEntries?: number): MetricsCollector;
25
+ /**
26
+ * Compose a logger with a metrics collector.
27
+ * Returns a curried wrapper: `withMetrics(collector)(logger)`
28
+ *
29
+ * Records span duration to the provided collector on span disposal.
30
+ * Stackable: `withMetrics(a)(withMetrics(b)(logger))` fans out to both.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const collector = createMetricsCollector()
35
+ * const log = withMetrics(collector)(createLogger("myapp"))
36
+ * ```
37
+ */
38
+ declare function withMetrics(collector: SpanRecorder): (logger: ConditionalLogger) => ConditionalLogger;
39
+ //#endregion
40
+ //#region src/core.d.ts
41
+ interface SpanRecord {
42
+ readonly name: string;
43
+ readonly durationMs: number;
44
+ }
45
+ interface SpanRecorder {
46
+ recordSpan(data: SpanRecord): void;
47
+ }
48
+ type LazyMessage = string | (() => string);
49
+ type LazyProps = Record<string, unknown> | (() => Record<string, unknown>);
50
+ interface SpanData {
51
+ readonly id: string;
52
+ readonly traceId: string;
53
+ readonly parentId: string | null;
54
+ readonly startTime: number;
55
+ readonly endTime: number | null;
56
+ readonly duration: number | null;
57
+ [key: string]: unknown;
58
+ }
59
+ interface Logger extends Disposable {
60
+ readonly name: string;
61
+ readonly props: Readonly<Record<string, unknown>>;
62
+ readonly level: LogLevel;
63
+ dispatch(event: Event): void;
64
+ trace(message: LazyMessage, data?: Record<string, unknown>): void;
65
+ debug(message: LazyMessage, data?: Record<string, unknown>): void;
66
+ info(message: LazyMessage, data?: Record<string, unknown>): void;
67
+ warn(message: LazyMessage, data?: Record<string, unknown>): void;
68
+ error(message: LazyMessage, data?: Record<string, unknown>): void;
69
+ error(error: Error, data?: Record<string, unknown>): void;
70
+ error(error: Error, message: string, data?: Record<string, unknown>): void;
71
+ /** @deprecated Use .child() */
72
+ logger(namespace?: string, props?: Record<string, unknown>): ConditionalLogger;
73
+ span(namespace?: string, props?: LazyProps): SpanLogger;
74
+ child(namespace: string, props?: Record<string, unknown>): ConditionalLogger;
75
+ child(context: Record<string, unknown>): ConditionalLogger;
76
+ end(): void;
77
+ }
78
+ interface SpanLogger extends ConditionalLogger, Disposable {
79
+ readonly spanData: SpanData & {
80
+ [key: string]: unknown;
81
+ };
82
+ }
83
+ interface ConditionalLogger extends Disposable {
84
+ readonly name: string;
85
+ readonly props: Readonly<Record<string, unknown>>;
86
+ readonly level: LogLevel;
87
+ /** Metrics collector, present when `{ metrics: true }` is in config or `withMetrics()` was applied */
88
+ readonly metrics?: MetricsCollector;
89
+ dispatch(event: Event): void;
90
+ trace?: (message: LazyMessage, data?: Record<string, unknown>) => void;
91
+ debug?: (message: LazyMessage, data?: Record<string, unknown>) => void;
92
+ info?: (message: LazyMessage, data?: Record<string, unknown>) => void;
93
+ warn?: (message: LazyMessage, data?: Record<string, unknown>) => void;
94
+ error?: {
95
+ (message: LazyMessage, data?: Record<string, unknown>): void;
96
+ (error: Error, data?: Record<string, unknown>): void;
97
+ (error: Error, message: string, data?: Record<string, unknown>): void;
98
+ };
99
+ /** @deprecated Use .child() */
100
+ logger(namespace?: string, props?: Record<string, unknown>): ConditionalLogger;
101
+ span?(namespace?: string, props?: LazyProps): SpanLogger;
102
+ child(namespace: string, props?: Record<string, unknown>): ConditionalLogger;
103
+ child(context: Record<string, unknown>): ConditionalLogger;
104
+ end(): void;
105
+ }
106
+ declare function resetIds(): void;
107
+ /** @internal */
108
+ declare function _setContextHooks(hooks: {
109
+ getContextTags: () => Record<string, string>;
110
+ getContextParent: () => {
111
+ spanId: string;
112
+ traceId: string;
113
+ } | null;
114
+ enterContext: (spanId: string, traceId: string, parentId: string | null) => void;
115
+ exitContext: (spanId: string) => void;
116
+ }): void;
117
+ /** @internal */
118
+ declare function _clearContextHooks(): void;
119
+ interface SpanDataFields {
120
+ id: string;
121
+ traceId: string;
122
+ parentId: string | null;
123
+ startTime: number;
124
+ endTime: number | null;
125
+ duration: number | null;
126
+ }
127
+ declare function createSpanDataProxy(getFields: () => SpanDataFields, attrs: Record<string, unknown>): SpanData;
128
+ declare function startCollecting(): void;
129
+ declare function stopCollecting(): SpanData[];
130
+ declare function getCollectedSpans(): SpanData[];
131
+ declare function clearCollectedSpans(): void;
132
+ /**
133
+ * Plugin: adds span creation capability to loggers.
134
+ * Without this plugin, `.span` is undefined on ConditionalLogger.
135
+ * Included by default in `createLogger`.
136
+ */
137
+ declare function withSpans(): LoggerPlugin;
138
+ /**
139
+ * Base createLogger — requires a config array.
140
+ * Use the default `createLogger` export (with `withEnvDefaults`) for zero-config.
141
+ *
142
+ * Note: loggers from baseCreateLogger do NOT have `.span()` capability.
143
+ * Use `pipe(baseCreateLogger, withSpans())` or the default `createLogger` for spans.
144
+ */
145
+ declare function baseCreateLogger(name: string, configOrProps?: ConfigElement[] | Record<string, unknown>): ConditionalLogger;
146
+ type LoggerFactory = (name: string, configOrProps?: ConfigElement[] | Record<string, unknown>) => ConditionalLogger;
147
+ interface PluginCtx {
148
+ [key: string]: unknown;
149
+ }
150
+ type LoggerPlugin = (factory: LoggerFactory, ctx: PluginCtx) => LoggerFactory;
151
+ declare function pipe(base: LoggerFactory, ...plugins: LoggerPlugin[]): LoggerFactory;
152
+ /**
153
+ * Plugin: read defaults from environment variables (LOG_LEVEL, DEBUG, LOG_FORMAT, TRACE, LOG_FILE).
154
+ * Included by default. Omit to disable env-var behavior entirely.
155
+ *
156
+ * When no config array is given, provides console output + env-var-based config.
157
+ * When a config array IS given, env vars are already used as defaults by buildPipeline.
158
+ * Legacy setters (setLogLevel, addWriter, etc.) affect loggers created without explicit config.
159
+ */
160
+ declare function withEnvDefaults(): LoggerPlugin;
161
+ /**
162
+ * Plugin: when `{ metrics: true }` appears in the config array, automatically
163
+ * creates a MetricsCollector and applies withMetrics to the logger.
164
+ * The collector is accessible via `logger.metrics`.
165
+ */
166
+ declare function withConfigMetrics(): LoggerPlugin;
167
+ /** Default createLogger — includes withEnvDefaults + withSpans + withConfigMetrics. */
168
+ declare const createLogger: LoggerFactory;
169
+ /** Test helper — all levels, console output. */
170
+ declare function createTestLogger(name: string): ConditionalLogger;
171
+ /** @deprecated Use config array */
172
+ declare function setLogLevel(level: LogLevel): void;
173
+ declare function getLogLevel(): LogLevel;
174
+ declare function enableSpans(): void;
175
+ declare function disableSpans(): void;
176
+ declare function spansAreEnabled(): boolean;
177
+ declare function setTraceFilter(namespaces: string[] | null): void;
178
+ declare function getTraceFilter(): string[] | null;
179
+ declare function setDebugFilter(namespaces: string[] | null): void;
180
+ declare function getDebugFilter(): string[] | null;
181
+ declare function setLogFormat(format: LogFormat): void;
182
+ declare function getLogFormat(): LogFormat;
183
+ declare function setSuppressConsole(value: boolean): void;
184
+ type OutputMode = "console" | "stderr" | "writers-only";
185
+ declare function setOutputMode(_mode: OutputMode): void;
186
+ declare function getOutputMode(): OutputMode;
187
+ declare function addWriter(writer: (formatted: string, level: string) => void): () => void;
188
+ declare function writeSpan(namespace: string, duration: number, attrs: Record<string, unknown>): void;
189
+ //#endregion
190
+ export { resetIds as A, withConfigMetrics as B, getCollectedSpans as C, getOutputMode as D, getLogLevel as E, setSuppressConsole as F, SpanStats as G, withSpans as H, setTraceFilter as I, createMetricsCollector as K, spansAreEnabled as L, setLogFormat as M, setLogLevel as N, getTraceFilter as O, setOutputMode as P, startCollecting as R, enableSpans as S, getLogFormat as T, writeSpan as U, withEnvDefaults as V, MetricsCollector as W, clearCollectedSpans as _, LoggerFactory as a, createTestLogger as b, PluginCtx as c, SpanRecord as d, SpanRecorder as f, baseCreateLogger as g, addWriter as h, Logger as i, setDebugFilter as j, pipe as k, SpanData as l, _setContextHooks as m, LazyMessage as n, LoggerPlugin as o, _clearContextHooks as p, withMetrics as q, LazyProps as r, OutputMode as s, ConditionalLogger as t, SpanLogger as u, createLogger as v, getDebugFilter as w, disableSpans as x, createSpanDataProxy as y, stopCollecting as z };
191
+ //# sourceMappingURL=core-Dm2PQUoS.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-Dm2PQUoS.d.mts","names":[],"sources":["../src/metrics.ts","../src/core.ts"],"mappings":";;;UA0BiB,SAAA;EACf,KAAA;EACA,GAAA;EACA,GAAA;EACA,IAAA;EACA,GAAA;EACA,GAAA;EACA,GAAA;EACA,KAAA;AAAA;AAAA,UA0Be,gBAAA,SAAyB,YAAA;EAAY;EAEpD,KAAA,CAAM,IAAA,WAAe,SAAA;EAArB;EAEA,GAAA,IAAO,GAAA,SAAY,SAAA;EAFE;EAIrB,OAAA;EAFO;EAIP,KAAA;AAAA;AAAA,iBAGc,sBAAA,CAAuB,UAAA,YAAoB,gBAAA;;;AAA3D;;;;;AA4DA;;;;;;iBAAgB,WAAA,CAAY,SAAA,EAAW,YAAA,IAAgB,MAAA,EAAQ,iBAAA,KAAsB,iBAAA;;;UCjFpE,UAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA;AAAA;AAAA,UAGM,YAAA;EACf,UAAA,CAAW,IAAA,EAAM,UAAA;AAAA;AAAA,KAKP,WAAA;AAAA,KACA,SAAA,GAAY,MAAA,2BAAiC,MAA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,iBAOtC,SAAA,CAAU,SAAA,UAAmB,QAAA,UAAkB,KAAA,EAAO,MAAA"}
@@ -1,49 +1,5 @@
1
- import { c as SpanData } from "./core-DAFH-huv.mjs";
1
+ import { l as SpanData } from "./core-Dm2PQUoS.mjs";
2
2
 
3
- //#region src/file-writer.d.ts
4
- /**
5
- * File writer for loggily — Node.js/Bun only.
6
- *
7
- * Separated from core logger to allow tree-shaking in browser bundles.
8
- * Uses dynamic import("node:fs") to avoid static dependency on Node APIs.
9
- */
10
- /** Options for creating an async buffered file writer */
11
- interface FileWriterOptions {
12
- /** Buffer size threshold in bytes before flushing (default: 4096) */
13
- bufferSize?: number;
14
- /** Flush interval in milliseconds (default: 100) */
15
- flushInterval?: number;
16
- }
17
- /** An async buffered file writer with automatic flushing */
18
- interface FileWriter {
19
- /** Write a line to the buffer (appends newline) */
20
- write(line: string): void;
21
- /** Flush the buffer immediately */
22
- flush(): void;
23
- /** Close the writer and flush remaining buffer */
24
- close(): void;
25
- }
26
- /**
27
- * Create an async buffered file writer for log output.
28
- * Buffers writes and flushes on size threshold or interval.
29
- * Registers a process.on('exit') handler to flush remaining buffer.
30
- *
31
- * **Node.js/Bun only** — not available in browser environments.
32
- *
33
- * @param filePath - Path to the log file (opened in append mode)
34
- * @param options - Buffer size and flush interval configuration
35
- * @returns FileWriter with write, flush, and close methods
36
- *
37
- * @example
38
- * const writer = createFileWriter('/tmp/app.log')
39
- * const unsubscribe = addWriter((formatted) => writer.write(formatted))
40
- *
41
- * // On shutdown:
42
- * unsubscribe()
43
- * writer.close()
44
- */
45
- declare function createFileWriter(filePath: string, options?: FileWriterOptions): FileWriter;
46
- //#endregion
47
3
  //#region src/tracing.d.ts
48
4
  /** Supported ID formats */
49
5
  type IdFormat = "simple" | "w3c";
@@ -51,9 +7,15 @@ type IdFormat = "simple" | "w3c";
51
7
  * Set the ID format for new spans and traces.
52
8
  * - "simple": sp_1, sp_2, tr_1, tr_2 (default, lightweight)
53
9
  * - "w3c": 32-char hex trace ID, 16-char hex span ID (W3C Trace Context compatible)
10
+ *
11
+ * @deprecated Use the `TRACE_ID_FORMAT` env var or `{ idFormat: "w3c" }` in the config array instead.
54
12
  */
55
13
  declare function setIdFormat(format: IdFormat): void;
56
- /** Get the current ID format */
14
+ /**
15
+ * Get the current ID format.
16
+ *
17
+ * @deprecated Use the `TRACE_ID_FORMAT` env var or `{ idFormat: "w3c" }` in the config array instead.
18
+ */
57
19
  declare function getIdFormat(): IdFormat;
58
20
  /** Options for traceparent header formatting */
59
21
  interface TraceparentOptions {
@@ -88,11 +50,60 @@ declare function traceparent(spanData: SpanData, options?: TraceparentOptions):
88
50
  * Set the head-based sampling rate for new traces.
89
51
  * Applied at trace creation — all spans within a sampled trace are kept.
90
52
  *
53
+ * @deprecated Use the `TRACE_SAMPLE_RATE` env var or `{ sampleRate: 0.1 }` in the config array instead.
91
54
  * @param rate - Sampling rate from 0.0 (sample nothing) to 1.0 (sample everything, default)
92
55
  */
93
56
  declare function setSampleRate(rate: number): void;
94
- /** Get the current sampling rate */
57
+ /**
58
+ * Get the current sampling rate.
59
+ *
60
+ * @deprecated Use the `TRACE_SAMPLE_RATE` env var or `{ sampleRate: 0.1 }` in the config array instead.
61
+ */
95
62
  declare function getSampleRate(): number;
96
63
  //#endregion
97
- export { setIdFormat as a, FileWriter as c, getSampleRate as i, FileWriterOptions as l, TraceparentOptions as n, setSampleRate as o, getIdFormat as r, traceparent as s, IdFormat as t, createFileWriter as u };
98
- //# sourceMappingURL=index-Co4jC3mx.d.mts.map
64
+ //#region src/file-writer.d.ts
65
+ /**
66
+ * File writer for loggily — Node.js/Bun only.
67
+ *
68
+ * Separated from core logger to allow tree-shaking in browser bundles.
69
+ * Uses dynamic import("node:fs") to avoid static dependency on Node APIs.
70
+ */
71
+ /** Options for creating an async buffered file writer */
72
+ interface FileWriterOptions {
73
+ /** Buffer size threshold in bytes before flushing (default: 4096) */
74
+ bufferSize?: number;
75
+ /** Flush interval in milliseconds (default: 100) */
76
+ flushInterval?: number;
77
+ }
78
+ /** An async buffered file writer with automatic flushing */
79
+ interface FileWriter {
80
+ /** Write a line to the buffer (appends newline) */
81
+ write(line: string): void;
82
+ /** Flush the buffer immediately */
83
+ flush(): void;
84
+ /** Close the writer and flush remaining buffer */
85
+ close(): void;
86
+ }
87
+ /**
88
+ * Create an async buffered file writer for log output.
89
+ * Buffers writes and flushes on size threshold or interval.
90
+ * Registers a process.on('exit') handler to flush remaining buffer.
91
+ *
92
+ * **Node.js/Bun only** — not available in browser environments.
93
+ *
94
+ * @param filePath - Path to the log file (opened in append mode)
95
+ * @param options - Buffer size and flush interval configuration
96
+ * @returns FileWriter with write, flush, and close methods
97
+ *
98
+ * @example
99
+ * const writer = createFileWriter('/tmp/app.log')
100
+ * const unsubscribe = addWriter((formatted) => writer.write(formatted))
101
+ *
102
+ * // On shutdown:
103
+ * unsubscribe()
104
+ * writer.close()
105
+ */
106
+ declare function createFileWriter(filePath: string, options?: FileWriterOptions): FileWriter;
107
+ //#endregion
108
+ export { TraceparentOptions as a, setIdFormat as c, IdFormat as i, setSampleRate as l, FileWriterOptions as n, getIdFormat as o, createFileWriter as r, getSampleRate as s, FileWriter as t, traceparent as u };
109
+ //# sourceMappingURL=file-writer-DtaY8Njt.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-writer-DtaY8Njt.d.mts","names":[],"sources":["../src/tracing.ts","../src/file-writer.ts"],"mappings":";;;;KAYY,QAAA;;;;;AAoBZ;;;iBATgB,WAAA,CAAY,MAAA,EAAQ,QAAA;;AAkDpC;;;;iBAzCgB,WAAA,CAAA,GAAe,QAAA;;UAyCd,kBAAA;EA4B2D;EA1B1E,OAAA;AAAA;;;;;AAyEF;;;;;;;;AC1IA;;;;;AAQA;;;;;;iBDmFgB,WAAA,CAAY,QAAA,EAAU,QAAA,EAAU,OAAA,GAAU,kBAAA;;;;ACvD1D;;;;iBD0FgB,aAAA,CAAc,IAAA;;;;;;iBAYd,aAAA,CAAA;;;;;;AAxIhB;;;;UCFiB,iBAAA;EDaD;ECXd,UAAA;;EAEA,aAAA;AAAA;ADkBF;AAAA,UCdiB,UAAA;;EAEf,KAAA,CAAM,IAAA;EDY+B;ECVrC,KAAA;EDmDiC;ECjDjC,KAAA;AAAA;;AD6EF;;;;;;;;;;AAmCA;;;;;AAYA;;;iBCtGgB,gBAAA,CAAiB,QAAA,UAAkB,OAAA,GAAS,iBAAA,GAAyB,UAAA"}
@@ -0,0 +1,10 @@
1
+ import { A as resetIds, B as withConfigMetrics, C as getCollectedSpans, D as getOutputMode, E as getLogLevel, F as setSuppressConsole, H as withSpans, I as setTraceFilter, L as spansAreEnabled, M as setLogFormat, N as setLogLevel, O as getTraceFilter, P as setOutputMode, R as startCollecting, S as enableSpans, T as getLogFormat, U as writeSpan, V as withEnvDefaults, _ as clearCollectedSpans, a as LoggerFactory, b as createTestLogger, c as PluginCtx, d as SpanRecord, f as SpanRecorder, g as baseCreateLogger, h as addWriter, i as Logger, j as setDebugFilter, k as pipe, l as SpanData, n as LazyMessage, o as LoggerPlugin, r as LazyProps, s as OutputMode, t as ConditionalLogger, u as SpanLogger, v as createLogger, w as getDebugFilter, x as disableSpans, z as stopCollecting } from "./core-Dm2PQUoS.mjs";
2
+ import { a as LOG_LEVEL_PRIORITY, c as LogLevel, d as SpanEvent, f as Stage, h as safeStringify, i as FileDescriptor, l as OutputLogLevel, m as buildPipeline, n as ConfigObject, o as LogEvent, p as Writable, r as Event, s as LogFormat, t as ConfigElement, u as Pipeline } from "./pipeline-Cl9-wCmt.mjs";
3
+ import { a as TraceparentOptions, c as setIdFormat, i as IdFormat, l as setSampleRate, n as FileWriterOptions, o as getIdFormat, s as getSampleRate, t as FileWriter, u as traceparent } from "./file-writer-DtaY8Njt.mjs";
4
+
5
+ //#region src/index.browser.d.ts
6
+ /** @throws Always — createFileWriter is not available in browser environments */
7
+ declare function createFileWriter(): never;
8
+ //#endregion
9
+ export { type ConditionalLogger, type ConfigElement, type ConfigObject, type Event, type FileDescriptor, type FileWriter, type FileWriterOptions, type IdFormat, LOG_LEVEL_PRIORITY, type LazyMessage, type LazyProps, type LogEvent, type LogFormat, type LogLevel, type Logger, type LoggerFactory, type LoggerPlugin, type OutputLogLevel, type OutputMode, type Pipeline, type PluginCtx, type SpanData, type SpanEvent, type SpanLogger, type SpanRecord, type SpanRecorder, type Stage, type TraceparentOptions, type Writable, addWriter, baseCreateLogger, buildPipeline, clearCollectedSpans, createFileWriter, createLogger, createTestLogger, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, pipe, resetIds, safeStringify, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, withConfigMetrics, withEnvDefaults, withSpans, writeSpan };
10
+ //# sourceMappingURL=index.browser.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.d.mts","names":[],"sources":["../src/index.browser.ts"],"mappings":";;;;;;iBA6FgB,gBAAA,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { A as withEnvDefaults, B as setSampleRate, C as setOutputMode, D as startCollecting, E as spansAreEnabled, F as safeStringify, L as getIdFormat, M as writeSpan, N as LOG_LEVEL_PRIORITY, O as stopCollecting, P as buildPipeline, R as getSampleRate, S as setLogLevel, T as setTraceFilter, V as traceparent, _ as getTraceFilter, a as baseCreateLogger, b as setDebugFilter, d as enableSpans, f as getCollectedSpans, g as getOutputMode, h as getLogLevel, i as addWriter, j as withSpans, k as withConfigMetrics, l as createTestLogger, m as getLogFormat, o as clearCollectedSpans, p as getDebugFilter, s as createLogger, u as disableSpans, v as pipe, w as setSuppressConsole, x as setLogFormat, y as resetIds, z as setIdFormat } from "./core-B3pox577.mjs";
2
+ //#region src/index.browser.ts
3
+ /** @throws Always — createFileWriter is not available in browser environments */
4
+ function createFileWriter() {
5
+ throw new Error("createFileWriter is not available in browser environments. Use a writable sink in the config array instead.");
6
+ }
7
+ //#endregion
8
+ export { LOG_LEVEL_PRIORITY, addWriter, baseCreateLogger, buildPipeline, clearCollectedSpans, createFileWriter, createLogger, createTestLogger, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, pipe, resetIds, safeStringify, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, withConfigMetrics, withEnvDefaults, withSpans, writeSpan };
9
+
10
+ //# sourceMappingURL=index.browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.mjs","names":[],"sources":["../src/index.browser.ts"],"sourcesContent":["/**\n * loggily v2 browser entry point.\n *\n * Re-exports the full logger API except createFileWriter (which requires node:fs).\n * Bundlers resolve this via the \"browser\" condition in package.json exports.\n */\n\nexport {\n // Core API\n createLogger,\n baseCreateLogger,\n createTestLogger,\n pipe,\n withSpans,\n withEnvDefaults,\n withConfigMetrics,\n type LoggerFactory,\n type LoggerPlugin,\n type PluginCtx,\n\n // Types\n type ConditionalLogger,\n type Logger,\n type SpanLogger,\n type SpanData,\n type LazyMessage,\n type LazyProps,\n type Event,\n type LogEvent,\n type SpanEvent,\n type Stage,\n type LogLevel,\n type OutputLogLevel,\n type LogFormat,\n type OutputMode,\n\n // Constants\n LOG_LEVEL_PRIORITY,\n\n // Utilities\n safeStringify,\n resetIds,\n\n // Span collection\n startCollecting,\n stopCollecting,\n getCollectedSpans,\n clearCollectedSpans,\n\n // Span metrics\n type SpanRecord,\n type SpanRecorder,\n\n // Deprecated v1 API (throws with migration instructions)\n setLogLevel,\n getLogLevel,\n enableSpans,\n disableSpans,\n spansAreEnabled,\n setTraceFilter,\n getTraceFilter,\n setDebugFilter,\n getDebugFilter,\n setLogFormat,\n getLogFormat,\n setSuppressConsole,\n setOutputMode,\n getOutputMode,\n addWriter,\n writeSpan,\n} from \"./core.js\"\n\n// Tracing utilities (runtime-agnostic, work in browser)\nexport {\n setIdFormat,\n getIdFormat,\n type IdFormat,\n traceparent,\n type TraceparentOptions,\n setSampleRate,\n getSampleRate,\n} from \"./tracing.js\"\n\n// Pipeline builder for power users\nexport { buildPipeline, type Pipeline } from \"./pipeline.js\"\n\n// Re-export config types for typed pipeline construction\nexport type { ConfigElement, ConfigObject, FileDescriptor, Writable } from \"./pipeline.js\"\n\n// File writer types (exported for type compatibility, but the function throws)\nexport type { FileWriterOptions, FileWriter } from \"./file-writer.js\"\n\n/** @throws Always — createFileWriter is not available in browser environments */\nexport function createFileWriter(): never {\n throw new Error(\n \"createFileWriter is not available in browser environments. Use a writable sink in the config array instead.\",\n )\n}\n"],"mappings":";;;AA6FA,SAAgB,mBAA0B;AACxC,OAAM,IAAI,MACR,8GACD"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
- import { A as setDebugFilter, B as Event, C as getCollectedSpans, D as getOutputMode, E as getLogLevel, F as setTraceFilter, G as OutputLogLevel, H as LogEvent, I as spansAreEnabled, J as Stage, K as Pipeline, L as startCollecting, M as setLogLevel, N as setOutputMode, O as getTraceFilter, P as setSuppressConsole, R as stopCollecting, S as enableSpans, T as getLogFormat, U as LogFormat, V as LOG_LEVEL_PRIORITY, W as LogLevel, X as defaultPipeline, Y as buildPipeline, Z as safeStringify, _ as clearCollectedSpans, a as LoggerFactory, b as createSpanDataProxy, c as SpanData, d as SpanRecorder, f as _ambientRecorder, g as addWriter, h as _setContextHooks, i as Logger, j as setLogFormat, k as resetIds, l as SpanLogger, m as _setAmbientRecorder, n as LazyMessage, o as LoggerPlugin, p as _clearContextHooks, q as SpanEvent, r as LazyProps, s as OutputMode, t as ConditionalLogger, u as SpanRecord, v as compose, w as getDebugFilter, x as disableSpans, y as createLogger, z as writeSpan } from "./core-DAFH-huv.mjs";
2
- import { a as setIdFormat, c as FileWriter, i as getSampleRate, l as FileWriterOptions, n as TraceparentOptions, o as setSampleRate, r as getIdFormat, s as traceparent, t as IdFormat, u as createFileWriter } from "./index-Co4jC3mx.mjs";
3
- export { ConditionalLogger, Event, FileWriter, FileWriterOptions, IdFormat, LOG_LEVEL_PRIORITY, LazyMessage, LazyProps, LogEvent, LogFormat, LogLevel, Logger, LoggerFactory, LoggerPlugin, OutputLogLevel, OutputMode, Pipeline, SpanData, SpanEvent, SpanLogger, SpanRecord, SpanRecorder, Stage, TraceparentOptions, _ambientRecorder, _clearContextHooks, _setAmbientRecorder, _setContextHooks, addWriter, buildPipeline, clearCollectedSpans, compose, createFileWriter, createLogger, createSpanDataProxy, defaultPipeline, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, resetIds, safeStringify, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, writeSpan };
1
+ import { A as resetIds, B as withConfigMetrics, C as getCollectedSpans, D as getOutputMode, E as getLogLevel, F as setSuppressConsole, H as withSpans, I as setTraceFilter, L as spansAreEnabled, M as setLogFormat, N as setLogLevel, O as getTraceFilter, P as setOutputMode, R as startCollecting, S as enableSpans, T as getLogFormat, U as writeSpan, V as withEnvDefaults, _ as clearCollectedSpans, a as LoggerFactory, b as createTestLogger, c as PluginCtx, d as SpanRecord, f as SpanRecorder, g as baseCreateLogger, h as addWriter, i as Logger, j as setDebugFilter, k as pipe, l as SpanData, m as _setContextHooks, n as LazyMessage, o as LoggerPlugin, p as _clearContextHooks, r as LazyProps, s as OutputMode, t as ConditionalLogger, u as SpanLogger, v as createLogger, w as getDebugFilter, x as disableSpans, y as createSpanDataProxy, z as stopCollecting } from "./core-Dm2PQUoS.mjs";
2
+ import { a as LOG_LEVEL_PRIORITY, c as LogLevel, d as SpanEvent, f as Stage, g as serializeCause, h as safeStringify, i as FileDescriptor, l as OutputLogLevel, m as buildPipeline, n as ConfigObject, o as LogEvent, p as Writable, r as Event, s as LogFormat, t as ConfigElement, u as Pipeline } from "./pipeline-Cl9-wCmt.mjs";
3
+ import { a as TraceparentOptions, c as setIdFormat, i as IdFormat, l as setSampleRate, n as FileWriterOptions, o as getIdFormat, r as createFileWriter, s as getSampleRate, t as FileWriter, u as traceparent } from "./file-writer-DtaY8Njt.mjs";
4
+ export { type ConditionalLogger, type ConfigElement, type ConfigObject, type Event, type FileDescriptor, type FileWriter, type FileWriterOptions, type IdFormat, LOG_LEVEL_PRIORITY, type LazyMessage, type LazyProps, type LogEvent, type LogFormat, type LogLevel, type Logger, type LoggerFactory, type LoggerPlugin, type OutputLogLevel, type OutputMode, type Pipeline, type PluginCtx, type SpanData, type SpanEvent, type SpanLogger, type SpanRecord, type SpanRecorder, type Stage, type TraceparentOptions, type Writable, _clearContextHooks, _setContextHooks, addWriter, baseCreateLogger, buildPipeline, clearCollectedSpans, createFileWriter, createLogger, createSpanDataProxy, createTestLogger, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, pipe, resetIds, safeStringify, serializeCause, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, withConfigMetrics, withEnvDefaults, withSpans, writeSpan };
package/dist/index.mjs CHANGED
@@ -1,2 +1,7 @@
1
- import { A as getSampleRate, C as setSuppressConsole, D as stopCollecting, E as startCollecting, F as buildPipeline, I as defaultPipeline, L as safeStringify, M as setSampleRate, N as traceparent, O as writeSpan, P as LOG_LEVEL_PRIORITY, R as createFileWriter, S as setOutputMode, T as spansAreEnabled, _ as getTraceFilter, a as addWriter, b as setLogFormat, c as createLogger, d as enableSpans, f as getCollectedSpans, g as getOutputMode, h as getLogLevel, i as _setContextHooks, j as setIdFormat, k as getIdFormat, l as createSpanDataProxy, m as getLogFormat, n as _clearContextHooks, o as clearCollectedSpans, p as getDebugFilter, r as _setAmbientRecorder, s as compose, t as _ambientRecorder, u as disableSpans, v as resetIds, w as setTraceFilter, x as setLogLevel, y as setDebugFilter } from "./core-Du3sIje6.mjs";
2
- export { LOG_LEVEL_PRIORITY, _ambientRecorder, _clearContextHooks, _setAmbientRecorder, _setContextHooks, addWriter, buildPipeline, clearCollectedSpans, compose, createFileWriter, createLogger, createSpanDataProxy, defaultPipeline, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, resetIds, safeStringify, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, writeSpan };
1
+ import { A as withEnvDefaults, B as setSampleRate, C as setOutputMode, D as startCollecting, E as spansAreEnabled, F as safeStringify, H as createFileWriter, I as serializeCause, L as getIdFormat, M as writeSpan, N as LOG_LEVEL_PRIORITY, O as stopCollecting, P as buildPipeline, R as getSampleRate, S as setLogLevel, T as setTraceFilter, V as traceparent, _ as getTraceFilter, a as baseCreateLogger, b as setDebugFilter, c as createSpanDataProxy, d as enableSpans, f as getCollectedSpans, g as getOutputMode, h as getLogLevel, i as addWriter, j as withSpans, k as withConfigMetrics, l as createTestLogger, m as getLogFormat, n as _setContextHooks, o as clearCollectedSpans, p as getDebugFilter, r as _setLogFileWriterFactory, s as createLogger, t as _clearContextHooks, u as disableSpans, v as pipe, w as setSuppressConsole, x as setLogFormat, y as resetIds, z as setIdFormat } from "./core-B3pox577.mjs";
2
+ //#region src/index.ts
3
+ _setLogFileWriterFactory(createFileWriter);
4
+ //#endregion
5
+ export { LOG_LEVEL_PRIORITY, _clearContextHooks, _setContextHooks, addWriter, baseCreateLogger, buildPipeline, clearCollectedSpans, createFileWriter, createLogger, createSpanDataProxy, createTestLogger, disableSpans, enableSpans, getCollectedSpans, getDebugFilter, getIdFormat, getLogFormat, getLogLevel, getOutputMode, getSampleRate, getTraceFilter, pipe, resetIds, safeStringify, serializeCause, setDebugFilter, setIdFormat, setLogFormat, setLogLevel, setOutputMode, setSampleRate, setSuppressConsole, setTraceFilter, spansAreEnabled, startCollecting, stopCollecting, traceparent, withConfigMetrics, withEnvDefaults, withSpans, writeSpan };
6
+
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["_cfw"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * loggily v2 — Structured logging with spans\n *\n * One import. Objects configure. Arrays branch. Values write.\n */\n\nexport {\n // Core API\n createLogger,\n baseCreateLogger,\n createTestLogger,\n pipe,\n type LoggerFactory,\n type LoggerPlugin,\n type PluginCtx,\n // Plugins\n withSpans,\n withEnvDefaults,\n withConfigMetrics,\n // Types\n type ConditionalLogger,\n type Logger,\n type SpanLogger,\n type SpanData,\n type LazyMessage,\n type LazyProps,\n type Event,\n type LogEvent,\n type SpanEvent,\n type Stage,\n type LogLevel,\n type OutputLogLevel,\n type LogFormat,\n type OutputMode,\n // Constants\n LOG_LEVEL_PRIORITY,\n // Utilities\n safeStringify,\n resetIds,\n // Span collection\n startCollecting,\n stopCollecting,\n getCollectedSpans,\n clearCollectedSpans,\n // Span metrics\n type SpanRecord,\n type SpanRecorder,\n // Internal (used by context.ts)\n _setContextHooks,\n _clearContextHooks,\n createSpanDataProxy,\n // Deprecated v1 API (maps to env vars for backwards compat)\n setLogLevel,\n getLogLevel,\n enableSpans,\n disableSpans,\n spansAreEnabled,\n setTraceFilter,\n getTraceFilter,\n setDebugFilter,\n getDebugFilter,\n setLogFormat,\n getLogFormat,\n setSuppressConsole,\n setOutputMode,\n getOutputMode,\n addWriter,\n writeSpan,\n} from \"./core.js\"\n\nexport { createFileWriter, type FileWriter, type FileWriterOptions } from \"./file-writer.js\"\n\n// Wire file writer into core for LOG_FILE env var support\nimport { createFileWriter as _cfw } from \"./file-writer.js\"\nimport { _setLogFileWriterFactory } from \"./core.js\"\n_setLogFileWriterFactory(_cfw)\n\nexport {\n setIdFormat,\n getIdFormat,\n type IdFormat,\n traceparent,\n type TraceparentOptions,\n setSampleRate,\n getSampleRate,\n} from \"./tracing.js\"\n\n// Re-export pipeline builder and utilities for power users\nexport { buildPipeline, type Pipeline, serializeCause } from \"./pipeline.js\"\n\n// Re-export config types for typed pipeline construction\nexport type { ConfigElement, ConfigObject, FileDescriptor, Writable } from \"./pipeline.js\"\n"],"mappings":";;AA2EA,yBAAyBA,iBAAK"}