@vsfedorenko/next-logger 0.1.0 → 0.2.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.
- package/README.md +100 -121
- package/README.ru.md +210 -0
- package/README.zh.md +200 -0
- package/dist/config.d.ts +25 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -70
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +31 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -54
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +40 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +50 -0
- package/dist/init.js.map +1 -0
- package/dist/logger.d.ts +8 -15
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +8 -16
- package/dist/logger.js.map +1 -1
- package/dist/patches/console.d.ts +17 -18
- package/dist/patches/console.d.ts.map +1 -1
- package/dist/patches/console.js +23 -34
- package/dist/patches/console.js.map +1 -1
- package/dist/patches/next.d.ts +11 -36
- package/dist/patches/next.d.ts.map +1 -1
- package/dist/patches/next.js +22 -113
- package/dist/patches/next.js.map +1 -1
- package/dist/withLogger.d.ts +36 -0
- package/dist/withLogger.d.ts.map +1 -0
- package/dist/withLogger.js +34 -0
- package/dist/withLogger.js.map +1 -0
- package/package.json +6 -24
- package/dist/presets/all.d.ts +0 -14
- package/dist/presets/all.d.ts.map +0 -1
- package/dist/presets/all.js +0 -15
- package/dist/presets/all.js.map +0 -1
- package/dist/presets/next-only.d.ts +0 -12
- package/dist/presets/next-only.d.ts.map +0 -1
- package/dist/presets/next-only.js +0 -13
- package/dist/presets/next-only.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,98 +2,83 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* # @vsfedorenko/next-logger
|
|
4
4
|
*
|
|
5
|
-
* A universal logging kit for Next.js.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* custom Next.js server.
|
|
5
|
+
* A universal logging kit for Next.js. Wraps the global `console.*` (which
|
|
6
|
+
* Next.js' own internal logger also funnels through) so all diagnostic output
|
|
7
|
+
* flows through a single level-controllable consola sink — without monkey
|
|
8
|
+
* patching Next's module (which is unreachable under Turbopack).
|
|
10
9
|
*
|
|
11
10
|
* ## Usage
|
|
12
11
|
*
|
|
13
|
-
*
|
|
12
|
+
* Wrap your Next config and call `init()` from instrumentation:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* // next.config.ts
|
|
16
|
+
* import { withLogger } from "@vsfedorenko/next-logger";
|
|
17
|
+
*
|
|
18
|
+
* export default withLogger({ consola: { level: 4 } })({
|
|
19
|
+
* // ...your next config
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
14
22
|
*
|
|
15
23
|
* ```ts
|
|
16
24
|
* // instrumentation.ts (project root)
|
|
17
25
|
* export async function register() {
|
|
18
26
|
* if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
19
|
-
* await import("@vsfedorenko/next-logger");
|
|
27
|
+
* const { init } = await import("@vsfedorenko/next-logger");
|
|
28
|
+
* init();
|
|
20
29
|
* }
|
|
21
30
|
* }
|
|
22
31
|
* ```
|
|
23
32
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* await import("@vsfedorenko/next-logger/presets/next-only");
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* ### `-r` preload
|
|
32
|
-
*
|
|
33
|
-
* ```sh
|
|
34
|
-
* node -r @vsfedorenko/next-logger server.js
|
|
35
|
-
* ```
|
|
33
|
+
* `init()` patches `console.*`. To skip patching console, pass
|
|
34
|
+
* `{ console: false }`.
|
|
36
35
|
*
|
|
37
36
|
* ## Configuration
|
|
38
37
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* export default {
|
|
45
|
-
* consola: createConsola({ level: 4 }), // full custom instance
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* Or partial options (merged with defaults):
|
|
38
|
+
* `withLogger(options)` serialises `options` into the `NEXT_LOGGER_CONFIG` env
|
|
39
|
+
* var via Next.js' validated `env` config key (no "Unrecognized key" warning),
|
|
40
|
+
* inlined at build time and read back at runtime. Only serialisable consola
|
|
41
|
+
* options are supported (level, formatOptions, …):
|
|
50
42
|
*
|
|
51
43
|
* ```ts
|
|
52
|
-
*
|
|
53
|
-
* consola: { level: 4, formatOptions: { date: false } },
|
|
54
|
-
* };
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* Or a factory (receives the library's default options):
|
|
58
|
-
*
|
|
59
|
-
* ```ts
|
|
60
|
-
* import type { ConsolaOptions } from "consola";
|
|
61
|
-
*
|
|
62
|
-
* export default {
|
|
63
|
-
* consola: (defaults: Partial<ConsolaOptions>) =>
|
|
64
|
-
* createConsola({ ...defaults, level: 5 }),
|
|
65
|
-
* };
|
|
44
|
+
* withLogger({ consola: { level: 4, formatOptions: { date: false } } })
|
|
66
45
|
* ```
|
|
67
46
|
*
|
|
68
47
|
* ## Log level
|
|
69
48
|
*
|
|
70
|
-
* Without
|
|
49
|
+
* Without `withLogger`, the level resolves from (in order) `LOG_LEVEL` or
|
|
71
50
|
* `NEXT_PUBLIC_LOG_LEVEL` (numeric or named: silent/fatal/error/warn/info/log/
|
|
72
51
|
* debug/trace/verbose), falling back to `3` (info).
|
|
73
52
|
*/
|
|
74
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
-
exports.skipEmpty = exports.isEmptyMessage = exports.CONSOLE_METHODS = exports.routeConsoleMethod = exports.patchConsole = exports.
|
|
76
|
-
|
|
77
|
-
|
|
54
|
+
exports.skipEmpty = exports.isEmptyMessage = exports.isNextLog = exports.CONSOLE_METHODS = exports.routeConsoleMethod = exports.patchConsole = exports.createJsonReporter = exports.resolveFormat = exports.defaultConsolaOptions = exports.CONFIG_ENV_VAR = exports.resolveLoggerConfig = exports.loadConfig = exports.buildLogger = exports.getLogger = exports.init = exports.withLogger = void 0;
|
|
55
|
+
// Build-time Next.js config wrapper.
|
|
56
|
+
var withLogger_1 = require("./withLogger");
|
|
57
|
+
Object.defineProperty(exports, "withLogger", { enumerable: true, get: function () { return withLogger_1.withLogger; } });
|
|
58
|
+
// Runtime initialisation + instance access.
|
|
59
|
+
var init_1 = require("./init");
|
|
60
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
61
|
+
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return init_1.getLogger; } });
|
|
62
|
+
// Logger + config internals.
|
|
78
63
|
var logger_1 = require("./logger");
|
|
79
|
-
Object.defineProperty(exports, "
|
|
64
|
+
Object.defineProperty(exports, "buildLogger", { enumerable: true, get: function () { return logger_1.buildLogger; } });
|
|
80
65
|
var config_1 = require("./config");
|
|
81
66
|
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
|
|
67
|
+
Object.defineProperty(exports, "resolveLoggerConfig", { enumerable: true, get: function () { return config_1.resolveLoggerConfig; } });
|
|
68
|
+
Object.defineProperty(exports, "CONFIG_ENV_VAR", { enumerable: true, get: function () { return config_1.CONFIG_ENV_VAR; } });
|
|
82
69
|
var defaults_1 = require("./defaults");
|
|
83
70
|
Object.defineProperty(exports, "defaultConsolaOptions", { enumerable: true, get: function () { return defaults_1.defaultConsolaOptions; } });
|
|
84
71
|
Object.defineProperty(exports, "resolveFormat", { enumerable: true, get: function () { return defaults_1.resolveFormat; } });
|
|
85
72
|
// JSON reporter (server-side structured logging).
|
|
86
73
|
var json_1 = require("./reporters/json");
|
|
87
74
|
Object.defineProperty(exports, "createJsonReporter", { enumerable: true, get: function () { return json_1.createJsonReporter; } });
|
|
88
|
-
//
|
|
89
|
-
var next_1 = require("./patches/next");
|
|
90
|
-
Object.defineProperty(exports, "patchNext", { enumerable: true, get: function () { return next_1.patchNext; } });
|
|
91
|
-
Object.defineProperty(exports, "routeNextMethod", { enumerable: true, get: function () { return next_1.routeNextMethod; } });
|
|
92
|
-
Object.defineProperty(exports, "NEXT_PREFIXES", { enumerable: true, get: function () { return next_1.NEXT_PREFIXES; } });
|
|
75
|
+
// Console-sink patch + Next-log classifier.
|
|
93
76
|
var console_1 = require("./patches/console");
|
|
94
77
|
Object.defineProperty(exports, "patchConsole", { enumerable: true, get: function () { return console_1.patchConsole; } });
|
|
95
78
|
Object.defineProperty(exports, "routeConsoleMethod", { enumerable: true, get: function () { return console_1.routeConsoleMethod; } });
|
|
96
79
|
Object.defineProperty(exports, "CONSOLE_METHODS", { enumerable: true, get: function () { return console_1.CONSOLE_METHODS; } });
|
|
80
|
+
var next_1 = require("./patches/next");
|
|
81
|
+
Object.defineProperty(exports, "isNextLog", { enumerable: true, get: function () { return next_1.isNextLog; } });
|
|
97
82
|
var util_1 = require("./patches/util");
|
|
98
83
|
Object.defineProperty(exports, "isEmptyMessage", { enumerable: true, get: function () { return util_1.isEmptyMessage; } });
|
|
99
84
|
Object.defineProperty(exports, "skipEmpty", { enumerable: true, get: function () { return util_1.skipEmpty; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;AAEH,qCAAqC;AACrC,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAGnB,4CAA4C;AAC5C,+BAAyC;AAAhC,4FAAA,IAAI,OAAA;AAAE,iGAAA,SAAS,OAAA;AAGxB,6BAA6B;AAC7B,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AACpB,mCAA2E;AAAlE,oGAAA,UAAU,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAExD,uCAAkE;AAAzD,iHAAA,qBAAqB,OAAA;AAAE,yGAAA,aAAa,OAAA;AAG7C,kDAAkD;AAClD,yCAAsD;AAA7C,0GAAA,kBAAkB,OAAA;AAE3B,4CAA4C;AAC5C,6CAAsF;AAA7E,uGAAA,YAAY,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,0GAAA,eAAe,OAAA;AAE1D,uCAA2C;AAAlC,iGAAA,SAAS,OAAA;AAClB,uCAA2D;AAAlD,sGAAA,cAAc,OAAA;AAAE,iGAAA,SAAS,OAAA"}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ConsolaInstance } from "consola";
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link init}.
|
|
4
|
+
*/
|
|
5
|
+
export interface InitOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Patch the global `console.*` (default `true`). Set `false` to leave native
|
|
8
|
+
* `console` formatting untouched.
|
|
9
|
+
*/
|
|
10
|
+
readonly console?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Initialises `@vsfedorenko/next-logger`.
|
|
14
|
+
*
|
|
15
|
+
* Builds the shared consola instance from the `NEXT_LOGGER_CONFIG` env var
|
|
16
|
+
* (injected at build time by {@link withLogger}) and patches the global
|
|
17
|
+
* `console.*` so all diagnostic output — application logs AND Next.js' own
|
|
18
|
+
* internal logs — flows through one level-controllable sink. Call once from
|
|
19
|
+
* your `instrumentation.ts` `register()` hook:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* // instrumentation.ts (project root)
|
|
23
|
+
* export async function register() {
|
|
24
|
+
* if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
25
|
+
* const { init } = await import("@vsfedorenko/next-logger");
|
|
26
|
+
* init();
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Returns the configured consola instance. Idempotent — a second call is a
|
|
32
|
+
* no-op that returns the existing instance.
|
|
33
|
+
*/
|
|
34
|
+
export declare function init(options?: InitOptions): ConsolaInstance;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the consola instance built by {@link init}. Throws if {@link init}
|
|
37
|
+
* has not been called yet.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getLogger(): ConsolaInstance;
|
|
40
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI/C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAID;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,eAAe,CAW/D;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,eAAe,CAO3C"}
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = init;
|
|
4
|
+
exports.getLogger = getLogger;
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const console_1 = require("./patches/console");
|
|
7
|
+
let active = null;
|
|
8
|
+
/**
|
|
9
|
+
* Initialises `@vsfedorenko/next-logger`.
|
|
10
|
+
*
|
|
11
|
+
* Builds the shared consola instance from the `NEXT_LOGGER_CONFIG` env var
|
|
12
|
+
* (injected at build time by {@link withLogger}) and patches the global
|
|
13
|
+
* `console.*` so all diagnostic output — application logs AND Next.js' own
|
|
14
|
+
* internal logs — flows through one level-controllable sink. Call once from
|
|
15
|
+
* your `instrumentation.ts` `register()` hook:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* // instrumentation.ts (project root)
|
|
19
|
+
* export async function register() {
|
|
20
|
+
* if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
21
|
+
* const { init } = await import("@vsfedorenko/next-logger");
|
|
22
|
+
* init();
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Returns the configured consola instance. Idempotent — a second call is a
|
|
28
|
+
* no-op that returns the existing instance.
|
|
29
|
+
*/
|
|
30
|
+
function init(options = {}) {
|
|
31
|
+
if (active)
|
|
32
|
+
return active;
|
|
33
|
+
const instance = (0, logger_1.buildLogger)();
|
|
34
|
+
active = instance;
|
|
35
|
+
if (options.console !== false) {
|
|
36
|
+
(0, console_1.patchConsole)(instance);
|
|
37
|
+
}
|
|
38
|
+
return instance;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the consola instance built by {@link init}. Throws if {@link init}
|
|
42
|
+
* has not been called yet.
|
|
43
|
+
*/
|
|
44
|
+
function getLogger() {
|
|
45
|
+
if (!active) {
|
|
46
|
+
throw new Error("@vsfedorenko/next-logger: call init() before getLogger().");
|
|
47
|
+
}
|
|
48
|
+
return active;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;AAuCA,oBAWC;AAMD,8BAOC;AA9DD,qCAAuC;AACvC,+CAAiD;AAajD,IAAI,MAAM,GAA2B,IAAI,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,IAAI,CAAC,UAAuB,EAAE;IAC5C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,QAAQ,GAAG,IAAA,oBAAW,GAAE,CAAC;IAC/B,MAAM,GAAG,QAAQ,CAAC;IAElB,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QAC9B,IAAA,sBAAY,EAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS;IACvB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { type ConsolaInstance } from "consola";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Builds the shared consola instance from the resolved config.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 3. No config → built from {@link defaultConsolaOptions}.
|
|
5
|
+
* The config is delivered at build time by {@link withLogger} via the
|
|
6
|
+
* `NEXT_LOGGER_CONFIG` env var (see {@link loadConfig}). When `LOG_FORMAT=json`
|
|
7
|
+
* is set, the instance uses the {@link createJsonReporter} instead of consola's
|
|
8
|
+
* default pretty reporter. A custom instance/factory (only reachable when
|
|
9
|
+
* {@link loadConfig} is bypassed) is used as-is.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
* the {@link createJsonReporter} instead of consola's default pretty reporter.
|
|
14
|
-
* A config file's custom instance / factory bypasses format selection — the
|
|
15
|
-
* user's instance controls everything.
|
|
16
|
-
*
|
|
17
|
-
* Both patches (`patches/next`, `patches/console`) call `.withTag()` on this
|
|
18
|
-
* object so they can namespace their output.
|
|
11
|
+
* Call from {@link init} (the instrumentation hook).
|
|
19
12
|
*/
|
|
20
|
-
export declare
|
|
13
|
+
export declare function buildLogger(): ConsolaInstance;
|
|
21
14
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAK9D
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAK9D;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,IAAI,eAAe,CAkB7C"}
|
package/dist/logger.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.buildLogger = buildLogger;
|
|
4
4
|
const consola_1 = require("consola");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
const defaults_1 = require("./defaults");
|
|
7
7
|
const json_1 = require("./reporters/json");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Builds the shared consola instance from the resolved config.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 3. No config → built from {@link defaultConsolaOptions}.
|
|
11
|
+
* The config is delivered at build time by {@link withLogger} via the
|
|
12
|
+
* `NEXT_LOGGER_CONFIG` env var (see {@link loadConfig}). When `LOG_FORMAT=json`
|
|
13
|
+
* is set, the instance uses the {@link createJsonReporter} instead of consola's
|
|
14
|
+
* default pretty reporter. A custom instance/factory (only reachable when
|
|
15
|
+
* {@link loadConfig} is bypassed) is used as-is.
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
* the {@link createJsonReporter} instead of consola's default pretty reporter.
|
|
20
|
-
* A config file's custom instance / factory bypasses format selection — the
|
|
21
|
-
* user's instance controls everything.
|
|
22
|
-
*
|
|
23
|
-
* Both patches (`patches/next`, `patches/console`) call `.withTag()` on this
|
|
24
|
-
* object so they can namespace their output.
|
|
17
|
+
* Call from {@link init} (the instrumentation hook).
|
|
25
18
|
*/
|
|
26
|
-
exports.logger = buildLogger();
|
|
27
19
|
function buildLogger() {
|
|
28
20
|
const resolved = (0, config_1.loadConfig)();
|
|
29
21
|
switch (resolved.kind) {
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;AAgBA,kCAkBC;AAlCD,qCAA8D;AAC9D,qCAAsC;AACtC,yCAA2C;AAC3C,2CAAsD;AAEtD;;;;;;;;;;GAUG;AACH,SAAgB,WAAW;IACzB,MAAM,QAAQ,GAAG,IAAA,mBAAU,GAAE,CAAC;IAE9B,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,QAAQ,CAAC,QAAQ,CAAC;QAC3B,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,QAAQ,GAAG,IAAA,uBAAa,EAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAEjD,wEAAwE;YACxE,kDAAkD;YAClD,IAAI,IAAA,wBAAa,GAAE,KAAK,MAAM,EAAE,CAAC;gBAC/B,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAA,yBAAkB,GAAE,CAAC,CAAC,CAAC;YAChD,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Patches the global `console.*` methods so every call routes through the
|
|
3
|
-
*
|
|
3
|
+
* consola instance — the single interception point that captures BOTH
|
|
4
|
+
* application console output AND Next.js' internal logs (which `log.ts`
|
|
5
|
+
* funnels through `console.*`).
|
|
4
6
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Each call is classified via {@link isNextLog}: lines carrying one of Next's
|
|
8
|
+
* marker symbols (`▲`/`✓`/`⚠`) are tagged `next.js`, everything else `console`.
|
|
9
|
+
* This restores the source distinction without monkeypatching Next's module
|
|
10
|
+
* (which Turbopack isolates into a separate bundle instance).
|
|
8
11
|
*
|
|
9
|
-
*
|
|
12
|
+
* Call explicitly via {@link init} — not a side-effect module.
|
|
10
13
|
*/
|
|
11
14
|
import type { ConsolaInstance } from "consola";
|
|
12
15
|
import type { LogFunction } from "../types";
|
|
@@ -17,22 +20,18 @@ export declare const CONSOLE_METHODS: readonly ["log", "debug", "info", "warn",
|
|
|
17
20
|
/** A console method name we patch. */
|
|
18
21
|
export type ConsoleMethodName = (typeof CONSOLE_METHODS)[number];
|
|
19
22
|
/**
|
|
20
|
-
* Maps a console method name to the corresponding consola log function
|
|
23
|
+
* Maps a console method name to the corresponding consola log function bound
|
|
24
|
+
* to a child logger tagged `tag`. `console.log` and `console.info` both map to
|
|
25
|
+
* consola `info`. The result is wrapped in {@link skipEmpty}.
|
|
21
26
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* tagged with `tag`, so every call is namespaced.
|
|
25
|
-
*
|
|
26
|
-
* Pure function — given a consola instance and a tag, returns the routing
|
|
27
|
-
* function. Exported so the level mapping can be unit-tested without touching
|
|
28
|
-
* the global `console`.
|
|
27
|
+
* Pure — exported so the routing can be unit-tested without touching the global
|
|
28
|
+
* `console`.
|
|
29
29
|
*/
|
|
30
30
|
export declare function routeConsoleMethod(method: ConsoleMethodName | string, consola: ConsolaInstance, tag: string): LogFunction;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @param tagOverride override the `console` tag (useful for tests).
|
|
32
|
+
* Overwrites `console.{log,debug,info,warn,error}` so calls route through the
|
|
33
|
+
* given consola instance, tagged `next.js` for Next's own log lines and
|
|
34
|
+
* `console` for everything else.
|
|
36
35
|
*/
|
|
37
|
-
export declare function patchConsole(
|
|
36
|
+
export declare function patchConsole(consola: ConsolaInstance): void;
|
|
38
37
|
//# sourceMappingURL=console.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/patches/console.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/patches/console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C;;GAEG;AACH,eAAO,MAAM,eAAe,oDAMlB,CAAC;AAEX,sCAAsC;AACtC,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,MAAM,GACV,WAAW,CAGb;AAqBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAO3D"}
|
package/dist/patches/console.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Patches the global `console.*` methods so every call routes through the
|
|
4
|
-
*
|
|
4
|
+
* consola instance — the single interception point that captures BOTH
|
|
5
|
+
* application console output AND Next.js' internal logs (which `log.ts`
|
|
6
|
+
* funnels through `console.*`).
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* Each call is classified via {@link isNextLog}: lines carrying one of Next's
|
|
9
|
+
* marker symbols (`▲`/`✓`/`⚠`) are tagged `next.js`, everything else `console`.
|
|
10
|
+
* This restores the source distinction without monkeypatching Next's module
|
|
11
|
+
* (which Turbopack isolates into a separate bundle instance).
|
|
9
12
|
*
|
|
10
|
-
*
|
|
13
|
+
* Call explicitly via {@link init} — not a side-effect module.
|
|
11
14
|
*/
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.CONSOLE_METHODS = void 0;
|
|
14
17
|
exports.routeConsoleMethod = routeConsoleMethod;
|
|
15
18
|
exports.patchConsole = patchConsole;
|
|
16
|
-
const
|
|
19
|
+
const next_1 = require("./next");
|
|
17
20
|
const util_1 = require("./util");
|
|
18
21
|
/**
|
|
19
22
|
* The console methods this patch overwrites.
|
|
@@ -26,27 +29,17 @@ exports.CONSOLE_METHODS = [
|
|
|
26
29
|
"error",
|
|
27
30
|
];
|
|
28
31
|
/**
|
|
29
|
-
* Maps a console method name to the corresponding consola log function
|
|
32
|
+
* Maps a console method name to the corresponding consola log function bound
|
|
33
|
+
* to a child logger tagged `tag`. `console.log` and `console.info` both map to
|
|
34
|
+
* consola `info`. The result is wrapped in {@link skipEmpty}.
|
|
30
35
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* tagged with `tag`, so every call is namespaced.
|
|
34
|
-
*
|
|
35
|
-
* Pure function — given a consola instance and a tag, returns the routing
|
|
36
|
-
* function. Exported so the level mapping can be unit-tested without touching
|
|
37
|
-
* the global `console`.
|
|
36
|
+
* Pure — exported so the routing can be unit-tested without touching the global
|
|
37
|
+
* `console`.
|
|
38
38
|
*/
|
|
39
39
|
function routeConsoleMethod(method, consola, tag) {
|
|
40
40
|
const child = consola.withTag(tag);
|
|
41
|
-
|
|
42
|
-
return (0, util_1.skipEmpty)(bound);
|
|
41
|
+
return (0, util_1.skipEmpty)(selectConsolaMethod(method, child));
|
|
43
42
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Selects the consola method matching a console method name.
|
|
46
|
-
*
|
|
47
|
-
* The bound function is returned directly; consola's methods accept the same
|
|
48
|
-
* `(...args: unknown[])` shape as {@link LogFunction}.
|
|
49
|
-
*/
|
|
50
43
|
function selectConsolaMethod(method, consola) {
|
|
51
44
|
switch (method) {
|
|
52
45
|
case "error":
|
|
@@ -59,24 +52,20 @@ function selectConsolaMethod(method, consola) {
|
|
|
59
52
|
case "info":
|
|
60
53
|
return consola.info.bind(consola);
|
|
61
54
|
default:
|
|
62
|
-
// Unknown method name — default to info (same as the original).
|
|
63
55
|
return consola.info.bind(consola);
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
58
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @param tagOverride override the `console` tag (useful for tests).
|
|
59
|
+
* Overwrites `console.{log,debug,info,warn,error}` so calls route through the
|
|
60
|
+
* given consola instance, tagged `next.js` for Next's own log lines and
|
|
61
|
+
* `console` for everything else.
|
|
71
62
|
*/
|
|
72
|
-
function patchConsole(
|
|
73
|
-
const tag = tagOverride ?? "console";
|
|
63
|
+
function patchConsole(consola) {
|
|
74
64
|
for (const method of exports.CONSOLE_METHODS) {
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
console[method] = ((...args) => {
|
|
66
|
+
const tag = (0, next_1.isNextLog)(args) ? "next.js" : "console";
|
|
67
|
+
routeConsoleMethod(method, consola, tag)(...args);
|
|
68
|
+
});
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
|
-
// Apply on import (side effect), matching the original's
|
|
80
|
-
// `require('./patches/console')` semantics.
|
|
81
|
-
patchConsole();
|
|
82
71
|
//# sourceMappingURL=console.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/patches/console.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/patches/console.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA6BH,gDAOC;AA0BD,oCAOC;AAjED,iCAAmC;AACnC,iCAAmC;AAEnC;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;CACC,CAAC;AAKX;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,MAAkC,EAClC,OAAwB,EACxB,GAAW;IAEX,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,IAAA,gBAAS,EAAC,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,mBAAmB,CAC1B,MAAc,EACd,OAAwB;IAExB,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAgB,CAAC;QACpD,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB,CAAC;QACnD,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAgB,CAAC;QACpD,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB,CAAC;QACnD;YACE,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB,CAAC;IACrD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,OAAwB;IACnD,KAAK,MAAM,MAAM,IAAI,uBAAe,EAAE,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE;YACxC,MAAM,GAAG,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;YACpD,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACpD,CAAC,CAA+B,CAAC;IACnC,CAAC;AACH,CAAC"}
|
package/dist/patches/next.d.ts
CHANGED
|
@@ -1,42 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* call routes through the shared consola instance tagged `next.js`.
|
|
2
|
+
* Classifier for Next.js' internal log output captured at the console sink.
|
|
4
3
|
*
|
|
5
|
-
* Next
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
import type { ConsolaInstance } from "consola";
|
|
13
|
-
import type { LogFunction } from "../types";
|
|
14
|
-
/**
|
|
15
|
-
* The methods exported by Next's log module that we patch.
|
|
16
|
-
*
|
|
17
|
-
* `prefixes` is the set Next itself advertises (wait/error/warn/ready/info/
|
|
18
|
-
* event/trace). `bootstrap` is an extra export that bypasses the prefix logic
|
|
19
|
-
* (raw `console.log`) — we route it too so it stays consistent.
|
|
4
|
+
* Next.js' `next/dist/build/output/log` funnels every diagnostic line through
|
|
5
|
+
* `console.log`/`console.warn`/`console.error`, prefixing each with a coloured
|
|
6
|
+
* marker symbol (`▲`, `✓`, `⚠`, …). Detecting that prefix lets the console
|
|
7
|
+
* patch tag those lines as `next.js` rather than `console` — restoring the
|
|
8
|
+
* source distinction WITHOUT monkeypatching Next's module (which is isolated
|
|
9
|
+
* into a separate bundle instance under Turbopack and unreachable via
|
|
10
|
+
* `require.cache`).
|
|
20
11
|
*/
|
|
21
|
-
export declare const NEXT_PREFIXES: readonly ["wait", "error", "warn", "ready", "info", "event", "trace"];
|
|
22
|
-
/** A Next.js prefix method name we patch. */
|
|
23
|
-
export type NextMethodName = (typeof NEXT_PREFIXES)[number];
|
|
24
12
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* it; the pino original had to fall back to `debug` for Winston which lacks
|
|
28
|
-
* trace).
|
|
29
|
-
*
|
|
30
|
-
* Pure function — given a consola instance and a tag, returns the routing
|
|
31
|
-
* function. Exported so the level mapping can be unit-tested without touching
|
|
32
|
-
* `require.cache` or a real Next.js install.
|
|
33
|
-
*/
|
|
34
|
-
export declare function routeNextMethod(method: NextMethodName | string, consola: ConsolaInstance, tag: string): LogFunction;
|
|
35
|
-
/**
|
|
36
|
-
* Applies the Next.js logger patch. Safe to call multiple times — it
|
|
37
|
-
* re-derives the methods from the current {@link logger} each time.
|
|
38
|
-
*
|
|
39
|
-
* @param tagOverride override the `next.js` tag (useful for tests).
|
|
13
|
+
* Returns `true` when the given console call args look like a Next.js log line
|
|
14
|
+
* (first string arg, ANSI-stripped, starts with a Next marker symbol).
|
|
40
15
|
*/
|
|
41
|
-
export declare function
|
|
16
|
+
export declare function isNextLog(args: readonly unknown[]): boolean;
|
|
42
17
|
//# sourceMappingURL=next.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/patches/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/patches/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAK3D"}
|