loggily 0.6.0 → 0.6.1

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.
@@ -1,239 +0,0 @@
1
- //#region src/core.d.ts
2
- /**
3
- * loggily - Structured logging with spans
4
- *
5
- * Logger-first architecture: Span = Logger + Duration
6
- *
7
- * @example
8
- * const log = createLogger('myapp')
9
- *
10
- * // Simple logging
11
- * log.info('starting')
12
- *
13
- * // Lazy messages (function not called when level is disabled)
14
- * log.debug?.(() => `expensive: ${computeState()}`)
15
- *
16
- * // Child loggers with context fields
17
- * const reqLog = log.child({ requestId: 'abc' })
18
- * reqLog.info('handling request') // includes requestId in every message
19
- *
20
- * // With timing (span)
21
- * {
22
- * using task = log.span('import', { file: 'data.csv' })
23
- * task.info('importing')
24
- * task.spanData.count = 42 // Set span attributes
25
- * // Auto-disposal on block exit → SPAN myapp:import (15ms)
26
- * }
27
- */
28
- /** Data passed to span recorders on disposal */
29
- interface SpanRecord {
30
- readonly name: string;
31
- readonly durationMs: number;
32
- }
33
- /** Interface for span duration recording — implemented by createMetricsCollector() in metrics.ts */
34
- interface SpanRecorder {
35
- recordSpan(data: SpanRecord): void;
36
- }
37
- /**
38
- * Ambient span recorder — auto-records when TRACE is active.
39
- * Set by metrics.ts on import; can be replaced for testing.
40
- * @internal
41
- */
42
- declare let _ambientRecorder: SpanRecorder | null;
43
- declare function _setAmbientRecorder(recorder: SpanRecorder | null): void;
44
- /** Log levels that produce output */
45
- type OutputLogLevel = "trace" | "debug" | "info" | "warn" | "error";
46
- /** All log levels including silent (for filtering) */
47
- type LogLevel = OutputLogLevel | "silent";
48
- /** Message can be a string or a lazy function that returns a string */
49
- type LazyMessage = string | (() => string);
50
- /** Span props can be an object or a lazy function (skipped entirely via ?. when tracing is off) */
51
- type LazyProps = Record<string, unknown> | (() => Record<string, unknown>);
52
- /** Span data accessible via logger.spanData */
53
- interface SpanData {
54
- readonly id: string;
55
- readonly traceId: string;
56
- readonly parentId: string | null;
57
- readonly startTime: number;
58
- readonly endTime: number | null;
59
- readonly duration: number | null;
60
- /** Custom attributes - set via direct property assignment */
61
- [key: string]: unknown;
62
- }
63
- /** Logger interface */
64
- interface Logger {
65
- /** Logger namespace (e.g., 'myapp:import') */
66
- readonly name: string;
67
- /** Props inherited from parent + own props */
68
- readonly props: Readonly<Record<string, unknown>>;
69
- /** Span data (non-null for span loggers, null for regular loggers) */
70
- readonly spanData: SpanData | null;
71
- trace(message: LazyMessage, data?: Record<string, unknown>): void;
72
- debug(message: LazyMessage, data?: Record<string, unknown>): void;
73
- info(message: LazyMessage, data?: Record<string, unknown>): void;
74
- warn(message: LazyMessage, data?: Record<string, unknown>): void;
75
- error(message: LazyMessage, data?: Record<string, unknown>): void;
76
- /** Error overload - extracts message, stack, code from Error */
77
- error(error: Error, data?: Record<string, unknown>): void;
78
- /** Create child logger (extends namespace, inherits props) */
79
- logger(namespace?: string, props?: Record<string, unknown>): Logger;
80
- /** Create child span (extends namespace, inherits props, adds timing). Props can be lazy. */
81
- span(namespace?: string, props?: LazyProps): SpanLogger;
82
- /** Create child logger with context fields merged into every message */
83
- child(context: Record<string, unknown>): Logger;
84
- /** @deprecated Use .logger() instead for namespace-based children */
85
- child(context: string): Logger;
86
- /** End span manually (alternative to using keyword) */
87
- end(): void;
88
- }
89
- /** Span logger - Logger with active span (spanData is non-null, implements Disposable) */
90
- interface SpanLogger extends Logger, Disposable {
91
- readonly spanData: SpanData & {
92
- /** Mutable attributes - set directly */[key: string]: unknown;
93
- };
94
- }
95
- type LogWriter = (formatted: string, level: string) => void;
96
- /** Add a writer that receives all formatted log output. Returns unsubscribe. */
97
- declare function addWriter(writer: LogWriter): () => void;
98
- /** Suppress console output from the logger (writers still receive output). */
99
- declare function setSuppressConsole(value: boolean): void;
100
- /** Output mode for writeLog */
101
- type OutputMode = "console" | "stderr" | "writers-only";
102
- /** Set output mode for log messages (not spans — spans always use stderr). */
103
- declare function setOutputMode(mode: OutputMode): void;
104
- /** Get current output mode */
105
- declare function getOutputMode(): OutputMode;
106
- /** Set minimum log level */
107
- declare function setLogLevel(level: LogLevel): void;
108
- /** Get current log level */
109
- declare function getLogLevel(): LogLevel;
110
- /** Enable span output */
111
- declare function enableSpans(): void;
112
- /** Disable span output */
113
- declare function disableSpans(): void;
114
- /** Check if spans are enabled */
115
- declare function spansAreEnabled(): boolean;
116
- /**
117
- * Set trace filter for namespace-based span output control.
118
- * Only spans matching these namespace prefixes will be output.
119
- * @param namespaces - Array of namespace prefixes, or null to disable filtering
120
- */
121
- declare function setTraceFilter(namespaces: string[] | null): void;
122
- /** Get current trace filter (null means no filtering) */
123
- declare function getTraceFilter(): string[] | null;
124
- /**
125
- * Set debug namespace filter (like the `debug` npm package).
126
- * When set, only loggers matching these namespace prefixes produce output.
127
- * Supports negative patterns with `-` prefix (e.g., ["-km:noisy"]).
128
- * Also ensures log level is at least `debug`.
129
- * @param namespaces - Array of namespace prefixes (prefix with `-` to exclude), or null to disable
130
- */
131
- declare function setDebugFilter(namespaces: string[] | null): void;
132
- /** Get current debug namespace filter (null means no filtering) */
133
- declare function getDebugFilter(): string[] | null;
134
- /** Output format: human-readable console or structured JSON */
135
- type LogFormat = "console" | "json";
136
- /** Set log output format */
137
- declare function setLogFormat(format: LogFormat): void;
138
- /** Get current log output format */
139
- declare function getLogFormat(): LogFormat;
140
- declare function resetIds(): void;
141
- /**
142
- * Register context propagation hooks (called by context.ts).
143
- * @internal
144
- */
145
- declare function _setContextHooks(hooks: {
146
- getContextTags: () => Record<string, string>;
147
- getContextParent: () => {
148
- spanId: string;
149
- traceId: string;
150
- } | null;
151
- enterContext: (spanId: string, traceId: string, parentId: string | null) => void;
152
- exitContext: (spanId: string) => void;
153
- }): void;
154
- /**
155
- * Clear context propagation hooks (called by disableContextPropagation).
156
- * @internal
157
- */
158
- declare function _clearContextHooks(): void;
159
- declare function writeSpan(namespace: string, duration: number, attrs: Record<string, unknown>): void;
160
- interface SpanDataFields {
161
- id: string;
162
- traceId: string;
163
- parentId: string | null;
164
- startTime: number;
165
- endTime: number | null;
166
- duration: number | null;
167
- }
168
- /**
169
- * Create a proxy that exposes span metadata as readonly and custom attributes as writable.
170
- * Shared between core logger spans and worker logger spans.
171
- */
172
- declare function createSpanDataProxy(getFields: () => SpanDataFields, attrs: Record<string, unknown>): SpanData;
173
- /** Enable span collection for analysis */
174
- declare function startCollecting(): void;
175
- /** Stop collecting and return collected spans */
176
- declare function stopCollecting(): SpanData[];
177
- /** Get collected spans */
178
- declare function getCollectedSpans(): SpanData[];
179
- /** Clear collected spans */
180
- declare function clearCollectedSpans(): void;
181
- /**
182
- * Logger with optional methods — returns undefined for disabled levels.
183
- * Use with optional chaining: `log.debug?.("msg")` for zero-overhead when disabled.
184
- *
185
- * Defined as an explicit interface (not Omit<Logger,...>) so that
186
- * oxlint's type-aware mode can resolve it without advanced type inference.
187
- */
188
- interface ConditionalLogger {
189
- readonly name: string;
190
- readonly props: Readonly<Record<string, unknown>>;
191
- readonly spanData: SpanData | null;
192
- trace?: (message: LazyMessage, data?: Record<string, unknown>) => void;
193
- debug?: (message: LazyMessage, data?: Record<string, unknown>) => void;
194
- info?: (message: LazyMessage, data?: Record<string, unknown>) => void;
195
- warn?: (message: LazyMessage, data?: Record<string, unknown>) => void;
196
- error?: {
197
- (message: LazyMessage, data?: Record<string, unknown>): void;
198
- (error: Error, data?: Record<string, unknown>): void;
199
- };
200
- logger(namespace?: string, props?: Record<string, unknown>): Logger;
201
- span(namespace?: string, props?: LazyProps): SpanLogger;
202
- child(context: Record<string, unknown>): Logger;
203
- child(context: string): Logger;
204
- end(): void;
205
- }
206
- /**
207
- * Create a logger for a component.
208
- * Returns undefined for disabled levels - use with optional chaining for zero overhead.
209
- *
210
- * Log levels (most → least verbose): trace < debug < info < warn < error < silent
211
- * Default level: info (trace and debug disabled)
212
- *
213
- * @example
214
- * const log = createLogger('myapp')
215
- *
216
- * // All methods support ?. for zero-overhead when disabled
217
- * log.trace?.(`very verbose: ${expensiveDebug()}`) // Skipped at info level
218
- * log.debug?.(`debug: ${getState()}`) // Skipped at info level
219
- * log.info?.('starting') // Enabled at info level
220
- * log.warn?.('deprecated') // Enabled at info level
221
- * log.error?.('failed') // Enabled at info level
222
- *
223
- * // With -q flag or LOG_LEVEL=warn:
224
- * log.info?.('starting') // Now skipped - info < warn
225
- *
226
- * // With initial props
227
- * const log = createLogger('myapp', { version: '1.0' })
228
- *
229
- * // Create spans
230
- * {
231
- * using task = log.span('import', { file: 'data.csv' })
232
- * task.info?.('importing')
233
- * task.spanData.count = 42
234
- * }
235
- */
236
- declare function createLogger(name: string, props?: Record<string, unknown>): ConditionalLogger;
237
- //#endregion
238
- export { setDebugFilter as A, getCollectedSpans as C, getOutputMode as D, getLogLevel as E, setTraceFilter as F, spansAreEnabled as I, startCollecting as L, setLogLevel as M, setOutputMode as N, getTraceFilter as O, setSuppressConsole as P, stopCollecting as R, enableSpans as S, getLogFormat as T, addWriter as _, LogLevel as a, createSpanDataProxy as b, OutputMode as c, SpanRecord as d, SpanRecorder as f, _setContextHooks as g, _setAmbientRecorder as h, LogFormat as i, setLogFormat as j, resetIds as k, SpanData as l, _clearContextHooks as m, LazyMessage as n, Logger as o, _ambientRecorder as p, LazyProps as r, OutputLogLevel as s, ConditionalLogger as t, SpanLogger as u, clearCollectedSpans as v, getDebugFilter as w, disableSpans as x, createLogger as y, writeSpan as z };
239
- //# sourceMappingURL=core-7D7sstHl.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-7D7sstHl.d.mts","names":[],"sources":["../src/core.ts"],"mappings":";;AAgCA;;;;;AAMA;;;;;;;;;AASA;;;;;AACA;;;;;AA0BA;;UA1CiB,UAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA;AAAA;;UAIM,YAAA;EACf,UAAA,CAAW,IAAA,EAAM,UAAA;AAAA;AAyCnB;;;;;AAAA,YAjCW,gBAAA,EAAkB,YAAA;AAAA,iBACb,mBAAA,CAAoB,QAAA,EAAU,YAAA;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