@unhingged/logit 0.0.0-stage → 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ import {
2
+ CLEF_MEDIA_TYPE,
3
+ DEFAULT_DESTRUCTURING,
4
+ DEFAULT_OUTPUT_TEMPLATE,
5
+ LEVELS,
6
+ LEVEL_CODES,
7
+ LEVEL_NUMBERS,
8
+ LEVEL_ORDER,
9
+ LevelSwitch,
10
+ LogContext,
11
+ LogEvent,
12
+ Logger,
13
+ LoggerConfiguration,
14
+ Matching,
15
+ Operation,
16
+ SERILOG_LEVEL_NAMES,
17
+ ansi,
18
+ audit,
19
+ batchingSink,
20
+ byExcluding,
21
+ byIncludingOnly,
22
+ byTransforming,
23
+ callbackSink,
24
+ captureError,
25
+ captureProperty,
26
+ captureValue,
27
+ clefFormatter,
28
+ closeAndFlush,
29
+ conditional,
30
+ configure,
31
+ consoleSink,
32
+ createLogger,
33
+ detectColors,
34
+ diagnosticContext,
35
+ formatDate,
36
+ formatError,
37
+ formatLevel,
38
+ formatNumber,
39
+ fromLogContext,
40
+ httpSink,
41
+ isLevel,
42
+ isoTimestamp,
43
+ jsonFormatter,
44
+ jsonReplacer,
45
+ levelAtLeast,
46
+ log,
47
+ mapSink,
48
+ memorySink,
49
+ parseLevel,
50
+ parseTemplate,
51
+ prettyFormatter,
52
+ rateLimited,
53
+ renderTemplate,
54
+ renderValue,
55
+ resolveFormatter,
56
+ resolveLevel,
57
+ resolveStyles,
58
+ restricted,
59
+ sampled,
60
+ selfLog,
61
+ seqSink,
62
+ streamSink,
63
+ templateHash,
64
+ textFormatter,
65
+ toJson,
66
+ withComputed,
67
+ withEnvironment,
68
+ withProperties,
69
+ withProperty,
70
+ withTraceContext
71
+ } from "./chunk-GW7WQELF.js";
72
+ export {
73
+ CLEF_MEDIA_TYPE,
74
+ DEFAULT_DESTRUCTURING,
75
+ DEFAULT_OUTPUT_TEMPLATE,
76
+ LEVELS,
77
+ LEVEL_CODES,
78
+ LEVEL_NUMBERS,
79
+ LEVEL_ORDER,
80
+ LevelSwitch,
81
+ LogContext,
82
+ LogEvent,
83
+ Logger,
84
+ LoggerConfiguration,
85
+ Matching,
86
+ Operation,
87
+ SERILOG_LEVEL_NAMES,
88
+ ansi,
89
+ audit,
90
+ batchingSink,
91
+ byExcluding,
92
+ byIncludingOnly,
93
+ byTransforming,
94
+ callbackSink,
95
+ captureError,
96
+ captureProperty,
97
+ captureValue,
98
+ clefFormatter,
99
+ closeAndFlush,
100
+ conditional,
101
+ configure,
102
+ consoleSink,
103
+ createLogger,
104
+ detectColors,
105
+ diagnosticContext,
106
+ formatDate,
107
+ formatError,
108
+ formatLevel,
109
+ formatNumber,
110
+ fromLogContext,
111
+ httpSink,
112
+ isLevel,
113
+ isoTimestamp,
114
+ jsonFormatter,
115
+ jsonReplacer,
116
+ levelAtLeast,
117
+ log,
118
+ mapSink,
119
+ memorySink,
120
+ parseLevel,
121
+ parseTemplate,
122
+ prettyFormatter,
123
+ rateLimited,
124
+ renderTemplate,
125
+ renderValue,
126
+ resolveFormatter,
127
+ resolveLevel,
128
+ resolveStyles,
129
+ restricted,
130
+ sampled,
131
+ selfLog,
132
+ seqSink,
133
+ streamSink,
134
+ templateHash,
135
+ textFormatter,
136
+ toJson,
137
+ withComputed,
138
+ withEnvironment,
139
+ withProperties,
140
+ withProperty,
141
+ withTraceContext
142
+ };
143
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/next.cjs ADDED
@@ -0,0 +1,212 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkSKS54NHBcjs = require('./chunk-SKS54NHB.cjs');
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ var _chunk3FU7DTQEcjs = require('./chunk-3FU7DTQE.cjs');
76
+
77
+ // src/next.ts
78
+ var _async_hooks = require('async_hooks');
79
+ if (!_chunk3FU7DTQEcjs.LogContext.isAsync) _chunk3FU7DTQEcjs.LogContext.use(new (0, _async_hooks.AsyncLocalStorage)());
80
+ function withLogging(handler, options = {}) {
81
+ const logger = _nullishCoalesce(options.logger, () => ( _chunk3FU7DTQEcjs.log));
82
+ const wrapped = async (request, ...args) => {
83
+ const url = safeUrl(request.url);
84
+ const info = { method: request.method, path: _nullishCoalesce(_optionalChain([url, 'optionalAccess', _ => _.pathname]), () => ( request.url)), url: request.url, headers: request.headers };
85
+ if (_optionalChain([options, 'access', _2 => _2.ignore, 'optionalCall', _3 => _3(info)])) return handler(request, ...args);
86
+ return _chunkSKS54NHBcjs.runRequestScope.call(void 0, info, options, logger, async (scope) => {
87
+ try {
88
+ const response = await handler(request, ...args);
89
+ scope.complete(response instanceof Response ? response.status : 200);
90
+ return response;
91
+ } catch (error) {
92
+ scope.complete(statusOf(error), error);
93
+ throw error;
94
+ }
95
+ });
96
+ };
97
+ return wrapped;
98
+ }
99
+ function safeUrl(url) {
100
+ try {
101
+ return new URL(url);
102
+ } catch (e) {
103
+ return void 0;
104
+ }
105
+ }
106
+ function statusOf(error) {
107
+ const digest = _optionalChain([error, 'optionalAccess', _4 => _4.digest]);
108
+ if (typeof digest === "string") {
109
+ if (digest.startsWith("NEXT_REDIRECT")) {
110
+ const parts = digest.split(";");
111
+ const code = Number(parts[3]);
112
+ return Number.isFinite(code) ? code : 307;
113
+ }
114
+ if (digest === "NEXT_NOT_FOUND") return 404;
115
+ }
116
+ return 500;
117
+ }
118
+ function createOnRequestError(options = {}) {
119
+ const logger = (_nullishCoalesce(options.logger, () => ( _chunk3FU7DTQEcjs.log))).forSource(_nullishCoalesce(options.source, () => ( "next")));
120
+ const level = _nullishCoalesce(options.level, () => ( "error"));
121
+ return async (error, request, context) => {
122
+ const err = error instanceof Error ? error : new Error(String(error));
123
+ const digest = _optionalChain([error, 'optionalAccess', _5 => _5.digest]);
124
+ const target = logger.forContext({
125
+ RequestMethod: request.method,
126
+ RequestPath: request.path,
127
+ RouterKind: context.routerKind,
128
+ RouteType: context.routeType,
129
+ ...context.renderSource ? { RenderSource: context.renderSource } : {},
130
+ ...typeof digest === "string" ? { Digest: digest } : {}
131
+ });
132
+ target.write(level, err, "{RouteType:l} {RoutePath:l} failed", context.routeType, context.routePath);
133
+ if (_nullishCoalesce(options.flush, () => ( true))) await logger.flush();
134
+ };
135
+ }
136
+ var requestDiagnostics = _chunk3FU7DTQEcjs.diagnosticContext;
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ exports.CLEF_MEDIA_TYPE = _chunk3FU7DTQEcjs.CLEF_MEDIA_TYPE; exports.DEFAULT_DESTRUCTURING = _chunk3FU7DTQEcjs.DEFAULT_DESTRUCTURING; exports.DEFAULT_OUTPUT_TEMPLATE = _chunk3FU7DTQEcjs.DEFAULT_OUTPUT_TEMPLATE; exports.LEVELS = _chunk3FU7DTQEcjs.LEVELS; exports.LEVEL_CODES = _chunk3FU7DTQEcjs.LEVEL_CODES; exports.LEVEL_NUMBERS = _chunk3FU7DTQEcjs.LEVEL_NUMBERS; exports.LEVEL_ORDER = _chunk3FU7DTQEcjs.LEVEL_ORDER; exports.LevelSwitch = _chunk3FU7DTQEcjs.LevelSwitch; exports.LogContext = _chunk3FU7DTQEcjs.LogContext; exports.LogEvent = _chunk3FU7DTQEcjs.LogEvent; exports.Logger = _chunk3FU7DTQEcjs.Logger; exports.LoggerConfiguration = _chunk3FU7DTQEcjs.LoggerConfiguration; exports.Matching = _chunk3FU7DTQEcjs.Matching; exports.Operation = _chunk3FU7DTQEcjs.Operation; exports.REQUEST_COMPLETION_TEMPLATE = _chunkSKS54NHBcjs.REQUEST_COMPLETION_TEMPLATE; exports.SERILOG_LEVEL_NAMES = _chunk3FU7DTQEcjs.SERILOG_LEVEL_NAMES; exports.ansi = _chunk3FU7DTQEcjs.ansi; exports.audit = _chunk3FU7DTQEcjs.audit; exports.batchingSink = _chunk3FU7DTQEcjs.batchingSink; exports.byExcluding = _chunk3FU7DTQEcjs.byExcluding; exports.byIncludingOnly = _chunk3FU7DTQEcjs.byIncludingOnly; exports.byTransforming = _chunk3FU7DTQEcjs.byTransforming; exports.callbackSink = _chunk3FU7DTQEcjs.callbackSink; exports.captureError = _chunk3FU7DTQEcjs.captureError; exports.captureProperty = _chunk3FU7DTQEcjs.captureProperty; exports.captureValue = _chunk3FU7DTQEcjs.captureValue; exports.clefFormatter = _chunk3FU7DTQEcjs.clefFormatter; exports.closeAndFlush = _chunk3FU7DTQEcjs.closeAndFlush; exports.conditional = _chunk3FU7DTQEcjs.conditional; exports.configure = _chunk3FU7DTQEcjs.configure; exports.consoleSink = _chunk3FU7DTQEcjs.consoleSink; exports.createLogger = _chunk3FU7DTQEcjs.createLogger; exports.createOnRequestError = createOnRequestError; exports.detectColors = _chunk3FU7DTQEcjs.detectColors; exports.diagnosticContext = _chunk3FU7DTQEcjs.diagnosticContext; exports.formatDate = _chunk3FU7DTQEcjs.formatDate; exports.formatError = _chunk3FU7DTQEcjs.formatError; exports.formatLevel = _chunk3FU7DTQEcjs.formatLevel; exports.formatNumber = _chunk3FU7DTQEcjs.formatNumber; exports.fromLogContext = _chunk3FU7DTQEcjs.fromLogContext; exports.httpSink = _chunk3FU7DTQEcjs.httpSink; exports.isLevel = _chunk3FU7DTQEcjs.isLevel; exports.isoTimestamp = _chunk3FU7DTQEcjs.isoTimestamp; exports.jsonFormatter = _chunk3FU7DTQEcjs.jsonFormatter; exports.jsonReplacer = _chunk3FU7DTQEcjs.jsonReplacer; exports.levelAtLeast = _chunk3FU7DTQEcjs.levelAtLeast; exports.log = _chunk3FU7DTQEcjs.log; exports.mapSink = _chunk3FU7DTQEcjs.mapSink; exports.memorySink = _chunk3FU7DTQEcjs.memorySink; exports.parseLevel = _chunk3FU7DTQEcjs.parseLevel; exports.parseTemplate = _chunk3FU7DTQEcjs.parseTemplate; exports.prettyFormatter = _chunk3FU7DTQEcjs.prettyFormatter; exports.rateLimited = _chunk3FU7DTQEcjs.rateLimited; exports.renderTemplate = _chunk3FU7DTQEcjs.renderTemplate; exports.renderValue = _chunk3FU7DTQEcjs.renderValue; exports.requestDiagnostics = requestDiagnostics; exports.resolveFormatter = _chunk3FU7DTQEcjs.resolveFormatter; exports.resolveLevel = _chunk3FU7DTQEcjs.resolveLevel; exports.resolveStyles = _chunk3FU7DTQEcjs.resolveStyles; exports.restricted = _chunk3FU7DTQEcjs.restricted; exports.sampled = _chunk3FU7DTQEcjs.sampled; exports.selfLog = _chunk3FU7DTQEcjs.selfLog; exports.seqSink = _chunk3FU7DTQEcjs.seqSink; exports.streamSink = _chunk3FU7DTQEcjs.streamSink; exports.templateHash = _chunk3FU7DTQEcjs.templateHash; exports.textFormatter = _chunk3FU7DTQEcjs.textFormatter; exports.toJson = _chunk3FU7DTQEcjs.toJson; exports.withComputed = _chunk3FU7DTQEcjs.withComputed; exports.withEnvironment = _chunk3FU7DTQEcjs.withEnvironment; exports.withLogging = withLogging; exports.withProperties = _chunk3FU7DTQEcjs.withProperties; exports.withProperty = _chunk3FU7DTQEcjs.withProperty; exports.withTraceContext = _chunk3FU7DTQEcjs.withTraceContext;
212
+ //# sourceMappingURL=next.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/logit/logit/packages/logit/dist/next.cjs","../src/next.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC5DA,0CAAkC;AASlC,GAAA,CAAI,CAAC,4BAAA,CAAW,OAAA,EAAS,4BAAA,CAAW,GAAA,CAAI,IAAI,mCAAA,CAAkB,CAAC,CAAA;AAYxD,SAAS,WAAA,CACd,OAAA,EACA,QAAA,EAAiC,CAAC,CAAA,EACqB;AACvD,EAAA,MAAM,OAAA,mBAAS,OAAA,CAAQ,MAAA,UAAU,uBAAA;AACjC,EAA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AAA;AAAA,MACnB,GAAI,OAAA,CAAQ,aAAA,EAAe,EAAE,YAAA,EAAc,OAAA,CAAQ,aAAa,EAAA,EAAI,CAAC,CAAA;AAAA,MACrE,GAAI,OAAO,OAAA,IAAW,SAAA,EAAW,EAAE,MAAA,EAAQ,OAAO,EAAA,EAAI,CAAC;AAAA,IACzD,CAAC,CAAA;AACD,IAAA,MAAA,CAAO,KAAA,CAAM,KAAA,EAAO,GAAA,EAAK,oCAAA,EAAsC,OAAA,CAAQ,SAAA,EAAW,OAAA,CAAQ,SAAS,CAAA;AACnG,IAAA,GAAA,kBAAI,OAAA,CAAQ,KAAA,UAAS,MAAA,EAAM,MAAM,MAAA,CAAO,KAAA,CAAM,CAAA;AAAA,EAChD,CAAA;AACF;AAGO,IAAM,mBAAA,EAAqB,mCAAA;ADClC;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,o3HAAC","file":"/home/runner/work/logit/logit/packages/logit/dist/next.cjs","sourcesContent":[null,"/**\n * `@unhingged/logit/next` — Next.js in three places:\n *\n * instrumentation.ts `register()` configures the logger once per server\n * (behind a literal `process.env.NEXT_RUNTIME === 'nodejs'`\n * check, which Next inlines at build time so the Node-only\n * import is dropped from the edge bundle);\n * `onRequestError` logs every error Next catches.\n * middleware.ts `withLogging(middleware)` — ambient request context\n * and a completion event, on the edge runtime too.\n * route handlers `withLogging(handler)` — the same for `GET` / `POST`.\n * server actions `log.timed('Action createOrder', () => …)`.\n *\n * This entry imports only `node:async_hooks`, which Next.js provides in the\n * edge runtime as well, so it is safe in `middleware.ts`.\n */\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { LogContext, diagnosticContext } from './context';\nimport type { LogLevel } from './levels';\nimport { type Logger, log } from './logger';\nimport { type RequestLoggingOptions, runRequestScope } from './request';\n\nexport * from './index';\nexport { REQUEST_COMPLETION_TEMPLATE, type RequestLoggingOptions, type RequestInfo } from './request';\n\nif (!LogContext.isAsync) LogContext.use(new AsyncLocalStorage());\n\ntype HandlerResult = Response | void | Promise<Response | void>;\n\n/**\n * Wraps a route handler or `middleware` so that every request gets\n * `RequestId`, `RequestMethod` and `RequestPath` in the ambient context and\n * one completion event when it finishes. Errors are logged at `error` with\n * the request's facts and rethrown.\n *\n * export const GET = withLogging(async (request) => { … });\n */\nexport function withLogging<A extends unknown[], R extends HandlerResult>(\n handler: (request: Request, ...args: A) => R,\n options: RequestLoggingOptions = {},\n): (request: Request, ...args: A) => Promise<Awaited<R>> {\n const logger = options.logger ?? log;\n const wrapped = async (request: Request, ...args: A): Promise<unknown> => {\n const url = safeUrl(request.url);\n const info = { method: request.method, path: url?.pathname ?? request.url, url: request.url, headers: request.headers };\n if (options.ignore?.(info)) return handler(request, ...args);\n return runRequestScope(info, options, logger, async (scope) => {\n try {\n const response = await handler(request, ...args);\n scope.complete(response instanceof Response ? response.status : 200);\n return response;\n } catch (error) {\n scope.complete(statusOf(error), error);\n throw error;\n }\n });\n };\n return wrapped as (request: Request, ...args: A) => Promise<Awaited<R>>;\n}\n\nfunction safeUrl(url: string): URL | undefined {\n try {\n return new URL(url);\n } catch {\n return undefined;\n }\n}\n\n/** Next's `redirect()` / `notFound()` throw; they are not failures. */\nfunction statusOf(error: unknown): number {\n const digest = (error as { digest?: unknown })?.digest;\n if (typeof digest === 'string') {\n if (digest.startsWith('NEXT_REDIRECT')) {\n const parts = digest.split(';');\n const code = Number(parts[3]);\n return Number.isFinite(code) ? code : 307;\n }\n if (digest === 'NEXT_NOT_FOUND') return 404;\n }\n return 500;\n}\n\n/** The shape Next.js passes to `onRequestError` (kept structural so this package does not depend on `next`). */\nexport interface NextRequestErrorContext {\n routerKind: 'Pages Router' | 'App Router';\n routePath: string;\n routeType: 'render' | 'route' | 'action' | 'middleware';\n renderSource?: string;\n revalidateReason?: string;\n renderType?: string;\n}\n\nexport interface NextErrorRequest {\n path: string;\n method: string;\n headers: Record<string, string | string[] | undefined> | { get(name: string): string | null };\n}\n\nexport interface OnRequestErrorOptions {\n logger?: Logger;\n level?: LogLevel;\n source?: string;\n /** Flush the logger after each error (recommended on serverless, where the instance may freeze right after). Default true. */\n flush?: boolean;\n}\n\n/**\n * Builds the `onRequestError` export for `instrumentation.ts`:\n *\n * export const onRequestError = createOnRequestError();\n *\n * Logs the error with the route, the router kind and the request's facts.\n * Next may hand over a wrapped error during RSC rendering — the `digest` is\n * logged too, which is what identifies the original.\n */\nexport function createOnRequestError(options: OnRequestErrorOptions = {}) {\n const logger = (options.logger ?? log).forSource(options.source ?? 'next');\n const level = options.level ?? 'error';\n return async (error: unknown, request: NextErrorRequest, context: NextRequestErrorContext): Promise<void> => {\n const err = error instanceof Error ? error : new Error(String(error));\n const digest = (error as { digest?: unknown })?.digest;\n const target = logger.forContext({\n RequestMethod: request.method,\n RequestPath: request.path,\n RouterKind: context.routerKind,\n RouteType: context.routeType,\n ...(context.renderSource ? { RenderSource: context.renderSource } : {}),\n ...(typeof digest === 'string' ? { Digest: digest } : {}),\n });\n target.write(level, err, '{RouteType:l} {RoutePath:l} failed', context.routeType, context.routePath);\n if (options.flush ?? true) await logger.flush();\n };\n}\n\n/** `diagnosticContext.set()` re-exported under the name the Next docs use. */\nexport const requestDiagnostics = diagnosticContext;\n"]}
@@ -0,0 +1,55 @@
1
+ import { Logger, LogLevel } from './index.cjs';
2
+ export { BatchingOptions, BatchingSink, CLEF_MEDIA_TYPE, CapturedError, ClefFormatterOptions, ConsoleSinkOptions, ContextFrame, ContextHandle, ContextStore, DEFAULT_DESTRUCTURING, DEFAULT_OUTPUT_TEMPLATE, DestructuringOptions, DestructuringPolicy, Enricher, FetchLike, Filter, FormatName, Formatter, HoleToken, HttpSinkOptions, JsonFormatterOptions, LEVELS, LEVEL_CODES, LEVEL_NUMBERS, LEVEL_ORDER, LevelOrSwitch, LevelSwitch, LogContext, LogEvent, LogEventInit, LogMethod, LoggerConfiguration, LoggerOptions, MapSinkOptions, Matching, MemorySink, MessageTemplate, Operation, OperationOptions, PrettyFormatterOptions, RenderOptions, SERILOG_LEVEL_NAMES, SeqSinkOptions, Sink, SinkOptions, StreamLike, StreamSinkOptions, TemplateToken, TextFormatterOptions, TextToken, TraceContext, ValueStyles, ansi, audit, batchingSink, byExcluding, byIncludingOnly, byTransforming, callbackSink, captureError, captureProperty, captureValue, clefFormatter, closeAndFlush, conditional, configure, consoleSink, createLogger, detectColors, diagnosticContext, formatDate, formatError, formatLevel, formatNumber, fromLogContext, httpSink, isLevel, isoTimestamp, jsonFormatter, jsonReplacer, levelAtLeast, log, mapSink, memorySink, parseLevel, parseTemplate, prettyFormatter, rateLimited, renderTemplate, renderValue, resolveFormatter, resolveLevel, resolveStyles, restricted, sampled, selfLog, seqSink, streamSink, templateHash, textFormatter, toJson, withComputed, withEnvironment, withProperties, withProperty, withTraceContext } from './index.cjs';
3
+ import { R as RequestLoggingOptions } from './request-DrVrbDze.cjs';
4
+ export { a as REQUEST_COMPLETION_TEMPLATE, b as RequestInfo } from './request-DrVrbDze.cjs';
5
+
6
+ type HandlerResult = Response | void | Promise<Response | void>;
7
+ /**
8
+ * Wraps a route handler or `middleware` so that every request gets
9
+ * `RequestId`, `RequestMethod` and `RequestPath` in the ambient context and
10
+ * one completion event when it finishes. Errors are logged at `error` with
11
+ * the request's facts and rethrown.
12
+ *
13
+ * export const GET = withLogging(async (request) => { … });
14
+ */
15
+ declare function withLogging<A extends unknown[], R extends HandlerResult>(handler: (request: Request, ...args: A) => R, options?: RequestLoggingOptions): (request: Request, ...args: A) => Promise<Awaited<R>>;
16
+ /** The shape Next.js passes to `onRequestError` (kept structural so this package does not depend on `next`). */
17
+ interface NextRequestErrorContext {
18
+ routerKind: 'Pages Router' | 'App Router';
19
+ routePath: string;
20
+ routeType: 'render' | 'route' | 'action' | 'middleware';
21
+ renderSource?: string;
22
+ revalidateReason?: string;
23
+ renderType?: string;
24
+ }
25
+ interface NextErrorRequest {
26
+ path: string;
27
+ method: string;
28
+ headers: Record<string, string | string[] | undefined> | {
29
+ get(name: string): string | null;
30
+ };
31
+ }
32
+ interface OnRequestErrorOptions {
33
+ logger?: Logger;
34
+ level?: LogLevel;
35
+ source?: string;
36
+ /** Flush the logger after each error (recommended on serverless, where the instance may freeze right after). Default true. */
37
+ flush?: boolean;
38
+ }
39
+ /**
40
+ * Builds the `onRequestError` export for `instrumentation.ts`:
41
+ *
42
+ * export const onRequestError = createOnRequestError();
43
+ *
44
+ * Logs the error with the route, the router kind and the request's facts.
45
+ * Next may hand over a wrapped error during RSC rendering — the `digest` is
46
+ * logged too, which is what identifies the original.
47
+ */
48
+ declare function createOnRequestError(options?: OnRequestErrorOptions): (error: unknown, request: NextErrorRequest, context: NextRequestErrorContext) => Promise<void>;
49
+ /** `diagnosticContext.set()` re-exported under the name the Next docs use. */
50
+ declare const requestDiagnostics: {
51
+ set(name: string, value: unknown): void;
52
+ readonly active: boolean;
53
+ };
54
+
55
+ export { LogLevel, Logger, type NextErrorRequest, type NextRequestErrorContext, type OnRequestErrorOptions, RequestLoggingOptions, createOnRequestError, requestDiagnostics, withLogging };
package/dist/next.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { Logger, LogLevel } from './index.js';
2
+ export { BatchingOptions, BatchingSink, CLEF_MEDIA_TYPE, CapturedError, ClefFormatterOptions, ConsoleSinkOptions, ContextFrame, ContextHandle, ContextStore, DEFAULT_DESTRUCTURING, DEFAULT_OUTPUT_TEMPLATE, DestructuringOptions, DestructuringPolicy, Enricher, FetchLike, Filter, FormatName, Formatter, HoleToken, HttpSinkOptions, JsonFormatterOptions, LEVELS, LEVEL_CODES, LEVEL_NUMBERS, LEVEL_ORDER, LevelOrSwitch, LevelSwitch, LogContext, LogEvent, LogEventInit, LogMethod, LoggerConfiguration, LoggerOptions, MapSinkOptions, Matching, MemorySink, MessageTemplate, Operation, OperationOptions, PrettyFormatterOptions, RenderOptions, SERILOG_LEVEL_NAMES, SeqSinkOptions, Sink, SinkOptions, StreamLike, StreamSinkOptions, TemplateToken, TextFormatterOptions, TextToken, TraceContext, ValueStyles, ansi, audit, batchingSink, byExcluding, byIncludingOnly, byTransforming, callbackSink, captureError, captureProperty, captureValue, clefFormatter, closeAndFlush, conditional, configure, consoleSink, createLogger, detectColors, diagnosticContext, formatDate, formatError, formatLevel, formatNumber, fromLogContext, httpSink, isLevel, isoTimestamp, jsonFormatter, jsonReplacer, levelAtLeast, log, mapSink, memorySink, parseLevel, parseTemplate, prettyFormatter, rateLimited, renderTemplate, renderValue, resolveFormatter, resolveLevel, resolveStyles, restricted, sampled, selfLog, seqSink, streamSink, templateHash, textFormatter, toJson, withComputed, withEnvironment, withProperties, withProperty, withTraceContext } from './index.js';
3
+ import { R as RequestLoggingOptions } from './request-7cW3twuF.js';
4
+ export { a as REQUEST_COMPLETION_TEMPLATE, b as RequestInfo } from './request-7cW3twuF.js';
5
+
6
+ type HandlerResult = Response | void | Promise<Response | void>;
7
+ /**
8
+ * Wraps a route handler or `middleware` so that every request gets
9
+ * `RequestId`, `RequestMethod` and `RequestPath` in the ambient context and
10
+ * one completion event when it finishes. Errors are logged at `error` with
11
+ * the request's facts and rethrown.
12
+ *
13
+ * export const GET = withLogging(async (request) => { … });
14
+ */
15
+ declare function withLogging<A extends unknown[], R extends HandlerResult>(handler: (request: Request, ...args: A) => R, options?: RequestLoggingOptions): (request: Request, ...args: A) => Promise<Awaited<R>>;
16
+ /** The shape Next.js passes to `onRequestError` (kept structural so this package does not depend on `next`). */
17
+ interface NextRequestErrorContext {
18
+ routerKind: 'Pages Router' | 'App Router';
19
+ routePath: string;
20
+ routeType: 'render' | 'route' | 'action' | 'middleware';
21
+ renderSource?: string;
22
+ revalidateReason?: string;
23
+ renderType?: string;
24
+ }
25
+ interface NextErrorRequest {
26
+ path: string;
27
+ method: string;
28
+ headers: Record<string, string | string[] | undefined> | {
29
+ get(name: string): string | null;
30
+ };
31
+ }
32
+ interface OnRequestErrorOptions {
33
+ logger?: Logger;
34
+ level?: LogLevel;
35
+ source?: string;
36
+ /** Flush the logger after each error (recommended on serverless, where the instance may freeze right after). Default true. */
37
+ flush?: boolean;
38
+ }
39
+ /**
40
+ * Builds the `onRequestError` export for `instrumentation.ts`:
41
+ *
42
+ * export const onRequestError = createOnRequestError();
43
+ *
44
+ * Logs the error with the route, the router kind and the request's facts.
45
+ * Next may hand over a wrapped error during RSC rendering — the `digest` is
46
+ * logged too, which is what identifies the original.
47
+ */
48
+ declare function createOnRequestError(options?: OnRequestErrorOptions): (error: unknown, request: NextErrorRequest, context: NextRequestErrorContext) => Promise<void>;
49
+ /** `diagnosticContext.set()` re-exported under the name the Next docs use. */
50
+ declare const requestDiagnostics: {
51
+ set(name: string, value: unknown): void;
52
+ readonly active: boolean;
53
+ };
54
+
55
+ export { LogLevel, Logger, type NextErrorRequest, type NextRequestErrorContext, type OnRequestErrorOptions, RequestLoggingOptions, createOnRequestError, requestDiagnostics, withLogging };