@eventuras/logger 0.7.1 → 0.8.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 +70 -12
- package/dist/Logger-n-HsscG5.js +314 -0
- package/dist/Logger-n-HsscG5.js.map +1 -0
- package/dist/Logger.d.ts +3 -3
- package/dist/Logger.d.ts.map +1 -1
- package/dist/index.js +34 -219
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +21 -7
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +196 -2
- package/dist/node.js.map +1 -0
- package/dist/opentelemetry.d.ts.map +1 -1
- package/dist/opentelemetry.js +140 -26
- package/dist/opentelemetry.js.map +1 -0
- package/dist/transports/pino.d.ts +14 -2
- package/dist/transports/pino.d.ts.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/chunk-NnHqS4_Y.js +0 -20
- package/dist/esm-CIhYjsQQ.js +0 -528
- package/dist/esm-Dido2CZe.js +0 -1580
- package/dist/pretty-sMlW_evX.js +0 -114
- package/dist/src-15l0SmY8.js +0 -407
package/dist/index.js
CHANGED
|
@@ -1,212 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
level: n.level ?? "info",
|
|
9
|
-
timestamp: t.stdTimeFunctions.isoTime,
|
|
10
|
-
formatters: { level: (e) => ({ level: e }) },
|
|
11
|
-
...n.redact && { redact: {
|
|
12
|
-
paths: n.redact,
|
|
13
|
-
censor: "[REDACTED]"
|
|
14
|
-
} },
|
|
15
|
-
...n.pinoOptions
|
|
16
|
-
};
|
|
17
|
-
n.prettyPrint ? this.pino = t(r, e()) : n.destination ? this.pino = t(r, t.destination(n.destination)) : this.pino = t(r);
|
|
18
|
-
}
|
|
19
|
-
log(e, t, n) {
|
|
20
|
-
n ? this.pino[e](t, n) : this.pino[e](t);
|
|
21
|
-
}
|
|
22
|
-
child(e) {
|
|
23
|
-
return new r(this.pino.child(e));
|
|
24
|
-
}
|
|
25
|
-
async flush() {
|
|
26
|
-
this.pino.flush();
|
|
27
|
-
}
|
|
28
|
-
}, r = class e {
|
|
29
|
-
constructor(e) {
|
|
30
|
-
this.pinoChild = e;
|
|
31
|
-
}
|
|
32
|
-
log(e, t, n) {
|
|
33
|
-
n ? this.pinoChild[e](t, n) : this.pinoChild[e](t);
|
|
34
|
-
}
|
|
35
|
-
child(t) {
|
|
36
|
-
return new e(this.pinoChild.child(t));
|
|
37
|
-
}
|
|
38
|
-
async flush() {
|
|
39
|
-
this.pinoChild.flush();
|
|
40
|
-
}
|
|
41
|
-
}, i = {
|
|
42
|
-
trace: "debug",
|
|
43
|
-
debug: "debug",
|
|
44
|
-
info: "log",
|
|
45
|
-
warn: "warn",
|
|
46
|
-
error: "error",
|
|
47
|
-
fatal: "error"
|
|
48
|
-
}, a = class e {
|
|
49
|
-
bindings;
|
|
50
|
-
constructor(e) {
|
|
51
|
-
this.bindings = e ?? {};
|
|
52
|
-
}
|
|
53
|
-
log(e, t, n) {
|
|
54
|
-
let r = i[e], a = {
|
|
55
|
-
...this.bindings,
|
|
56
|
-
...t
|
|
57
|
-
}, o = Object.keys(a).length > 0;
|
|
58
|
-
n && o ? console[r](`[${e}]`, n, a) : n ? console[r](`[${e}]`, n) : o && console[r](`[${e}]`, a);
|
|
59
|
-
}
|
|
60
|
-
child(t) {
|
|
61
|
-
return new e({
|
|
62
|
-
...this.bindings,
|
|
63
|
-
...t
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}, o = [
|
|
67
|
-
"password",
|
|
68
|
-
"token",
|
|
69
|
-
"apiKey",
|
|
70
|
-
"authorization",
|
|
71
|
-
"secret"
|
|
72
|
-
];
|
|
73
|
-
function s(e) {
|
|
74
|
-
if (typeof globalThis < "u" && typeof globalThis.process == "object") return globalThis.process.env[e];
|
|
75
|
-
}
|
|
76
|
-
function c() {
|
|
77
|
-
try {
|
|
78
|
-
return typeof process < "u" && typeof process.versions?.node == "string";
|
|
79
|
-
} catch {
|
|
80
|
-
return !1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function l(e) {
|
|
84
|
-
return c() ? new n({
|
|
85
|
-
level: e.level ?? s("LOG_LEVEL") ?? "info",
|
|
86
|
-
redact: e.redact ?? o,
|
|
87
|
-
prettyPrint: e.prettyPrint ?? s("NODE_ENV") === "development",
|
|
88
|
-
destination: e.destination
|
|
89
|
-
}) : new a();
|
|
90
|
-
}
|
|
91
|
-
var u = class e {
|
|
92
|
-
static transport;
|
|
93
|
-
static config = {};
|
|
94
|
-
options;
|
|
95
|
-
childTransport;
|
|
96
|
-
static {
|
|
97
|
-
e.transport = l(e.config);
|
|
98
|
-
}
|
|
99
|
-
constructor(t = {}) {
|
|
100
|
-
if (this.options = t, t.context || t.correlationId || t.namespace) {
|
|
101
|
-
let n = {
|
|
102
|
-
...t.namespace && { namespace: t.namespace },
|
|
103
|
-
...t.correlationId && { correlationId: t.correlationId },
|
|
104
|
-
...t.context
|
|
105
|
-
};
|
|
106
|
-
this.childTransport = e.transport.child(n);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
static configure(t) {
|
|
110
|
-
e.config = {
|
|
111
|
-
...e.config,
|
|
112
|
-
...t
|
|
113
|
-
}, e.transport = e.config.transport ?? l(e.config), e.rebindStaticMethods();
|
|
114
|
-
}
|
|
115
|
-
static getTransport() {
|
|
116
|
-
return e.transport;
|
|
117
|
-
}
|
|
118
|
-
static getPinoInstance() {
|
|
119
|
-
if (e.transport instanceof n) return e.transport.pino;
|
|
120
|
-
throw Error("getPinoInstance() requires PinoTransport. Use Logger.getTransport() for the active transport.");
|
|
121
|
-
}
|
|
122
|
-
static normalizeArgs(e, t) {
|
|
123
|
-
return typeof e == "string" ? [{}, [e, ...t]] : [e, t];
|
|
124
|
-
}
|
|
125
|
-
static isDevelopment() {
|
|
126
|
-
return s("NODE_ENV") === "development";
|
|
127
|
-
}
|
|
128
|
-
static formatError(e) {
|
|
129
|
-
return e instanceof Error ? `${e.name}: ${e.message}\nStack: ${e.stack}` : String(e);
|
|
130
|
-
}
|
|
131
|
-
static buildLogData(e) {
|
|
132
|
-
return {
|
|
133
|
-
...e.namespace && { namespace: e.namespace },
|
|
134
|
-
...e.correlationId && { correlationId: e.correlationId },
|
|
135
|
-
...e.context
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
static staticLog(t, n, ...r) {
|
|
139
|
-
if (n.developerOnly && !e.isDevelopment()) return;
|
|
140
|
-
let i = e.buildLogData(n);
|
|
141
|
-
e.transport.log(t, {
|
|
142
|
-
...i,
|
|
143
|
-
msg: r
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
static staticErrorLog(t, n, ...r) {
|
|
147
|
-
if (n.developerOnly && !e.isDevelopment()) return;
|
|
148
|
-
let i = n.error ? { error: e.formatError(n.error) } : {}, a = {
|
|
149
|
-
...e.buildLogData(n),
|
|
150
|
-
...i
|
|
151
|
-
};
|
|
152
|
-
e.transport.log(t, {
|
|
153
|
-
...a,
|
|
154
|
-
msg: r
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
static info(t, ...n) {
|
|
158
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
159
|
-
e.staticLog("info", r, ...i);
|
|
160
|
-
}
|
|
161
|
-
static debug(t, ...n) {
|
|
162
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
163
|
-
e.staticLog("debug", r, ...i);
|
|
164
|
-
}
|
|
165
|
-
static trace(t, ...n) {
|
|
166
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
167
|
-
e.staticLog("trace", r, ...i);
|
|
168
|
-
}
|
|
169
|
-
static warn(t, ...n) {
|
|
170
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
171
|
-
e.staticLog("warn", r, ...i);
|
|
172
|
-
}
|
|
173
|
-
static error(t, ...n) {
|
|
174
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
175
|
-
e.staticErrorLog("error", r, ...i);
|
|
176
|
-
}
|
|
177
|
-
static fatal(t, ...n) {
|
|
178
|
-
let [r, i] = e.normalizeArgs(t, n);
|
|
179
|
-
e.staticErrorLog("fatal", r, ...i);
|
|
180
|
-
}
|
|
181
|
-
static rebindStaticMethods() {}
|
|
182
|
-
static create(t = {}) {
|
|
183
|
-
return new e(t);
|
|
184
|
-
}
|
|
185
|
-
logInstance(t, n, r) {
|
|
186
|
-
let i = this.childTransport ?? e.transport;
|
|
187
|
-
typeof n == "string" ? i.log(t, {}, n) : r ? i.log(t, n ?? {}, r) : i.log(t, n ?? {});
|
|
188
|
-
}
|
|
189
|
-
trace(e, t) {
|
|
190
|
-
this.logInstance("trace", e, t);
|
|
191
|
-
}
|
|
192
|
-
debug(e, t) {
|
|
193
|
-
this.logInstance("debug", e, t);
|
|
194
|
-
}
|
|
195
|
-
info(e, t) {
|
|
196
|
-
this.logInstance("info", e, t);
|
|
197
|
-
}
|
|
198
|
-
warn(e, t) {
|
|
199
|
-
this.logInstance("warn", e, t);
|
|
200
|
-
}
|
|
201
|
-
error(t, n) {
|
|
202
|
-
let r = this.childTransport ?? e.transport;
|
|
203
|
-
typeof t == "string" ? r.log("error", {}, t) : t instanceof Error ? r.log("error", { error: t }, n) : n ? r.log("error", t ?? {}, n) : r.log("error", t ?? {});
|
|
204
|
-
}
|
|
205
|
-
fatal(t, n) {
|
|
206
|
-
let r = this.childTransport ?? e.transport;
|
|
207
|
-
typeof t == "string" ? r.log("fatal", {}, t) : t instanceof Error ? r.log("fatal", { error: t }, n) : n ? r.log("fatal", t ?? {}, n) : r.log("fatal", t ?? {});
|
|
208
|
-
}
|
|
209
|
-
}, d = [
|
|
1
|
+
import { n as ConsoleTransport, r as PinoTransport, t as Logger } from "./Logger-n-HsscG5.js";
|
|
2
|
+
//#region src/httpLogger.ts
|
|
3
|
+
/**
|
|
4
|
+
* HTTP logging utilities for API clients.
|
|
5
|
+
* Provides header redaction for structured logging.
|
|
6
|
+
*/
|
|
7
|
+
var SENSITIVE_HEADERS = [
|
|
210
8
|
"authorization",
|
|
211
9
|
"cookie",
|
|
212
10
|
"set-cookie",
|
|
@@ -214,15 +12,32 @@ var u = class e {
|
|
|
214
12
|
"x-auth-token",
|
|
215
13
|
"proxy-authorization"
|
|
216
14
|
];
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Redact sensitive headers for logging.
|
|
17
|
+
* Use with logger.debug/info/error to safely log HTTP headers.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* logger.debug({
|
|
21
|
+
* request: {
|
|
22
|
+
* url: '/api/users',
|
|
23
|
+
* headers: redactHeaders(headers)
|
|
24
|
+
* }
|
|
25
|
+
* }, 'HTTP request');
|
|
26
|
+
*/
|
|
27
|
+
function redactHeaders(headers) {
|
|
28
|
+
const result = {};
|
|
29
|
+
if (headers instanceof Headers) headers.forEach((value, key) => {
|
|
30
|
+
result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "[REDACTED]" : value;
|
|
31
|
+
});
|
|
32
|
+
else if (Array.isArray(headers)) headers.forEach(([key, value]) => {
|
|
33
|
+
result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "[REDACTED]" : String(value);
|
|
34
|
+
});
|
|
35
|
+
else Object.entries(headers).forEach(([key, value]) => {
|
|
36
|
+
result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? "[REDACTED]" : String(value);
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
226
39
|
}
|
|
227
40
|
//#endregion
|
|
228
|
-
export {
|
|
41
|
+
export { ConsoleTransport, Logger, PinoTransport, redactHeaders };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/httpLogger.ts"],"sourcesContent":["/**\n * HTTP logging utilities for API clients.\n * Provides header redaction for structured logging.\n */\n\nconst SENSITIVE_HEADERS = [\n 'authorization',\n 'cookie',\n 'set-cookie',\n 'x-api-key',\n 'x-auth-token',\n 'proxy-authorization',\n];\n\n/**\n * Redact sensitive headers for logging.\n * Use with logger.debug/info/error to safely log HTTP headers.\n *\n * @example\n * logger.debug({\n * request: {\n * url: '/api/users',\n * headers: redactHeaders(headers)\n * }\n * }, 'HTTP request');\n */\nexport function redactHeaders(\n headers: Headers | Record<string, unknown> | [string, string][],\n): Record<string, string> {\n const result: Record<string, string> = {};\n\n if (headers instanceof Headers) {\n headers.forEach((value: string, key: string) => {\n result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? '[REDACTED]' : value;\n });\n } else if (Array.isArray(headers)) {\n headers.forEach(([key, value]) => {\n result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? '[REDACTED]' : String(value);\n });\n } else {\n Object.entries(headers).forEach(([key, value]) => {\n result[key] = SENSITIVE_HEADERS.includes(key.toLowerCase()) ? '[REDACTED]' : String(value);\n });\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAKA,IAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;;AAcD,SAAgB,cACd,SACwB;CACxB,MAAM,SAAiC,EAAE;AAEzC,KAAI,mBAAmB,QACrB,SAAQ,SAAS,OAAe,QAAgB;AAC9C,SAAO,OAAO,kBAAkB,SAAS,IAAI,aAAa,CAAC,GAAG,eAAe;GAC7E;UACO,MAAM,QAAQ,QAAQ,CAC/B,SAAQ,SAAS,CAAC,KAAK,WAAW;AAChC,SAAO,OAAO,kBAAkB,SAAS,IAAI,aAAa,CAAC,GAAG,eAAe,OAAO,MAAM;GAC1F;KAEF,QAAO,QAAQ,QAAQ,CAAC,SAAS,CAAC,KAAK,WAAW;AAChD,SAAO,OAAO,kBAAkB,SAAS,IAAI,aAAa,CAAC,GAAG,eAAe,OAAO,MAAM;GAC1F;AAGJ,QAAO"}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
import { PinoTransportOptions } from './transports/pino';
|
|
2
|
+
import { LoggerConfig } from './types';
|
|
3
|
+
export { formatLogLine, createPrettyStream } from './transports/pretty';
|
|
4
|
+
/** Options for `configureNodeLogger`. */
|
|
5
|
+
export type NodeLoggerOptions = Omit<LoggerConfig, 'transport'> & {
|
|
6
|
+
/** Enable human-readable, ANSI-colored output. Off by default. */
|
|
7
|
+
prettyPrint?: boolean;
|
|
8
|
+
/** Raw PinoTransport options for advanced tuning. */
|
|
9
|
+
pinoOptions?: PinoTransportOptions['pinoOptions'];
|
|
10
|
+
};
|
|
1
11
|
/**
|
|
2
|
-
* Node
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* (`@eventuras/logger`) for the browser-safe API.
|
|
12
|
+
* Configure the global Logger with a Node-side PinoTransport, optionally
|
|
13
|
+
* wired to a pretty-print stream for development. Keeps the browser/edge
|
|
14
|
+
* main entry free of `node:stream` imports — call this from a Node-only
|
|
15
|
+
* bootstrap (e.g. `instrumentation.ts`, `server.ts`).
|
|
7
16
|
*
|
|
8
17
|
* @example
|
|
9
|
-
*
|
|
18
|
+
* // In your server entry point
|
|
19
|
+
* import { configureNodeLogger } from '@eventuras/logger/node';
|
|
20
|
+
* configureNodeLogger({
|
|
21
|
+
* level: 'debug',
|
|
22
|
+
* prettyPrint: process.env.NODE_ENV === 'development',
|
|
23
|
+
* });
|
|
10
24
|
*/
|
|
11
|
-
export
|
|
25
|
+
export declare function configureNodeLogger(options?: NodeLoggerOptions): void;
|
|
12
26
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAExE,yCAAyC;AACzC,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;IAChE,kEAAkE;IAClE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qDAAqD;IACrD,WAAW,CAAC,EAAE,oBAAoB,CAAC,aAAa,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAYzE"}
|
package/dist/node.js
CHANGED
|
@@ -1,2 +1,196 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as PinoTransport, t as Logger } from "./Logger-n-HsscG5.js";
|
|
2
|
+
import { Writable } from "node:stream";
|
|
3
|
+
//#region src/transports/pretty.ts
|
|
4
|
+
/**
|
|
5
|
+
* Lightweight pretty-print formatter for development.
|
|
6
|
+
* Zero external dependencies — uses ANSI colors and simple formatting.
|
|
7
|
+
*
|
|
8
|
+
* Produces output like:
|
|
9
|
+
* 12:34:56 INFO (web:auth) → User logged in
|
|
10
|
+
* 12:34:56 ERROR (web:auth) → Failed to authenticate { error: "invalid token" }
|
|
11
|
+
*/
|
|
12
|
+
var ANSI = {
|
|
13
|
+
reset: "\x1B[0m",
|
|
14
|
+
dim: "\x1B[2m",
|
|
15
|
+
bold: "\x1B[1m",
|
|
16
|
+
red: "\x1B[31m",
|
|
17
|
+
yellow: "\x1B[33m",
|
|
18
|
+
green: "\x1B[32m",
|
|
19
|
+
cyan: "\x1B[36m",
|
|
20
|
+
magenta: "\x1B[35m",
|
|
21
|
+
gray: "\x1B[90m"
|
|
22
|
+
};
|
|
23
|
+
var LEVEL_BY_NUMBER = {
|
|
24
|
+
10: {
|
|
25
|
+
label: "TRACE",
|
|
26
|
+
color: ANSI.gray
|
|
27
|
+
},
|
|
28
|
+
20: {
|
|
29
|
+
label: "DEBUG",
|
|
30
|
+
color: ANSI.cyan
|
|
31
|
+
},
|
|
32
|
+
30: {
|
|
33
|
+
label: "INFO ",
|
|
34
|
+
color: ANSI.green
|
|
35
|
+
},
|
|
36
|
+
40: {
|
|
37
|
+
label: "WARN ",
|
|
38
|
+
color: ANSI.yellow
|
|
39
|
+
},
|
|
40
|
+
50: {
|
|
41
|
+
label: "ERROR",
|
|
42
|
+
color: ANSI.red
|
|
43
|
+
},
|
|
44
|
+
60: {
|
|
45
|
+
label: "FATAL",
|
|
46
|
+
color: `${ANSI.bold}${ANSI.red}`
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var LEVEL_BY_NAME = {
|
|
50
|
+
trace: {
|
|
51
|
+
label: "TRACE",
|
|
52
|
+
color: ANSI.gray
|
|
53
|
+
},
|
|
54
|
+
debug: {
|
|
55
|
+
label: "DEBUG",
|
|
56
|
+
color: ANSI.cyan
|
|
57
|
+
},
|
|
58
|
+
info: {
|
|
59
|
+
label: "INFO ",
|
|
60
|
+
color: ANSI.green
|
|
61
|
+
},
|
|
62
|
+
warn: {
|
|
63
|
+
label: "WARN ",
|
|
64
|
+
color: ANSI.yellow
|
|
65
|
+
},
|
|
66
|
+
error: {
|
|
67
|
+
label: "ERROR",
|
|
68
|
+
color: ANSI.red
|
|
69
|
+
},
|
|
70
|
+
fatal: {
|
|
71
|
+
label: "FATAL",
|
|
72
|
+
color: `${ANSI.bold}${ANSI.red}`
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/** Keys excluded from the "extra data" output. */
|
|
76
|
+
var INTERNAL_KEYS = new Set([
|
|
77
|
+
"level",
|
|
78
|
+
"time",
|
|
79
|
+
"pid",
|
|
80
|
+
"hostname",
|
|
81
|
+
"msg",
|
|
82
|
+
"name",
|
|
83
|
+
"ns",
|
|
84
|
+
"namespace"
|
|
85
|
+
]);
|
|
86
|
+
function formatTime(time) {
|
|
87
|
+
if (typeof time === "string") {
|
|
88
|
+
const d = new Date(time);
|
|
89
|
+
return Number.isNaN(d.getTime()) ? "" : d.toLocaleTimeString("en-GB", { hour12: false });
|
|
90
|
+
}
|
|
91
|
+
if (typeof time === "number") return new Date(time).toLocaleTimeString("en-GB", { hour12: false });
|
|
92
|
+
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: false });
|
|
93
|
+
}
|
|
94
|
+
function formatData(obj) {
|
|
95
|
+
const filtered = {};
|
|
96
|
+
let hasKeys = false;
|
|
97
|
+
for (const [key, value] of Object.entries(obj)) if (!INTERNAL_KEYS.has(key)) {
|
|
98
|
+
filtered[key] = value;
|
|
99
|
+
hasKeys = true;
|
|
100
|
+
}
|
|
101
|
+
if (!hasKeys) return "";
|
|
102
|
+
return ` ${ANSI.dim}${JSON.stringify(filtered)}${ANSI.reset}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Format a Pino JSON log line into a human-readable string.
|
|
106
|
+
* @param line Raw JSON string from Pino
|
|
107
|
+
* @returns Formatted string, or the original line if parsing fails
|
|
108
|
+
*/
|
|
109
|
+
function formatLogLine(line) {
|
|
110
|
+
const trimmed = line.trim();
|
|
111
|
+
if (!trimmed) return "";
|
|
112
|
+
let obj;
|
|
113
|
+
try {
|
|
114
|
+
obj = JSON.parse(trimmed);
|
|
115
|
+
} catch {
|
|
116
|
+
return trimmed;
|
|
117
|
+
}
|
|
118
|
+
const level = obj.level;
|
|
119
|
+
const config = typeof level === "string" ? LEVEL_BY_NAME[level] ?? {
|
|
120
|
+
label: level.toUpperCase().padEnd(5),
|
|
121
|
+
color: ANSI.gray
|
|
122
|
+
} : LEVEL_BY_NUMBER[level] ?? {
|
|
123
|
+
label: `L${level}`,
|
|
124
|
+
color: ANSI.gray
|
|
125
|
+
};
|
|
126
|
+
const time = formatTime(obj.time);
|
|
127
|
+
const msg = obj.msg ?? "";
|
|
128
|
+
const ns = obj.namespace || obj.ns || obj.name || "";
|
|
129
|
+
const nsTag = ns ? ` ${ANSI.magenta}(${ns})${ANSI.reset}` : "";
|
|
130
|
+
const arrow = `${ANSI.dim}→${ANSI.reset}`;
|
|
131
|
+
const data = formatData(obj);
|
|
132
|
+
return `${ANSI.dim}${time}${ANSI.reset} ${config.color}${config.label}${ANSI.reset}${nsTag} ${arrow} ${msg}${data}`;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a Node.js writable stream that formats Pino JSON output.
|
|
136
|
+
* Used as the destination for PinoTransport when prettyPrint is enabled.
|
|
137
|
+
*/
|
|
138
|
+
function createPrettyStream() {
|
|
139
|
+
return new Writable({ write(chunk, _encoding, callback) {
|
|
140
|
+
const lines = chunk.toString().split("\n");
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
const formatted = formatLogLine(line);
|
|
143
|
+
if (formatted) process.stdout.write(formatted + "\n");
|
|
144
|
+
}
|
|
145
|
+
callback();
|
|
146
|
+
} });
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/node.ts
|
|
150
|
+
/**
|
|
151
|
+
* Node.js-only exports for @eventuras/logger.
|
|
152
|
+
*
|
|
153
|
+
* These utilities depend on `node:stream` and must not be imported in browser
|
|
154
|
+
* or edge runtime environments. Import from the root entry point
|
|
155
|
+
* (`@eventuras/logger`) for the browser-safe API.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* // Pretty dev output
|
|
159
|
+
* import { configureNodeLogger } from '@eventuras/logger/node';
|
|
160
|
+
* configureNodeLogger({ prettyPrint: process.env.NODE_ENV === 'development' });
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* // Lower-level: just the pretty helpers
|
|
164
|
+
* import { createPrettyStream, formatLogLine } from '@eventuras/logger/node';
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* Configure the global Logger with a Node-side PinoTransport, optionally
|
|
168
|
+
* wired to a pretty-print stream for development. Keeps the browser/edge
|
|
169
|
+
* main entry free of `node:stream` imports — call this from a Node-only
|
|
170
|
+
* bootstrap (e.g. `instrumentation.ts`, `server.ts`).
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* // In your server entry point
|
|
174
|
+
* import { configureNodeLogger } from '@eventuras/logger/node';
|
|
175
|
+
* configureNodeLogger({
|
|
176
|
+
* level: 'debug',
|
|
177
|
+
* prettyPrint: process.env.NODE_ENV === 'development',
|
|
178
|
+
* });
|
|
179
|
+
*/
|
|
180
|
+
function configureNodeLogger(options = {}) {
|
|
181
|
+
const { prettyPrint, pinoOptions, ...rest } = options;
|
|
182
|
+
Logger.configure({
|
|
183
|
+
...rest,
|
|
184
|
+
transport: new PinoTransport({
|
|
185
|
+
level: rest.level,
|
|
186
|
+
redact: rest.redact,
|
|
187
|
+
destination: rest.destination,
|
|
188
|
+
destinationStream: prettyPrint ? createPrettyStream() : void 0,
|
|
189
|
+
pinoOptions
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { configureNodeLogger, createPrettyStream, formatLogLine };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":[],"sources":["../src/transports/pretty.ts","../src/node.ts"],"sourcesContent":["/**\n * Lightweight pretty-print formatter for development.\n * Zero external dependencies — uses ANSI colors and simple formatting.\n *\n * Produces output like:\n * 12:34:56 INFO (web:auth) → User logged in\n * 12:34:56 ERROR (web:auth) → Failed to authenticate { error: \"invalid token\" }\n */\n\nimport { Writable } from 'node:stream';\n\nconst ANSI = {\n reset: '\\x1b[0m',\n dim: '\\x1b[2m',\n bold: '\\x1b[1m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n green: '\\x1b[32m',\n cyan: '\\x1b[36m',\n magenta: '\\x1b[35m',\n gray: '\\x1b[90m',\n} as const;\n\nconst LEVEL_BY_NUMBER: Record<number, { label: string; color: string; }> = {\n 10: { label: 'TRACE', color: ANSI.gray },\n 20: { label: 'DEBUG', color: ANSI.cyan },\n 30: { label: 'INFO ', color: ANSI.green },\n 40: { label: 'WARN ', color: ANSI.yellow },\n 50: { label: 'ERROR', color: ANSI.red },\n 60: { label: 'FATAL', color: `${ANSI.bold}${ANSI.red}` },\n};\n\nconst LEVEL_BY_NAME: Record<string, { label: string; color: string; }> = {\n trace: { label: 'TRACE', color: ANSI.gray },\n debug: { label: 'DEBUG', color: ANSI.cyan },\n info: { label: 'INFO ', color: ANSI.green },\n warn: { label: 'WARN ', color: ANSI.yellow },\n error: { label: 'ERROR', color: ANSI.red },\n fatal: { label: 'FATAL', color: `${ANSI.bold}${ANSI.red}` },\n};\n\n/** Keys excluded from the \"extra data\" output. */\nconst INTERNAL_KEYS = new Set([\n 'level', 'time', 'pid', 'hostname', 'msg', 'name', 'ns', 'namespace',\n]);\n\nfunction formatTime(time: unknown): string {\n if (typeof time === 'string') {\n // ISO string — extract time portion\n const d = new Date(time);\n return Number.isNaN(d.getTime()) ? '' : d.toLocaleTimeString('en-GB', { hour12: false });\n }\n if (typeof time === 'number') {\n return new Date(time).toLocaleTimeString('en-GB', { hour12: false });\n }\n return new Date().toLocaleTimeString('en-GB', { hour12: false });\n}\n\nfunction formatData(obj: Record<string, unknown>): string {\n const filtered: Record<string, unknown> = {};\n let hasKeys = false;\n\n for (const [key, value] of Object.entries(obj)) {\n if (!INTERNAL_KEYS.has(key)) {\n filtered[key] = value;\n hasKeys = true;\n }\n }\n\n if (!hasKeys) return '';\n return ` ${ANSI.dim}${JSON.stringify(filtered)}${ANSI.reset}`;\n}\n\n/**\n * Format a Pino JSON log line into a human-readable string.\n * @param line Raw JSON string from Pino\n * @returns Formatted string, or the original line if parsing fails\n */\nexport function formatLogLine(line: string): string {\n const trimmed = line.trim();\n if (!trimmed) return '';\n\n let obj: Record<string, unknown>;\n try {\n obj = JSON.parse(trimmed);\n } catch {\n return trimmed;\n }\n\n const level = obj.level;\n const config = typeof level === 'string'\n ? LEVEL_BY_NAME[level] ?? { label: level.toUpperCase().padEnd(5), color: ANSI.gray }\n : LEVEL_BY_NUMBER[level as number] ?? { label: `L${level}`, color: ANSI.gray };\n const time = formatTime(obj.time);\n const msg = (obj.msg as string) ?? '';\n const ns = (obj.namespace as string) || (obj.ns as string) || (obj.name as string) || '';\n\n const nsTag = ns ? ` ${ANSI.magenta}(${ns})${ANSI.reset}` : '';\n const arrow = `${ANSI.dim}→${ANSI.reset}`;\n const data = formatData(obj);\n\n return `${ANSI.dim}${time}${ANSI.reset} ${config.color}${config.label}${ANSI.reset}${nsTag} ${arrow} ${msg}${data}`;\n}\n\n/**\n * Creates a Node.js writable stream that formats Pino JSON output.\n * Used as the destination for PinoTransport when prettyPrint is enabled.\n */\nexport function createPrettyStream(): NodeJS.WritableStream {\n return new Writable({\n write(chunk: Buffer, _encoding: string, callback: () => void) {\n const lines = chunk.toString().split('\\n');\n for (const line of lines) {\n const formatted = formatLogLine(line);\n if (formatted) {\n process.stdout.write(formatted + '\\n');\n }\n }\n callback();\n },\n });\n}\n","/**\n * Node.js-only exports for @eventuras/logger.\n *\n * These utilities depend on `node:stream` and must not be imported in browser\n * or edge runtime environments. Import from the root entry point\n * (`@eventuras/logger`) for the browser-safe API.\n *\n * @example\n * // Pretty dev output\n * import { configureNodeLogger } from '@eventuras/logger/node';\n * configureNodeLogger({ prettyPrint: process.env.NODE_ENV === 'development' });\n *\n * @example\n * // Lower-level: just the pretty helpers\n * import { createPrettyStream, formatLogLine } from '@eventuras/logger/node';\n */\nimport { Logger } from './Logger';\nimport { PinoTransport, type PinoTransportOptions } from './transports/pino';\nimport { createPrettyStream } from './transports/pretty';\nimport type { LoggerConfig } from './types';\n\nexport { formatLogLine, createPrettyStream } from './transports/pretty';\n\n/** Options for `configureNodeLogger`. */\nexport type NodeLoggerOptions = Omit<LoggerConfig, 'transport'> & {\n /** Enable human-readable, ANSI-colored output. Off by default. */\n prettyPrint?: boolean;\n /** Raw PinoTransport options for advanced tuning. */\n pinoOptions?: PinoTransportOptions['pinoOptions'];\n};\n\n/**\n * Configure the global Logger with a Node-side PinoTransport, optionally\n * wired to a pretty-print stream for development. Keeps the browser/edge\n * main entry free of `node:stream` imports — call this from a Node-only\n * bootstrap (e.g. `instrumentation.ts`, `server.ts`).\n *\n * @example\n * // In your server entry point\n * import { configureNodeLogger } from '@eventuras/logger/node';\n * configureNodeLogger({\n * level: 'debug',\n * prettyPrint: process.env.NODE_ENV === 'development',\n * });\n */\nexport function configureNodeLogger(options: NodeLoggerOptions = {}): void {\n const { prettyPrint, pinoOptions, ...rest } = options;\n Logger.configure({\n ...rest,\n transport: new PinoTransport({\n level: rest.level,\n redact: rest.redact,\n destination: rest.destination,\n destinationStream: prettyPrint ? createPrettyStream() : undefined,\n pinoOptions,\n }),\n });\n}\n"],"mappings":";;;;;;;;;;;AAWA,IAAM,OAAO;CACX,OAAO;CACP,KAAK;CACL,MAAM;CACN,KAAK;CACL,QAAQ;CACR,OAAO;CACP,MAAM;CACN,SAAS;CACT,MAAM;CACP;AAED,IAAM,kBAAqE;CACzE,IAAI;EAAE,OAAO;EAAS,OAAO,KAAK;EAAM;CACxC,IAAI;EAAE,OAAO;EAAS,OAAO,KAAK;EAAM;CACxC,IAAI;EAAE,OAAO;EAAS,OAAO,KAAK;EAAO;CACzC,IAAI;EAAE,OAAO;EAAS,OAAO,KAAK;EAAQ;CAC1C,IAAI;EAAE,OAAO;EAAS,OAAO,KAAK;EAAK;CACvC,IAAI;EAAE,OAAO;EAAS,OAAO,GAAG,KAAK,OAAO,KAAK;EAAO;CACzD;AAED,IAAM,gBAAmE;CACvE,OAAO;EAAE,OAAO;EAAS,OAAO,KAAK;EAAM;CA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../src/opentelemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;
|
|
1
|
+
{"version":3,"file":"opentelemetry.d.ts","sourceRoot":"","sources":["../src/opentelemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC3D,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAwBD;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC;;OAEG;IACH,cAAc,CAAC,EAAE,kBAAkB,CAAC;IAEpC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CAiEf;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBjE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,GAAG,IAAI,CAO7D"}
|