@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.
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/dist/browser.d.ts +41 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +47 -0
- package/dist/browser.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +103 -0
- package/dist/config.js.map +1 -0
- package/dist/defaults.d.ts +31 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +119 -0
- package/dist/defaults.js.map +1 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +21 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +43 -0
- package/dist/logger.js.map +1 -0
- package/dist/patches/console.d.ts +38 -0
- package/dist/patches/console.d.ts.map +1 -0
- package/dist/patches/console.js +82 -0
- package/dist/patches/console.js.map +1 -0
- package/dist/patches/next.d.ts +42 -0
- package/dist/patches/next.d.ts.map +1 -0
- package/dist/patches/next.js +124 -0
- package/dist/patches/next.js.map +1 -0
- package/dist/patches/util.d.ts +25 -0
- package/dist/patches/util.d.ts.map +1 -0
- package/dist/patches/util.js +41 -0
- package/dist/patches/util.js.map +1 -0
- package/dist/presets/all.d.ts +14 -0
- package/dist/presets/all.d.ts.map +1 -0
- package/dist/presets/all.js +15 -0
- package/dist/presets/all.js.map +1 -0
- package/dist/presets/next-only.d.ts +12 -0
- package/dist/presets/next-only.d.ts.map +1 -0
- package/dist/presets/next-only.js +13 -0
- package/dist/presets/next-only.js.map +1 -0
- package/dist/reporters/json.d.ts +37 -0
- package/dist/reporters/json.d.ts.map +1 -0
- package/dist/reporters/json.js +160 -0
- package/dist/reporters/json.js.map +1 -0
- package/dist/reporters/sentry.d.ts +70 -0
- package/dist/reporters/sentry.d.ts.map +1 -0
- package/dist/reporters/sentry.js +152 -0
- package/dist/reporters/sentry.js.map +1 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +101 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset: patch Next.js' logger **and** the global `console.*`.
|
|
3
|
+
*
|
|
4
|
+
* This is the default — importing `@vsfedorenko/next-logger` or `@vsfedorenko/next-logger/presets/all`
|
|
5
|
+
* applies both patches as side effects.
|
|
6
|
+
*
|
|
7
|
+
* Order matters: Next's logger is patched first so its internal calls are
|
|
8
|
+
* already routed through consola before `console` itself is overwritten. Both
|
|
9
|
+
* patches share the same {@link logger} instance.
|
|
10
|
+
*/
|
|
11
|
+
import "../patches/next";
|
|
12
|
+
import "../patches/console";
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=all.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,iBAAiB,CAAC;AACzB,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Preset: patch Next.js' logger **and** the global `console.*`.
|
|
4
|
+
*
|
|
5
|
+
* This is the default — importing `@vsfedorenko/next-logger` or `@vsfedorenko/next-logger/presets/all`
|
|
6
|
+
* applies both patches as side effects.
|
|
7
|
+
*
|
|
8
|
+
* Order matters: Next's logger is patched first so its internal calls are
|
|
9
|
+
* already routed through consola before `console` itself is overwritten. Both
|
|
10
|
+
* patches share the same {@link logger} instance.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
require("../patches/next");
|
|
14
|
+
require("../patches/console");
|
|
15
|
+
//# sourceMappingURL=all.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/presets/all.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAEH,2BAAyB;AACzB,8BAA4B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preset: patch Next.js' logger **only**, leaving the global `console.*`
|
|
3
|
+
* untouched.
|
|
4
|
+
*
|
|
5
|
+
* Import `@vsfedorenko/next-logger/presets/next-only` instead of the default entry when you
|
|
6
|
+
* want Next's internal logs routed through consola but prefer to keep
|
|
7
|
+
* `console.log`/`console.error` with their native Node.js formatting (e.g. for
|
|
8
|
+
* terminal-pretty output in development).
|
|
9
|
+
*/
|
|
10
|
+
import "../patches/next";
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=next-only.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-only.d.ts","sourceRoot":"","sources":["../../src/presets/next-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Preset: patch Next.js' logger **only**, leaving the global `console.*`
|
|
4
|
+
* untouched.
|
|
5
|
+
*
|
|
6
|
+
* Import `@vsfedorenko/next-logger/presets/next-only` instead of the default entry when you
|
|
7
|
+
* want Next's internal logs routed through consola but prefer to keep
|
|
8
|
+
* `console.log`/`console.error` with their native Node.js formatting (e.g. for
|
|
9
|
+
* terminal-pretty output in development).
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("../patches/next");
|
|
13
|
+
//# sourceMappingURL=next-only.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-only.js","sourceRoot":"","sources":["../../src/presets/next-only.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAEH,2BAAyB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON reporter for consola — emits each log as a single-line JSON object to
|
|
3
|
+
* stdout (or stderr for error+), suitable for structured-log aggregators
|
|
4
|
+
* (Loki, Datadog, CloudWatch, Elasticsearch, …).
|
|
5
|
+
*
|
|
6
|
+
* Output shape (stable):
|
|
7
|
+
*
|
|
8
|
+
* ```json
|
|
9
|
+
* {"level":"error","type":"error","tag":"next.js","msg":"failed to compile","date":"2026-07-11T13:43:10.712Z"}
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* - `level` — consola's named level (`silent`/`error`/`warn`/`info`/`debug`/`trace`/`verbose`/…).
|
|
13
|
+
* - `type` — consola's log type (usually matches `level`, but Next.js
|
|
14
|
+
* distinguishes `event`, `ready`, `wait` etc.).
|
|
15
|
+
* - `tag` — the consola tag (`next.js`, `console`, `app`, …).
|
|
16
|
+
* - `msg` — the interpolated message string (multi-arg args joined with space).
|
|
17
|
+
* - `args` — additional structured arguments beyond the message (objects,
|
|
18
|
+
* errors). Omitted when there are no extra args.
|
|
19
|
+
* - `date` — ISO 8601 timestamp.
|
|
20
|
+
*
|
|
21
|
+
* Errors are serialised as `{ message, stack, name }` so stack traces survive
|
|
22
|
+
* in log aggregators.
|
|
23
|
+
*/
|
|
24
|
+
import type { ConsolaReporter } from "consola";
|
|
25
|
+
/**
|
|
26
|
+
* Creates a JSON reporter that writes to `process.stdout` / `process.stderr`.
|
|
27
|
+
*
|
|
28
|
+
* - Error-level messages (level ≤ 1) go to **stderr** (conventional for
|
|
29
|
+
* structured logs, keeps stdout clean for piping).
|
|
30
|
+
* - Everything else goes to **stdout**.
|
|
31
|
+
*
|
|
32
|
+
* @param overrideStream force all output to a single stream (useful for tests).
|
|
33
|
+
*/
|
|
34
|
+
export declare function createJsonReporter(overrideStream?: {
|
|
35
|
+
write: (s: string) => boolean;
|
|
36
|
+
}): ConsolaReporter;
|
|
37
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/reporters/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAA6B,MAAM,SAAS,CAAC;AA6D1E;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,cAAc,CAAC,EAAE;IAAE,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,GACjD,eAAe,CAyBjB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON reporter for consola — emits each log as a single-line JSON object to
|
|
4
|
+
* stdout (or stderr for error+), suitable for structured-log aggregators
|
|
5
|
+
* (Loki, Datadog, CloudWatch, Elasticsearch, …).
|
|
6
|
+
*
|
|
7
|
+
* Output shape (stable):
|
|
8
|
+
*
|
|
9
|
+
* ```json
|
|
10
|
+
* {"level":"error","type":"error","tag":"next.js","msg":"failed to compile","date":"2026-07-11T13:43:10.712Z"}
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* - `level` — consola's named level (`silent`/`error`/`warn`/`info`/`debug`/`trace`/`verbose`/…).
|
|
14
|
+
* - `type` — consola's log type (usually matches `level`, but Next.js
|
|
15
|
+
* distinguishes `event`, `ready`, `wait` etc.).
|
|
16
|
+
* - `tag` — the consola tag (`next.js`, `console`, `app`, …).
|
|
17
|
+
* - `msg` — the interpolated message string (multi-arg args joined with space).
|
|
18
|
+
* - `args` — additional structured arguments beyond the message (objects,
|
|
19
|
+
* errors). Omitted when there are no extra args.
|
|
20
|
+
* - `date` — ISO 8601 timestamp.
|
|
21
|
+
*
|
|
22
|
+
* Errors are serialised as `{ message, stack, name }` so stack traces survive
|
|
23
|
+
* in log aggregators.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createJsonReporter = createJsonReporter;
|
|
27
|
+
const defaults_1 = require("../defaults");
|
|
28
|
+
/**
|
|
29
|
+
* Serialises an `Error` into a JSON-safe plain object (preserves stack + cause).
|
|
30
|
+
*/
|
|
31
|
+
function serializeError(err) {
|
|
32
|
+
const obj = {
|
|
33
|
+
name: err.name,
|
|
34
|
+
message: err.message,
|
|
35
|
+
stack: err.stack,
|
|
36
|
+
};
|
|
37
|
+
if (err.cause !== undefined) {
|
|
38
|
+
obj.cause = err.cause instanceof Error ? serializeError(err.cause) : err.cause;
|
|
39
|
+
}
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Makes any value JSON-safe — recursively converts BigInt, Error, circular
|
|
44
|
+
* references, and class instances into plain objects.
|
|
45
|
+
*/
|
|
46
|
+
function jsonSafe(value, seen = new WeakSet()) {
|
|
47
|
+
if (value === null || value === undefined)
|
|
48
|
+
return value;
|
|
49
|
+
switch (typeof value) {
|
|
50
|
+
case "string":
|
|
51
|
+
case "number":
|
|
52
|
+
case "boolean":
|
|
53
|
+
return value;
|
|
54
|
+
case "bigint":
|
|
55
|
+
return String(value);
|
|
56
|
+
case "function":
|
|
57
|
+
return `[Function: ${value.name || "anonymous"}]`;
|
|
58
|
+
case "symbol":
|
|
59
|
+
return String(value);
|
|
60
|
+
case "object": {
|
|
61
|
+
// Circular reference guard.
|
|
62
|
+
if (seen.has(value))
|
|
63
|
+
return "[Circular]";
|
|
64
|
+
seen.add(value);
|
|
65
|
+
if (value instanceof Date)
|
|
66
|
+
return value.toISOString();
|
|
67
|
+
if (value instanceof Error)
|
|
68
|
+
return serializeError(value);
|
|
69
|
+
if (value instanceof RegExp)
|
|
70
|
+
return value.toString();
|
|
71
|
+
if (Array.isArray(value)) {
|
|
72
|
+
return value.map((v) => jsonSafe(v, seen));
|
|
73
|
+
}
|
|
74
|
+
const obj = value;
|
|
75
|
+
const result = {};
|
|
76
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
77
|
+
result[key] = jsonSafe(val, seen);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
default:
|
|
82
|
+
return String(value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a JSON reporter that writes to `process.stdout` / `process.stderr`.
|
|
87
|
+
*
|
|
88
|
+
* - Error-level messages (level ≤ 1) go to **stderr** (conventional for
|
|
89
|
+
* structured logs, keeps stdout clean for piping).
|
|
90
|
+
* - Everything else goes to **stdout**.
|
|
91
|
+
*
|
|
92
|
+
* @param overrideStream force all output to a single stream (useful for tests).
|
|
93
|
+
*/
|
|
94
|
+
function createJsonReporter(overrideStream) {
|
|
95
|
+
return {
|
|
96
|
+
log(logObj, _ctx) {
|
|
97
|
+
const msg = buildMessage(logObj.args);
|
|
98
|
+
const extra = buildExtraArgs(logObj.args);
|
|
99
|
+
const entry = {
|
|
100
|
+
level: defaults_1.LEVEL_TO_NAME[logObj.level] ?? "info",
|
|
101
|
+
type: logObj.type,
|
|
102
|
+
tag: logObj.tag ?? "",
|
|
103
|
+
msg,
|
|
104
|
+
date: logObj.date instanceof Date ? logObj.date.toISOString() : logObj.date,
|
|
105
|
+
};
|
|
106
|
+
// Include extra structured args when present.
|
|
107
|
+
if (extra !== undefined) {
|
|
108
|
+
entry.args = extra;
|
|
109
|
+
}
|
|
110
|
+
const line = JSON.stringify(jsonSafe(entry)) + "\n";
|
|
111
|
+
const stream = overrideStream ?? selectStream(logObj.level);
|
|
112
|
+
stream.write(line);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Selects stdout for info+ messages, stderr for error-level. */
|
|
117
|
+
function selectStream(level) {
|
|
118
|
+
if (level <= 1) {
|
|
119
|
+
return process.stderr ?? process.stdout;
|
|
120
|
+
}
|
|
121
|
+
return process.stdout;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Extracts the message string from consola args.
|
|
125
|
+
*
|
|
126
|
+
* Following the upstream sainsburys-tech/next-logger convention: string args
|
|
127
|
+
* are joined with a space. The first non-string arg (object/error) is NOT part
|
|
128
|
+
* of the message — it goes into `args`.
|
|
129
|
+
*/
|
|
130
|
+
function buildMessage(args) {
|
|
131
|
+
const parts = [];
|
|
132
|
+
for (const arg of args) {
|
|
133
|
+
if (typeof arg === "string") {
|
|
134
|
+
parts.push(arg);
|
|
135
|
+
}
|
|
136
|
+
else if (arg instanceof Error) {
|
|
137
|
+
parts.push(arg.message);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
break; // stop at the first non-string, non-error arg
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return parts.join(" ");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Extracts structured arguments beyond the message string — objects, errors,
|
|
147
|
+
* and non-string values that carry diagnostic metadata.
|
|
148
|
+
*
|
|
149
|
+
* Returns `undefined` when there are no extra args (keeps the JSON output clean).
|
|
150
|
+
*/
|
|
151
|
+
function buildExtraArgs(args) {
|
|
152
|
+
const extra = [];
|
|
153
|
+
for (const arg of args) {
|
|
154
|
+
if (typeof arg === "string")
|
|
155
|
+
continue;
|
|
156
|
+
extra.push(arg);
|
|
157
|
+
}
|
|
158
|
+
return extra.length > 0 ? extra : undefined;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/reporters/json.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AAwEH,gDA2BC;AAhGD,0CAA4C;AAE5C;;GAEG;AACH,SAAS,cAAc,CAAC,GAAU;IAChC,MAAM,GAAG,GAA4B;QACnC,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,G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AC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry breadcrumb reporter for consola — mirrors every browser log entry
|
|
3
|
+
* into Sentry as a **breadcrumb**.
|
|
4
|
+
*
|
|
5
|
+
* Breadcrumbs are NOT events — they don't create issues or cost anything on
|
|
6
|
+
* their own. They attach as context to the next real error captured by
|
|
7
|
+
* Sentry, giving you the full log trail that led to a crash.
|
|
8
|
+
*
|
|
9
|
+
* ## Optional dependency
|
|
10
|
+
*
|
|
11
|
+
* `@sentry/nextjs` is an **optional** peer dependency. The reporter resolves
|
|
12
|
+
* it lazily via dynamic `import()` inside `log()`. If the consumer hasn't
|
|
13
|
+
* installed `@sentry/nextjs`, the import rejects, the reporter catches it,
|
|
14
|
+
* and subsequent calls become a silent no-op — the logger keeps working.
|
|
15
|
+
*
|
|
16
|
+
* ## Usage
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // instrumentation-client.ts (or sentry.client.config.ts)
|
|
20
|
+
* import { logger } from "@vsfedorenko/next-logger/browser";
|
|
21
|
+
* import { createSentryBreadcrumbReporter } from "@vsfedorenko/next-logger/reporters/sentry";
|
|
22
|
+
*
|
|
23
|
+
* Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN });
|
|
24
|
+
* logger.addReporter(createSentryBreadcrumbReporter());
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Attach AFTER `Sentry.init` so the lazily-resolved client is ready. Safe to
|
|
28
|
+
* attach unconditionally — `addBreadcrumb` is a no-op when no DSN is set.
|
|
29
|
+
*/
|
|
30
|
+
import type { ConsolaReporter, LogObject } from "consola";
|
|
31
|
+
/**
|
|
32
|
+
* Sentry severity levels, ordered from highest to lowest.
|
|
33
|
+
*
|
|
34
|
+
* Mirrored here (not imported from `@sentry/nextjs`) so this module has **zero
|
|
35
|
+
* static dependency** on Sentry — the type alias is compile-time only and
|
|
36
|
+
* erased in the output.
|
|
37
|
+
*/
|
|
38
|
+
type SeverityLevel = "fatal" | "error" | "warning" | "log" | "info" | "debug";
|
|
39
|
+
/**
|
|
40
|
+
* The shape of a Sentry breadcrumb — the subset of fields this reporter
|
|
41
|
+
* populates. Defined locally to avoid importing from `@sentry/nextjs`.
|
|
42
|
+
*/
|
|
43
|
+
interface SentryBreadcrumb {
|
|
44
|
+
level?: SeverityLevel;
|
|
45
|
+
category?: string;
|
|
46
|
+
message?: string;
|
|
47
|
+
data?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build a Sentry breadcrumb from a consola log object.
|
|
51
|
+
*
|
|
52
|
+
* Pure function — no Sentry dependency, fully testable in isolation.
|
|
53
|
+
*
|
|
54
|
+
* - String arguments and `logObj.message` are joined into `message`.
|
|
55
|
+
* - `Error` instances go into `data` as `{ name, message }` (stack is omitted
|
|
56
|
+
* — breadcrumbs are one-line context, not stack traces).
|
|
57
|
+
* - Plain objects go into `data` keyed by argument position.
|
|
58
|
+
*/
|
|
59
|
+
export declare function logObjectToBreadcrumb(logObj: LogObject): SentryBreadcrumb;
|
|
60
|
+
/**
|
|
61
|
+
* Create a consola reporter that forwards every log entry to
|
|
62
|
+
* `Sentry.addBreadcrumb`.
|
|
63
|
+
*
|
|
64
|
+
* The reporter is safe to attach unconditionally:
|
|
65
|
+
* - `@sentry/nextjs` not installed → silent no-op (cached failed import).
|
|
66
|
+
* - Installed but no DSN configured → `addBreadcrumb` is a no-op internally.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createSentryBreadcrumbReporter(): ConsolaReporter;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/reporters/sentry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;GAMG;AACH,KAAK,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAoB9E;;;GAGG;AACH,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CA0BzE;AA2BD;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,IAAI,eAAe,CAOhE"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sentry breadcrumb reporter for consola — mirrors every browser log entry
|
|
4
|
+
* into Sentry as a **breadcrumb**.
|
|
5
|
+
*
|
|
6
|
+
* Breadcrumbs are NOT events — they don't create issues or cost anything on
|
|
7
|
+
* their own. They attach as context to the next real error captured by
|
|
8
|
+
* Sentry, giving you the full log trail that led to a crash.
|
|
9
|
+
*
|
|
10
|
+
* ## Optional dependency
|
|
11
|
+
*
|
|
12
|
+
* `@sentry/nextjs` is an **optional** peer dependency. The reporter resolves
|
|
13
|
+
* it lazily via dynamic `import()` inside `log()`. If the consumer hasn't
|
|
14
|
+
* installed `@sentry/nextjs`, the import rejects, the reporter catches it,
|
|
15
|
+
* and subsequent calls become a silent no-op — the logger keeps working.
|
|
16
|
+
*
|
|
17
|
+
* ## Usage
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // instrumentation-client.ts (or sentry.client.config.ts)
|
|
21
|
+
* import { logger } from "@vsfedorenko/next-logger/browser";
|
|
22
|
+
* import { createSentryBreadcrumbReporter } from "@vsfedorenko/next-logger/reporters/sentry";
|
|
23
|
+
*
|
|
24
|
+
* Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN });
|
|
25
|
+
* logger.addReporter(createSentryBreadcrumbReporter());
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Attach AFTER `Sentry.init` so the lazily-resolved client is ready. Safe to
|
|
29
|
+
* attach unconditionally — `addBreadcrumb` is a no-op when no DSN is set.
|
|
30
|
+
*/
|
|
31
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
34
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
35
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(o, k2, desc);
|
|
38
|
+
}) : (function(o, m, k, k2) {
|
|
39
|
+
if (k2 === undefined) k2 = k;
|
|
40
|
+
o[k2] = m[k];
|
|
41
|
+
}));
|
|
42
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
43
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
44
|
+
}) : function(o, v) {
|
|
45
|
+
o["default"] = v;
|
|
46
|
+
});
|
|
47
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
48
|
+
var ownKeys = function(o) {
|
|
49
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
50
|
+
var ar = [];
|
|
51
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
return ownKeys(o);
|
|
55
|
+
};
|
|
56
|
+
return function (mod) {
|
|
57
|
+
if (mod && mod.__esModule) return mod;
|
|
58
|
+
var result = {};
|
|
59
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.logObjectToBreadcrumb = logObjectToBreadcrumb;
|
|
66
|
+
exports.createSentryBreadcrumbReporter = createSentryBreadcrumbReporter;
|
|
67
|
+
/**
|
|
68
|
+
* Map consola's numeric level to Sentry's breadcrumb severity.
|
|
69
|
+
*
|
|
70
|
+
* Consola: 0=error/fatal, 1=warn, 2=log, 3=info, 4=debug, 5=trace/verbose.
|
|
71
|
+
*
|
|
72
|
+
* `fatal` and `error` both collapse to Sentry `error` — breadcrumbs are
|
|
73
|
+
* diagnostic context, not standalone error events. Real error capture goes
|
|
74
|
+
* through `captureException` / `onRequestError`.
|
|
75
|
+
*/
|
|
76
|
+
const SEVERITY_MAP = [
|
|
77
|
+
"error", // 0 — error / fatal
|
|
78
|
+
"warning", // 1 — warn
|
|
79
|
+
"log", // 2 — log
|
|
80
|
+
"info", // 3 — info / success / ready
|
|
81
|
+
"debug", // 4 — debug
|
|
82
|
+
"debug", // 5 — trace / verbose
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* Build a Sentry breadcrumb from a consola log object.
|
|
86
|
+
*
|
|
87
|
+
* Pure function — no Sentry dependency, fully testable in isolation.
|
|
88
|
+
*
|
|
89
|
+
* - String arguments and `logObj.message` are joined into `message`.
|
|
90
|
+
* - `Error` instances go into `data` as `{ name, message }` (stack is omitted
|
|
91
|
+
* — breadcrumbs are one-line context, not stack traces).
|
|
92
|
+
* - Plain objects go into `data` keyed by argument position.
|
|
93
|
+
*/
|
|
94
|
+
function logObjectToBreadcrumb(logObj) {
|
|
95
|
+
const level = SEVERITY_MAP[Math.max(0, Math.min(5, logObj.level))] ?? "info";
|
|
96
|
+
const args = logObj.args ?? [];
|
|
97
|
+
const messageParts = [];
|
|
98
|
+
const data = {};
|
|
99
|
+
if (logObj.message)
|
|
100
|
+
messageParts.push(logObj.message);
|
|
101
|
+
for (let i = 0; i < args.length; i++) {
|
|
102
|
+
const arg = args[i];
|
|
103
|
+
if (arg instanceof Error) {
|
|
104
|
+
data[`arg_${i}`] = { name: arg.name, message: arg.message };
|
|
105
|
+
}
|
|
106
|
+
else if (typeof arg === "object" && arg !== null) {
|
|
107
|
+
data[`arg_${i}`] = arg;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
messageParts.push(String(arg));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
level,
|
|
115
|
+
category: logObj.tag || "console",
|
|
116
|
+
message: messageParts.length > 0 ? messageParts.join(" ") : undefined,
|
|
117
|
+
data: Object.keys(data).length > 0 ? data : undefined,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
let sentryPromise = null;
|
|
121
|
+
/**
|
|
122
|
+
* Lazily resolve the `@sentry/nextjs` module.
|
|
123
|
+
*
|
|
124
|
+
* The import is attempted once and cached:
|
|
125
|
+
* - If the consumer has `@sentry/nextjs` installed → resolves to the module.
|
|
126
|
+
* - If not installed → the rejection is caught and `null` is cached, making
|
|
127
|
+
* subsequent `log()` calls a silent no-op without retrying.
|
|
128
|
+
*/
|
|
129
|
+
function getSentry() {
|
|
130
|
+
if (sentryPromise)
|
|
131
|
+
return sentryPromise;
|
|
132
|
+
sentryPromise = Promise.resolve().then(() => __importStar(require("@sentry/nextjs"))).then((mod) => mod)
|
|
133
|
+
.catch(() => null);
|
|
134
|
+
return sentryPromise;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a consola reporter that forwards every log entry to
|
|
138
|
+
* `Sentry.addBreadcrumb`.
|
|
139
|
+
*
|
|
140
|
+
* The reporter is safe to attach unconditionally:
|
|
141
|
+
* - `@sentry/nextjs` not installed → silent no-op (cached failed import).
|
|
142
|
+
* - Installed but no DSN configured → `addBreadcrumb` is a no-op internally.
|
|
143
|
+
*/
|
|
144
|
+
function createSentryBreadcrumbReporter() {
|
|
145
|
+
return {
|
|
146
|
+
log(logObj) {
|
|
147
|
+
const crumb = logObjectToBreadcrumb(logObj);
|
|
148
|
+
void getSentry().then((sentry) => sentry?.addBreadcrumb(crumb));
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=sentry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/reporters/sentry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDH,sDA0BC;AAmCD,wEAOC;AA3GD;;;;;;;;GAQG;AACH,MAAM,YAAY,GAA6B;IAC7C,OAAO,EAAE,oBAAoB;IAC7B,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,6BAA6B;IACrC,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,sBAAsB;CAChC,CAAC;AAaF;;;;;;;;;GASG;AACH,SAAgB,qBAAqB,CAAC,MAAiB;IACrD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;IAE7E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,IAAI,GAA4B,EAAE,CAAC;IAEzC,IAAI,MAAM,CAAC,OAAO;QAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CA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AAG,CAAC,MAAiB;YACnB,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;YAC5C,KAAK,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;QAClE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central type definitions for @vsfedorenko/next-logger.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports consola's core types so consumers don't need to depend on consola
|
|
5
|
+
* directly for type-only imports, and defines the shape of the Next.js log
|
|
6
|
+
* module we patch.
|
|
7
|
+
*/
|
|
8
|
+
import type { ConsolaInstance } from "consola";
|
|
9
|
+
/**
|
|
10
|
+
* A variadic log function — the common shape shared by `console.*`,
|
|
11
|
+
* consola's `LogFn`, and Next.js' log methods. Accepts any arguments
|
|
12
|
+
* (strings, objects, errors, mixed) and returns void.
|
|
13
|
+
*/
|
|
14
|
+
export type LogFunction = (...args: unknown[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* A Next.js log method signature. Identical to {@link LogFunction} but named
|
|
17
|
+
* to document that it matches the methods exported by
|
|
18
|
+
* `next/dist/build/output/log`.
|
|
19
|
+
*/
|
|
20
|
+
export type NextLogFn = (...args: unknown[]) => void;
|
|
21
|
+
/**
|
|
22
|
+
* The shape of `next/dist/build/output/log` that we patch.
|
|
23
|
+
*
|
|
24
|
+
* Based on the actual exports of Next.js 13+ (see
|
|
25
|
+
* `next/dist/build/output/log.d.ts`):
|
|
26
|
+
*
|
|
27
|
+
* - `prefixes` — a record mapping each method name to its coloured
|
|
28
|
+
* symbol (○ ⨯ ⚠ ▲ etc.).
|
|
29
|
+
* - `wait`/`error`/`warn`/`ready`/`info`/`event`/`trace` — the prefix-based
|
|
30
|
+
* log methods we replace.
|
|
31
|
+
* - `bootstrap` — a raw `console.log` (single `message` string, no prefix).
|
|
32
|
+
* - `warnOnce`/`errorOnce` — deduplicating wrappers (optional — older
|
|
33
|
+
* Next versions don't export them).
|
|
34
|
+
*/
|
|
35
|
+
export interface NextLogModule {
|
|
36
|
+
readonly prefixes: Record<string, string>;
|
|
37
|
+
wait: NextLogFn;
|
|
38
|
+
error: NextLogFn;
|
|
39
|
+
warn: NextLogFn;
|
|
40
|
+
ready: NextLogFn;
|
|
41
|
+
info: NextLogFn;
|
|
42
|
+
event: NextLogFn;
|
|
43
|
+
trace: NextLogFn;
|
|
44
|
+
bootstrap: (message: string) => void;
|
|
45
|
+
warnOnce?: NextLogFn;
|
|
46
|
+
errorOnce?: NextLogFn;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type guard: narrows `unknown` to {@link ConsolaInstance} by checking for the
|
|
50
|
+
* two methods both patches depend on (`.withTag()` + `.log()`).
|
|
51
|
+
*
|
|
52
|
+
* Used when resolving a config file's `consola` key — the value may be a
|
|
53
|
+
* partial options object, a factory, or a fully built instance.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isConsolaInstance(value: unknown): value is ConsolaInstance;
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAO1E"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Central type definitions for @vsfedorenko/next-logger.
|
|
4
|
+
*
|
|
5
|
+
* Re-exports consola's core types so consumers don't need to depend on consola
|
|
6
|
+
* directly for type-only imports, and defines the shape of the Next.js log
|
|
7
|
+
* module we patch.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.isConsolaInstance = isConsolaInstance;
|
|
11
|
+
/**
|
|
12
|
+
* Type guard: narrows `unknown` to {@link ConsolaInstance} by checking for the
|
|
13
|
+
* two methods both patches depend on (`.withTag()` + `.log()`).
|
|
14
|
+
*
|
|
15
|
+
* Used when resolving a config file's `consola` key — the value may be a
|
|
16
|
+
* partial options object, a factory, or a fully built instance.
|
|
17
|
+
*/
|
|
18
|
+
function isConsolaInstance(value) {
|
|
19
|
+
return (typeof value === "object" &&
|
|
20
|
+
value !== null &&
|
|
21
|
+
typeof value.withTag === "function" &&
|
|
22
|
+
typeof value.log === "function");
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAqDH,8CAOC;AAdD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAyB,CAAC,OAAO,KAAK,UAAU;QACxD,OAAQ,KAAyB,CAAC,GAAG,KAAK,UAAU,CACrD,CAAC;AACJ,CAAC"}
|