@vsfedorenko/next-logger 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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +229 -0
  3. package/dist/browser.d.ts +41 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +47 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/config.d.ts +38 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +103 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/defaults.d.ts +31 -0
  12. package/dist/defaults.d.ts.map +1 -0
  13. package/dist/defaults.js +119 -0
  14. package/dist/defaults.js.map +1 -0
  15. package/dist/index.d.ts +87 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +100 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/logger.d.ts +21 -0
  20. package/dist/logger.d.ts.map +1 -0
  21. package/dist/logger.js +43 -0
  22. package/dist/logger.js.map +1 -0
  23. package/dist/patches/console.d.ts +38 -0
  24. package/dist/patches/console.d.ts.map +1 -0
  25. package/dist/patches/console.js +82 -0
  26. package/dist/patches/console.js.map +1 -0
  27. package/dist/patches/next.d.ts +42 -0
  28. package/dist/patches/next.d.ts.map +1 -0
  29. package/dist/patches/next.js +124 -0
  30. package/dist/patches/next.js.map +1 -0
  31. package/dist/patches/util.d.ts +25 -0
  32. package/dist/patches/util.d.ts.map +1 -0
  33. package/dist/patches/util.js +41 -0
  34. package/dist/patches/util.js.map +1 -0
  35. package/dist/presets/all.d.ts +14 -0
  36. package/dist/presets/all.d.ts.map +1 -0
  37. package/dist/presets/all.js +15 -0
  38. package/dist/presets/all.js.map +1 -0
  39. package/dist/presets/next-only.d.ts +12 -0
  40. package/dist/presets/next-only.d.ts.map +1 -0
  41. package/dist/presets/next-only.js +13 -0
  42. package/dist/presets/next-only.js.map +1 -0
  43. package/dist/reporters/json.d.ts +37 -0
  44. package/dist/reporters/json.d.ts.map +1 -0
  45. package/dist/reporters/json.js +160 -0
  46. package/dist/reporters/json.js.map +1 -0
  47. package/dist/reporters/sentry.d.ts +70 -0
  48. package/dist/reporters/sentry.d.ts.map +1 -0
  49. package/dist/reporters/sentry.js +152 -0
  50. package/dist/reporters/sentry.js.map +1 -0
  51. package/dist/types.d.ts +56 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +24 -0
  54. package/dist/types.js.map +1 -0
  55. package/package.json +101 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vadim Fedorenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # @vsfedorenko/next-logger
2
+
3
+ A **universal logging kit for Next.js**.
4
+
5
+ Monkeypatches Next.js' internal logger (`next/dist/build/output/log`) **and**
6
+ the global `console.*` so all diagnostic output flows through a single
7
+ level-controllable sink — [consola](https://github.com/unjs/consola) by default,
8
+ with pluggable reporters for **Sentry**, structured **JSON**, and more — without
9
+ a custom Next.js server.
10
+
11
+ Inspired by [`sainsburys-tech/next-logger`](https://github.com/sainsburys-tech/next-logger),
12
+ which does the same with [pino](https://getpino.io). This package swaps pino
13
+ for consola as the default backend and adds a reporter API so logs can be
14
+ fanned out to any integration (Sentry breadcrumbs, JSON aggregators, …).
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ bun add @vsfedorenko/next-logger consola
20
+ # or
21
+ npm install @vsfedorenko/next-logger consola
22
+ ```
23
+
24
+ `consola` is a peer dependency — install it alongside this package.
25
+
26
+ ## Usage
27
+
28
+ ### Option A — Instrumentation hook (recommended)
29
+
30
+ ```ts
31
+ // instrumentation.ts (project root)
32
+ export async function register() {
33
+ if (process.env.NEXT_RUNTIME === "nodejs") {
34
+ await import("@vsfedorenko/next-logger");
35
+ }
36
+ }
37
+ ```
38
+
39
+ The default import applies both patches: Next.js' logger **and** the global
40
+ `console.*`.
41
+
42
+ ### Option B — `-r` preload
43
+
44
+ ```sh
45
+ node -r @vsfedorenko/next-logger server.js
46
+ ```
47
+
48
+ ### Patch Next only (leave `console` untouched)
49
+
50
+ ```ts
51
+ // instrumentation.ts
52
+ export async function register() {
53
+ if (process.env.NEXT_RUNTIME === "nodejs") {
54
+ await import("@vsfedorenko/next-logger/presets/next-only");
55
+ }
56
+ }
57
+ ```
58
+
59
+ Useful when you want Next's internal logs routed through consola but prefer
60
+ native `console.*` formatting (e.g. in development).
61
+
62
+ ### Browser / Client Components
63
+
64
+ The main entry (`@vsfedorenko/next-logger`) imports the patch modules, which
65
+ depend on `require.cache` and `lilconfig` — neither exists in a browser bundle.
66
+ For Client Components or any browser-side code, use the
67
+ **`@vsfedorenko/next-logger/browser`** subpath:
68
+
69
+ ```ts
70
+ "use client";
71
+ import { logger } from "@vsfedorenko/next-logger/browser";
72
+
73
+ export function MyComponent() {
74
+ logger.info("rendered");
75
+ logger.warn("deprecation notice");
76
+ return <div>…</div>;
77
+ }
78
+ ```
79
+
80
+ This entry builds a consola instance from env-driven defaults (same level
81
+ resolution: `LOG_LEVEL` → `NEXT_PUBLIC_LOG_LEVEL` → `3`), without the
82
+ server-side patching machinery. For build-time-inlined levels visible in the
83
+ browser bundle, use `NEXT_PUBLIC_LOG_LEVEL`.
84
+
85
+ ## Configuration
86
+
87
+ Optional config file (discovered from cwd upward via
88
+ [lilconfig](https://github.com/antonk52/lilconfig)). Supported filenames:
89
+
90
+ - `next-logger.config.ts` / `next-logger.config.js` / `next-logger.config.cjs`
91
+ - `.next-loggerrc.ts` / `.next-loggerrc.js` / `.next-loggerrc.cjs`
92
+ - `.next-loggerrc` (JSON)
93
+ - `.next-loggerrc.json`
94
+ - `next-logger` key in `package.json`
95
+
96
+ **TypeScript configs** (`.ts`) are loaded via [jiti](https://github.com/unjs/jiti).
97
+ Install it as an optional peer dependency:
98
+
99
+ ```sh
100
+ bun add -d jiti # or: npm install -D jiti
101
+ ```
102
+
103
+ ### Custom consola instance
104
+
105
+ ```ts
106
+ // next-logger.config.ts
107
+ import { createConsola } from "consola";
108
+
109
+ export default {
110
+ consola: createConsola({ level: 4 }),
111
+ };
112
+ ```
113
+
114
+ ### Partial options (merged with defaults)
115
+
116
+ ```ts
117
+ import type { ConsolaOptions } from "consola";
118
+
119
+ export default {
120
+ consola: { level: 4, formatOptions: { date: false } } satisfies Partial<ConsolaOptions>,
121
+ };
122
+ ```
123
+
124
+ ### Factory (receives the library defaults)
125
+
126
+ ```ts
127
+ import type { ConsolaOptions } from "consola";
128
+ import { createConsola } from "consola";
129
+
130
+ export default {
131
+ consola: (defaults: Partial<ConsolaOptions>) =>
132
+ createConsola({ ...defaults, level: 5 }),
133
+ };
134
+ ```
135
+
136
+ ## Log level
137
+
138
+ Without a config file, the level resolves from (in order):
139
+
140
+ 1. `LOG_LEVEL` (numeric or named)
141
+ 2. `NEXT_PUBLIC_LOG_LEVEL` (numeric or named)
142
+
143
+ Falling back to `3` (info).
144
+
145
+ Named levels: `silent` (-∞), `fatal` (0), `error` (0), `warn` (1),
146
+ `log` (2), `info` (3), `success` (3), `debug` (4), `trace` (5), `verbose` (∞).
147
+
148
+ ## Log format
149
+
150
+ Server-side output format, controlled by env var:
151
+
152
+ 1. `LOG_FORMAT` (`text` or `json`)
153
+ 2. `NEXT_PUBLIC_LOG_FORMAT` (same values)
154
+
155
+ Falling back to `text` (consola's default pretty reporter).
156
+
157
+ ### `text` (default)
158
+
159
+ Human-readable, coloured in TTY, with timestamps — consola's built-in reporter.
160
+ Best for local development.
161
+
162
+ ### `json`
163
+
164
+ Newline-delimited JSON to stdout (errors → stderr), suitable for structured-log
165
+ aggregators (Loki, Datadog, CloudWatch, Elasticsearch). Best for production.
166
+
167
+ ```json
168
+ {"level":"error","type":"error","tag":"next.js","msg":"failed to compile","date":"2026-07-11T13:43:10.712Z"}
169
+ ```
170
+
171
+ Each line contains:
172
+
173
+ | Field | Description |
174
+ |---------|------------------------------------------------------------------------------|
175
+ | `level` | Named level (`error`/`warn`/`info`/`debug`/`trace`) |
176
+ | `type` | Consola log type (e.g. `error`, `warn`, `info`, `success`, `ready`, `event`) |
177
+ | `tag` | The consola tag (`next.js`, `console`, `app`, …) |
178
+ | `msg` | The message string (multi-arg strings joined with space) |
179
+ | `date` | ISO 8601 timestamp |
180
+ | `args` | Additional structured arguments (omitted when none) |
181
+
182
+ Errors are serialised as `{ name, message, stack }`. Circular references become
183
+ `[Circular]`. BigInts become strings.
184
+
185
+ Only applies to the server entry (`@vsfedorenko/next-logger`) — the browser
186
+ entry always uses consola's built-in browser reporter. A custom consola instance
187
+ from a config file bypasses format selection entirely.
188
+
189
+ ## How it works
190
+
191
+ 1. **Next.js logger patch** (`patches/next.ts`) — replaces the methods exported
192
+ by `next/dist/build/output/log` (`wait`, `error`, `warn`, `ready`, `info`,
193
+ `event`, `trace`) with bound consola methods tagged `next.js`. Preserves the
194
+ critical Next 13+ workaround: since Next defines these exports as
195
+ non-configurable accessors, the patch replaces `require.cache[...].exports`
196
+ with a shallow copy, then redefines each method on the copy.
197
+
198
+ 2. **Console patch** (`patches/console.ts`) — overwrites
199
+ `console.{log,debug,info,warn,error}` with bound consola methods tagged
200
+ `console`. `log` and `info` both map to consola `info`.
201
+
202
+ Both patches share a single consola instance built by `logger.ts`, so the log
203
+ level is controllable from one place.
204
+
205
+ ### Empty-message skipping
206
+
207
+ Both patches skip printing when a message is **empty** — no arguments, or only
208
+ `undefined`/`null`/`""` (values that carry no diagnostic value and would render
209
+ as a bare tag line under consola). This mirrors Next.js' own behaviour, where
210
+ `prefixedLog` drops the prefix when the message is empty.
211
+
212
+ Falsy-but-present values (`0`, `false`) are **not** considered empty and are
213
+ printed normally.
214
+
215
+ ## Differences from `sainsburys-tech/next-logger`
216
+
217
+ | Concern | sainsburys-tech (pino) | this package (consola) |
218
+ |-------------------|-----------------------------------------------|-------------------------------------------------|
219
+ | Backend | pino (JSON to stdout) | consola (pretty by default) |
220
+ | Arg normalisation | custom `hooks.logMethod` | not needed — consola handles console-style args |
221
+ | Child logger | `logger.child({ name })` | `consola.withTag(tag)` |
222
+ | Custom backend | any logger with `.child()` (pino, winston, …) | consola instances / options only |
223
+ | `trace` level | falls back to `debug` (Winston has no trace) | native — consola has `trace` |
224
+ | Default level | hardcoded `debug` | env-driven (`LOG_LEVEL`) |
225
+ | Language | plain JS (CommonJS) | TypeScript (CJS output) |
226
+
227
+ ## License
228
+
229
+ MIT
@@ -0,0 +1,41 @@
1
+ /**
2
+ * # @vsfedorenko/next-logger/browser
3
+ *
4
+ * Browser-safe entry — exports a consola instance built from env-driven
5
+ * defaults, WITHOUT the server-side patching machinery.
6
+ *
7
+ * Use this from Client Components or any browser code:
8
+ *
9
+ * ```ts
10
+ * import { logger } from "@vsfedorenko/next-logger/browser";
11
+ *
12
+ * logger.info("hello from the browser");
13
+ * logger.warn("deprecation notice");
14
+ * ```
15
+ *
16
+ * ## Why a separate entry?
17
+ *
18
+ * The main entry (`@vsfedorenko/next-logger`) imports the patch modules, which
19
+ * depend on `require.cache` and `lilconfig` (filesystem) — neither of which
20
+ * exists in a browser bundle. This entry skips those entirely and builds the
21
+ * consola instance directly from {@link defaultConsolaOptions}.
22
+ *
23
+ * ## Level resolution
24
+ *
25
+ * Same as the server entry: `LOG_LEVEL` → `NEXT_PUBLIC_LOG_LEVEL` → `3` (info).
26
+ * For values inlined at build time (visible in the browser bundle), use
27
+ * `NEXT_PUBLIC_LOG_LEVEL`.
28
+ */
29
+ /**
30
+ * The shared consola instance for browser use.
31
+ *
32
+ * Built once from {@link defaultConsolaOptions}. Unlike the server entry, there
33
+ * is no config-file discovery (the browser has no filesystem). Override the
34
+ * level at runtime via `logger.level = N`.
35
+ */
36
+ export declare const logger: import("consola").ConsolaInstance;
37
+ export { defaultConsolaOptions } from "./defaults";
38
+ export { isEmptyMessage, skipEmpty } from "./patches/util";
39
+ export type { LogFunction, NextLogFn } from "./types";
40
+ export type { ConsolaInstance, ConsolaOptions, FormatOptions, LogLevel, LogObject, LogType, } from "consola";
41
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAKH;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,mCAAuC,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3D,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACtD,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,OAAO,GACR,MAAM,SAAS,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * # @vsfedorenko/next-logger/browser
4
+ *
5
+ * Browser-safe entry — exports a consola instance built from env-driven
6
+ * defaults, WITHOUT the server-side patching machinery.
7
+ *
8
+ * Use this from Client Components or any browser code:
9
+ *
10
+ * ```ts
11
+ * import { logger } from "@vsfedorenko/next-logger/browser";
12
+ *
13
+ * logger.info("hello from the browser");
14
+ * logger.warn("deprecation notice");
15
+ * ```
16
+ *
17
+ * ## Why a separate entry?
18
+ *
19
+ * The main entry (`@vsfedorenko/next-logger`) imports the patch modules, which
20
+ * depend on `require.cache` and `lilconfig` (filesystem) — neither of which
21
+ * exists in a browser bundle. This entry skips those entirely and builds the
22
+ * consola instance directly from {@link defaultConsolaOptions}.
23
+ *
24
+ * ## Level resolution
25
+ *
26
+ * Same as the server entry: `LOG_LEVEL` → `NEXT_PUBLIC_LOG_LEVEL` → `3` (info).
27
+ * For values inlined at build time (visible in the browser bundle), use
28
+ * `NEXT_PUBLIC_LOG_LEVEL`.
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.skipEmpty = exports.isEmptyMessage = exports.defaultConsolaOptions = exports.logger = void 0;
32
+ const consola_1 = require("consola");
33
+ const defaults_1 = require("./defaults");
34
+ /**
35
+ * The shared consola instance for browser use.
36
+ *
37
+ * Built once from {@link defaultConsolaOptions}. Unlike the server entry, there
38
+ * is no config-file discovery (the browser has no filesystem). Override the
39
+ * level at runtime via `logger.level = N`.
40
+ */
41
+ exports.logger = (0, consola_1.createConsola)(defaults_1.defaultConsolaOptions);
42
+ var defaults_2 = require("./defaults");
43
+ Object.defineProperty(exports, "defaultConsolaOptions", { enumerable: true, get: function () { return defaults_2.defaultConsolaOptions; } });
44
+ var util_1 = require("./patches/util");
45
+ Object.defineProperty(exports, "isEmptyMessage", { enumerable: true, get: function () { return util_1.isEmptyMessage; } });
46
+ Object.defineProperty(exports, "skipEmpty", { enumerable: true, get: function () { return util_1.skipEmpty; } });
47
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAEH,qCAAwC;AACxC,yCAAmD;AAEnD;;;;;;GAMG;AACU,QAAA,MAAM,GAAG,IAAA,uBAAa,EAAC,gCAAqB,CAAC,CAAC;AAE3D,uCAAmD;AAA1C,iHAAA,qBAAqB,OAAA;AAC9B,uCAA2D;AAAlD,sGAAA,cAAc,OAAA;AAAE,iGAAA,SAAS,OAAA"}
@@ -0,0 +1,38 @@
1
+ import type { ConsolaInstance, ConsolaOptions } from "consola";
2
+ /**
3
+ * Shape of a `next-logger.config.{js,ts,cjs}` file.
4
+ *
5
+ * The `consola` key may be:
6
+ * - a {@link ConsolaInstance} (complete custom backend — used directly), or
7
+ * - a partial {@link ConsolaOptions} object merged on top of the defaults, or
8
+ * - a factory `(defaults) => ConsolaInstance` (full control, receives the
9
+ * library's default options as a starting point).
10
+ */
11
+ export interface NextLoggerConfig {
12
+ consola?: ConsolaInstance | Partial<ConsolaOptions> | ((defaults: Partial<ConsolaOptions>) => ConsolaInstance);
13
+ }
14
+ /**
15
+ * Discriminated result of config discovery.
16
+ *
17
+ * - `kind: "instance"` — the config supplied a consola instance or a factory
18
+ * that produced one; use it directly.
19
+ * - `kind: "options"` — the config supplied a partial options object (or no
20
+ * config at all); build a consola from these merged options.
21
+ */
22
+ export type ResolvedConfig = {
23
+ readonly kind: "instance";
24
+ readonly instance: ConsolaInstance;
25
+ } | {
26
+ readonly kind: "options";
27
+ readonly options: Partial<ConsolaOptions>;
28
+ };
29
+ /**
30
+ * Searches for `next-logger.config.{ts,js,cjs,...}` from cwd upward.
31
+ *
32
+ * Always returns a value: either a built consola instance (when the config
33
+ * supplied one or a factory) or the options object to build from (the config's
34
+ * partial options merged with defaults, or the bare defaults when no config
35
+ * exists).
36
+ */
37
+ export declare function loadConfig(): ResolvedConfig;
38
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA+C/D;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EACJ,eAAe,GACf,OAAO,CAAC,cAAc,CAAC,GACvB,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,KAAK,eAAe,CAAC,CAAC;CAC9D;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAAE,CAAC;AAE5E;;;;;;;GAOG;AACH,wBAAgB,UAAU,IAAI,cAAc,CA0C3C"}
package/dist/config.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadConfig = loadConfig;
4
+ const lilconfig_1 = require("lilconfig");
5
+ const defaults_1 = require("./defaults");
6
+ const types_1 = require("./types");
7
+ /**
8
+ * Loader for `.ts` config files.
9
+ *
10
+ * Uses `jiti` when available (the standard transpile-on-require used by
11
+ * Nuxt/consola/tailwind). `jiti` is an optional peer dependency — when absent,
12
+ * a clear error is thrown pointing to the missing package.
13
+ *
14
+ * Lazily required so the default path (no `.ts` config) never pays the jiti
15
+ * import cost.
16
+ */
17
+ const tsLoader = (filepath) => {
18
+ const jiti = tryRequireJiti();
19
+ if (jiti === null) {
20
+ throw new Error(`next-logger: cannot load TypeScript config "${filepath}" — install "jiti" (optional peer dependency).`);
21
+ }
22
+ return jiti(filepath);
23
+ };
24
+ /**
25
+ * Resolves the `jiti` callable if installed, or returns `null`.
26
+ *
27
+ * `jiti` v2 exports `createJiti`; the returned {@link Jiti} instance extends
28
+ * `NodeRequire`, so it is directly callable as `jiti(filepath)`.
29
+ */
30
+ function tryRequireJiti() {
31
+ try {
32
+ const mod = require("jiti");
33
+ const jiti = mod.createJiti(__filename);
34
+ return jiti;
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ // Only register a loader for `.ts`; lilconfig's `defaultLoadersSync` handles
41
+ // `.js`/`.cjs`/`.json` natively via `require(filepath)` / `JSON.parse`.
42
+ const loaders = {
43
+ ...lilconfig_1.defaultLoadersSync,
44
+ ".ts": tsLoader,
45
+ };
46
+ /**
47
+ * Searches for `next-logger.config.{ts,js,cjs,...}` from cwd upward.
48
+ *
49
+ * Always returns a value: either a built consola instance (when the config
50
+ * supplied one or a factory) or the options object to build from (the config's
51
+ * partial options merged with defaults, or the bare defaults when no config
52
+ * exists).
53
+ */
54
+ function loadConfig() {
55
+ const explorer = (0, lilconfig_1.lilconfigSync)("next-logger", {
56
+ searchPlaces: [
57
+ "next-logger.config.ts",
58
+ "next-logger.config.js",
59
+ "next-logger.config.cjs",
60
+ ".next-loggerrc.ts",
61
+ ".next-loggerrc.js",
62
+ ".next-loggerrc.cjs",
63
+ ".next-loggerrc",
64
+ ".next-loggerrc.json",
65
+ "package.json",
66
+ ],
67
+ loaders,
68
+ });
69
+ const result = explorer.search();
70
+ const raw = result?.config;
71
+ const def = raw?.consola;
72
+ // No config, or config without a `consola` key → bare defaults.
73
+ if (def == null) {
74
+ return { kind: "options", options: defaults_1.defaultConsolaOptions };
75
+ }
76
+ // Factory — caller receives the library defaults, returns a consola.
77
+ if (typeof def === "function") {
78
+ const factory = def;
79
+ return { kind: "instance", instance: factory(defaults_1.defaultConsolaOptions) };
80
+ }
81
+ // Consola instance — use as-is (type guard narrows safely).
82
+ if ((0, types_1.isConsolaInstance)(def)) {
83
+ return { kind: "instance", instance: def };
84
+ }
85
+ // Partial options object — merge with defaults (formatOptions nested).
86
+ const extra = def;
87
+ return {
88
+ kind: "options",
89
+ options: mergeOptions(extra),
90
+ };
91
+ }
92
+ /** Merges a partial options object with the library defaults. */
93
+ function mergeOptions(extra) {
94
+ return {
95
+ ...defaults_1.defaultConsolaOptions,
96
+ ...extra,
97
+ formatOptions: {
98
+ ...defaults_1.defaultConsolaOptions.formatOptions,
99
+ ...extra.formatOptions,
100
+ },
101
+ };
102
+ }
103
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAoFA,gCA0CC;AA9HD,yCAA+E;AAE/E,yCAAmD;AACnD,mCAA4C;AAE5C;;;;;;;;;GASG;AACH,MAAM,QAAQ,GAAe,CAAC,QAAgB,EAAW,EAAE;IACzD,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,+CAA+C,QAAQ,gDAAgD,CACxG,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAA0B,CAAC;QACrD,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,IAA0C,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,6EAA6E;AAC7E,wEAAwE;AACxE,MAAM,OAAO,GAA+B;IAC1C,GAAG,8BAAkB;IACrB,KAAK,EAAE,QAAQ;CAChB,CAAC;AA8BF;;;;;;;GAOG;AACH,SAAgB,UAAU;IACxB,MAAM,QAAQ,GAAG,IAAA,yBAAa,EAAC,aAAa,EAAE;QAC5C,YAAY,EAAE;YACZ,uBAAuB;YACvB,uBAAuB;YACvB,wBAAwB;YACxB,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+ /**
4
+ * Supported log output formats.
5
+ *
6
+ * - `text` — consola's default pretty reporter (human-readable, coloured in TTY).
7
+ * - `json` — newline-delimited JSON to stdout/stderr (structured logging).
8
+ *
9
+ * Server-only; the browser entry always uses consola's built-in browser reporter.
10
+ */
11
+ export type LogFormat = "text" | "json";
12
+ /**
13
+ * Resolves the log format from the environment.
14
+ *
15
+ * Priority: `LOG_FORMAT` → `NEXT_PUBLIC_LOG_FORMAT` → `text`.
16
+ *
17
+ * Accepts `text`/`json` (case-insensitive). Unknown values fall back to `text`.
18
+ */
19
+ export declare function resolveFormat(): LogFormat;
20
+ /**
21
+ * Default consola options for the patched loggers.
22
+ *
23
+ * Unlike the pino original, consola already normalises console-style multi-arg
24
+ * signatures (strings, objects, errors, mixed), so there is no need for a
25
+ * `logMethod` hook. The level is env-driven instead of hardcoded.
26
+ *
27
+ * `colors` is intentionally omitted — consola auto-detects TTY and `CI`
28
+ * internally, so duplicating that logic here would be fragile.
29
+ */
30
+ export declare const defaultConsolaOptions: Readonly<Partial<ConsolaOptions>>;
31
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAyBtF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAaxD,CAAC;AAoDL;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,SAAS,CAIzC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAMnE,CAAC"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultConsolaOptions = exports.LEVEL_TO_NAME = void 0;
4
+ exports.resolveFormat = resolveFormat;
5
+ const consola_1 = require("consola");
6
+ /**
7
+ * Reverse lookup: consola numeric level → canonical name.
8
+ *
9
+ * Built by inverting consola's exported `LogLevels` (`Record<LogType, number>`),
10
+ * so this is always in sync with the actual library — no hand-rolled map that
11
+ * can drift. Multiple `LogType` values share the same numeric level (e.g.
12
+ * `fatal`/`error` → `0`, `info`/`success`/`ready`/`start`/`box` → `3`).
13
+ *
14
+ * When multiple names share a level, a priority list picks the most
15
+ * universally understood name (e.g. `"error"` over `"fatal"` for level `0`,
16
+ * `"info"` over `"success"`/`"ready"` etc. for level `3`).
17
+ */
18
+ const PREFERRED_NAMES = [
19
+ "silent",
20
+ "error", // preferred over "fatal" for level 0
21
+ "warn",
22
+ "log",
23
+ "info", // preferred over "success"/"fail"/"ready"/"start"/"box" for level 3
24
+ "debug",
25
+ "trace",
26
+ "verbose",
27
+ ];
28
+ exports.LEVEL_TO_NAME = (() => {
29
+ const inv = {};
30
+ // First pass: populate from PREFERRED_NAMES in priority order.
31
+ for (const name of PREFERRED_NAMES) {
32
+ const level = consola_1.LogLevels[name];
33
+ if (!(level in inv))
34
+ inv[level] = name;
35
+ }
36
+ // Second pass: fill any remaining levels from LogLevels (e.g. -Infinity for
37
+ // "silent" is already covered, but this catches edge cases).
38
+ for (const [name, level] of Object.entries(consola_1.LogLevels)) {
39
+ if (!(level in inv))
40
+ inv[level] = name;
41
+ }
42
+ return inv;
43
+ })();
44
+ /**
45
+ * Forward lookup: canonical name → consola numeric level.
46
+ *
47
+ * Directly derived from `LogLevels` — the authoritative source.
48
+ */
49
+ const NAME_TO_LEVEL = Object.fromEntries(Object.entries(consola_1.LogLevels));
50
+ /**
51
+ * Clamps an arbitrary number to consola's finite numeric level range `[0, 5]`.
52
+ *
53
+ * `-Infinity` (silent) and `Infinity` (verbose) are consola's sentinels; we
54
+ * collapse them to `0` and `5` respectively for env-var-driven configuration
55
+ * (users typing `LOG_LEVEL=999` get `5` = trace, not an unbounded value).
56
+ */
57
+ function clampLevel(n) {
58
+ if (n <= 0)
59
+ return 0;
60
+ if (n >= 5)
61
+ return 5;
62
+ return Math.floor(n);
63
+ }
64
+ /**
65
+ * Resolves the default log level from the environment.
66
+ *
67
+ * Priority: `process.env.LOG_LEVEL` (numeric or named) →
68
+ * `process.env.NEXT_PUBLIC_LOG_LEVEL` (same rules; useful when the value must
69
+ * be inlined at build time) → `3` (info).
70
+ *
71
+ * Named values are resolved against consola's canonical `LogLevels` map.
72
+ * Numeric values are clamped to `[0, 5]`.
73
+ */
74
+ function resolveLevel() {
75
+ for (const raw of [process.env.LOG_LEVEL, process.env.NEXT_PUBLIC_LOG_LEVEL]) {
76
+ if (raw === undefined || raw === "")
77
+ continue;
78
+ const numeric = Number(raw);
79
+ if (!Number.isNaN(numeric)) {
80
+ return clampLevel(numeric);
81
+ }
82
+ const mapped = NAME_TO_LEVEL[raw.toLowerCase()];
83
+ if (mapped !== undefined) {
84
+ return mapped;
85
+ }
86
+ }
87
+ return 3; // info
88
+ }
89
+ /**
90
+ * Resolves the log format from the environment.
91
+ *
92
+ * Priority: `LOG_FORMAT` → `NEXT_PUBLIC_LOG_FORMAT` → `text`.
93
+ *
94
+ * Accepts `text`/`json` (case-insensitive). Unknown values fall back to `text`.
95
+ */
96
+ function resolveFormat() {
97
+ const raw = process.env.LOG_FORMAT ?? process.env.NEXT_PUBLIC_LOG_FORMAT;
98
+ if (raw === undefined || raw === "")
99
+ return "text";
100
+ return raw.toLowerCase() === "json" ? "json" : "text";
101
+ }
102
+ /**
103
+ * Default consola options for the patched loggers.
104
+ *
105
+ * Unlike the pino original, consola already normalises console-style multi-arg
106
+ * signatures (strings, objects, errors, mixed), so there is no need for a
107
+ * `logMethod` hook. The level is env-driven instead of hardcoded.
108
+ *
109
+ * `colors` is intentionally omitted — consola auto-detects TTY and `CI`
110
+ * internally, so duplicating that logic here would be fragile.
111
+ */
112
+ exports.defaultConsolaOptions = {
113
+ level: resolveLevel(),
114
+ formatOptions: {
115
+ date: true,
116
+ compact: false,
117
+ },
118
+ };
119
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":";;;AA2GA,sCAIC;AA/GD,qCAAsF;AAEtF;;;;;;;;;;;GAWG;AACH,MAAM,eAAe,GAAuB;IAC1C,QAAQ;IACR,OAAO,EAAE,qCAAqC;IAC9C,MAAM;IACN,KAAK;IACL,MAAM,EAAE,oEAAoE;IAC5E,OAAO;IACP,OAAO;IACP,SAAS;CACV,CAAC;AAEW,QAAA,aAAa,GAAsC,CAAC,GAAG,EAAE;IACpE,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,+DAA+D;IAC/D,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,mBAAS,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC;YAAE,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACzC,CAAC;IACD,4EAA4E;IAC5E,6DAA6D;IAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAS,CAAC,EAAE,CAAC;QACtD,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC;YAAE,GAAG,CAAC,KAAK,CAAC,GAAG,IAAe,CAAC;IACpD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC,EAAE,CAAC;AAEL;;;;GAIG;AACH,MAAM,aAAa,GAAqC,MAAM,CAAC,WAAW,CACxE,MAAM,CAAC,OAAO,CAAC,mBAAS,CAAC,CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAA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