@eventuras/logger 0.7.1 → 0.8.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/README.md CHANGED
@@ -20,7 +20,12 @@ pnpm add @eventuras/logger
20
20
 
21
21
  ## Quick Start
22
22
 
23
- ### Scoped Logger (recommended)
23
+ ### Scoped Logger (preferred)
24
+
25
+ Create a `Logger` instance per module so every log entry carries the
26
+ module's namespace and any persistent context — it's the pattern we
27
+ use everywhere in Eventuras, and it makes filtering by module in Loki
28
+ / Grafana trivial.
24
29
 
25
30
  ```typescript
26
31
  import { Logger } from "@eventuras/logger";
@@ -36,6 +41,11 @@ logger.error({ error }, "Failed to save event");
36
41
 
37
42
  ### Static Methods (one-off logs)
38
43
 
44
+ The static methods are fine for bootstrap code that runs before any
45
+ scoped logger exists (server startup, top-level error handlers,
46
+ scripts). For anything inside a module or request path, prefer
47
+ `Logger.create()` so the output stays namespaced.
48
+
39
49
  ```typescript
40
50
  import { Logger } from "@eventuras/logger";
41
51
 
@@ -66,17 +76,30 @@ import { Logger } from "@eventuras/logger";
66
76
 
67
77
  Logger.configure({
68
78
  level: "debug",
69
- prettyPrint: process.env.NODE_ENV === "development",
70
79
  redact: ["password", "token", "apiKey", "authorization", "secret"],
71
80
  destination: "/var/log/app.log", // Optional file output
72
81
  });
73
82
  ```
74
83
 
84
+ ### Pretty dev output (Node only)
85
+
86
+ Pretty-printing depends on `node:stream`, so it lives in the `/node`
87
+ subpath to keep the main entry browser/edge-safe. Call it from your
88
+ server bootstrap:
89
+
90
+ ```typescript
91
+ import { configureNodeLogger } from "@eventuras/logger/node";
92
+
93
+ configureNodeLogger({
94
+ level: "debug",
95
+ prettyPrint: process.env.NODE_ENV === "development",
96
+ });
97
+ ```
98
+
75
99
  ### Environment Variables
76
100
 
77
101
  ```bash
78
- LOG_LEVEL=debug # Set global log level
79
- NODE_ENV=development # Enables pretty printing
102
+ LOG_LEVEL=debug # Set global log level (picked up by the default PinoTransport)
80
103
  ```
81
104
 
82
105
  ## Transports
@@ -99,16 +122,20 @@ interface LogTransport {
99
122
  ```typescript
100
123
  import { Logger, PinoTransport } from "@eventuras/logger";
101
124
 
102
- // Explicit Pino configuration
125
+ // Explicit Pino configuration (JSON output to stdout)
103
126
  Logger.configure({
104
127
  transport: new PinoTransport({
105
128
  level: "debug",
106
- prettyPrint: true,
107
129
  redact: ["password", "secret"],
108
130
  }),
109
131
  });
110
132
  ```
111
133
 
134
+ For pretty-printed dev output, use `configureNodeLogger` from
135
+ `@eventuras/logger/node` (see [Pretty dev output](#pretty-dev-output-node-only))
136
+ — the `prettyPrint` option lives there to keep `node:stream` out of the
137
+ universal main entry.
138
+
112
139
  ### ConsoleTransport
113
140
 
114
141
  A lightweight transport using native `console` methods. Automatically selected as the default in browser and edge runtimes. Also useful for testing:
@@ -147,6 +174,9 @@ Logger.configure({ transport: new DatadogTransport() });
147
174
  Sensitive fields are automatically redacted:
148
175
 
149
176
  ```typescript
177
+ import { Logger } from "@eventuras/logger";
178
+ const logger = Logger.create({ namespace: "auth" });
179
+
150
180
  logger.info(
151
181
  {
152
182
  username: "john",
@@ -161,6 +191,34 @@ Default redacted paths: `password`, `token`, `apiKey`, `authorization`, `secret`
161
191
 
162
192
  Configure additional paths via `Logger.configure({ redact: [...] })`.
163
193
 
194
+ ### Nested fields
195
+
196
+ Redaction uses [Pino's `redact` option](https://getpino.io/#/docs/redaction), which is powered by [fast-redact](https://github.com/davidmarkclements/fast-redact). Paths are **exact field paths** — they don't match nested occurrences by default:
197
+
198
+ ```typescript
199
+ // Only redacts top-level `password`
200
+ Logger.configure({ redact: ["password"] });
201
+
202
+ const logger = Logger.create({ namespace: "auth" });
203
+ logger.info({ password: "x" }); // → [REDACTED]
204
+ logger.info({ user: { password: "x" } }); // → NOT redacted
205
+ ```
206
+
207
+ To redact nested fields, spell out the path or use wildcards:
208
+
209
+ ```typescript
210
+ Logger.configure({
211
+ redact: [
212
+ "password",
213
+ "user.password",
214
+ "request.headers.authorization",
215
+ "*.token", // any key named `token` one level deep
216
+ ],
217
+ });
218
+ ```
219
+
220
+ For HTTP headers specifically, prefer [`redactHeaders`](#http-header-redaction) — it normalizes the object and handles `Headers` instances in addition to plain objects.
221
+
164
222
  ## HTTP Header Redaction
165
223
 
166
224
  Utility for redacting sensitive HTTP headers:
@@ -215,7 +273,7 @@ process.on("SIGTERM", async () => {
215
273
  });
216
274
  ```
217
275
 
218
- ### Environment Variables
276
+ ### OTel Environment Variables
219
277
 
220
278
  ```bash
221
279
  OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://...
@@ -290,11 +348,11 @@ import type {
290
348
 
291
349
  ## Subpath Exports
292
350
 
293
- | Import path | Contents | Environment |
294
- | --------------------------------- | --------------------------------------------------------------- | ----------- |
295
- | `@eventuras/logger` | Logger, types, PinoTransport, ConsoleTransport, httpLogger | Universal |
296
- | `@eventuras/logger/node` | `formatLogLine`, `createPrettyStream` (depends on `node:stream`) | Node.js |
297
- | `@eventuras/logger/opentelemetry` | `setupOpenTelemetryLogger`, `shutdownOpenTelemetryLogger` | Node.js |
351
+ | Import path | Contents | Environment |
352
+ | --- | --- | --- |
353
+ | `@eventuras/logger` | `Logger`, types, `PinoTransport`, `ConsoleTransport`, `redactHeaders` | Universal |
354
+ | `@eventuras/logger/node` | `configureNodeLogger`, `createPrettyStream`, `formatLogLine` | Node.js |
355
+ | `@eventuras/logger/opentelemetry` | `setupOpenTelemetryLogger`, `shutdownOpenTelemetryLogger` | Node.js |
298
356
 
299
357
  ### Node-only Pretty-print Utilities
300
358
 
@@ -0,0 +1,208 @@
1
+ import e from "pino";
2
+ //#region src/transports/pino.ts
3
+ var t = class {
4
+ pino;
5
+ constructor(t = {}) {
6
+ let n = {
7
+ level: t.level ?? "info",
8
+ timestamp: e.stdTimeFunctions.isoTime,
9
+ formatters: { level: (e) => ({ level: e }) },
10
+ ...t.redact && { redact: {
11
+ paths: t.redact,
12
+ censor: "[REDACTED]"
13
+ } },
14
+ ...t.pinoOptions
15
+ };
16
+ t.destinationStream ? this.pino = e(n, t.destinationStream) : t.destination ? this.pino = e(n, e.destination(t.destination)) : this.pino = e(n);
17
+ }
18
+ log(e, t, n) {
19
+ n ? this.pino[e](t, n) : this.pino[e](t);
20
+ }
21
+ child(e) {
22
+ return new n(this.pino.child(e));
23
+ }
24
+ async flush() {
25
+ this.pino.flush();
26
+ }
27
+ }, n = class e {
28
+ constructor(e) {
29
+ this.pinoChild = e;
30
+ }
31
+ log(e, t, n) {
32
+ n ? this.pinoChild[e](t, n) : this.pinoChild[e](t);
33
+ }
34
+ child(t) {
35
+ return new e(this.pinoChild.child(t));
36
+ }
37
+ async flush() {
38
+ this.pinoChild.flush();
39
+ }
40
+ }, r = {
41
+ trace: "debug",
42
+ debug: "debug",
43
+ info: "log",
44
+ warn: "warn",
45
+ error: "error",
46
+ fatal: "error"
47
+ }, i = class e {
48
+ bindings;
49
+ constructor(e) {
50
+ this.bindings = e ?? {};
51
+ }
52
+ log(e, t, n) {
53
+ let i = r[e], a = {
54
+ ...this.bindings,
55
+ ...t
56
+ }, o = Object.keys(a).length > 0;
57
+ n && o ? console[i](`[${e}]`, n, a) : n ? console[i](`[${e}]`, n) : o && console[i](`[${e}]`, a);
58
+ }
59
+ child(t) {
60
+ return new e({
61
+ ...this.bindings,
62
+ ...t
63
+ });
64
+ }
65
+ }, a = [
66
+ "password",
67
+ "token",
68
+ "apiKey",
69
+ "authorization",
70
+ "secret"
71
+ ];
72
+ function o(e) {
73
+ if (typeof globalThis < "u" && typeof globalThis.process == "object") return globalThis.process.env[e];
74
+ }
75
+ function s() {
76
+ try {
77
+ return typeof process < "u" && typeof process.versions?.node == "string";
78
+ } catch {
79
+ return !1;
80
+ }
81
+ }
82
+ function c(e) {
83
+ return s() ? new t({
84
+ level: e.level ?? o("LOG_LEVEL") ?? "info",
85
+ redact: e.redact ?? a,
86
+ destination: e.destination
87
+ }) : new i();
88
+ }
89
+ var l = class e {
90
+ static transport;
91
+ static config = {};
92
+ options;
93
+ childTransport;
94
+ static {
95
+ e.transport = c(e.config);
96
+ }
97
+ constructor(t = {}) {
98
+ if (this.options = t, t.context || t.correlationId || t.namespace) {
99
+ let n = {
100
+ ...t.namespace && { namespace: t.namespace },
101
+ ...t.correlationId && { correlationId: t.correlationId },
102
+ ...t.context
103
+ };
104
+ this.childTransport = e.transport.child(n);
105
+ }
106
+ }
107
+ static configure(t) {
108
+ e.config = {
109
+ ...e.config,
110
+ ...t
111
+ }, e.transport = e.config.transport ?? c(e.config);
112
+ }
113
+ static getTransport() {
114
+ return e.transport;
115
+ }
116
+ static getPinoInstance() {
117
+ if (e.transport instanceof t) return e.transport.pino;
118
+ throw Error("getPinoInstance() requires PinoTransport. Use Logger.getTransport() for the active transport.");
119
+ }
120
+ static normalizeArgs(e, t) {
121
+ return typeof e == "string" ? [{}, [e, ...t]] : [e, t];
122
+ }
123
+ static isDevelopment() {
124
+ return o("NODE_ENV") === "development";
125
+ }
126
+ static formatError(e) {
127
+ return e instanceof Error ? `${e.name}: ${e.message}\nStack: ${e.stack}` : String(e);
128
+ }
129
+ static buildLogData(e) {
130
+ return {
131
+ ...e.namespace && { namespace: e.namespace },
132
+ ...e.correlationId && { correlationId: e.correlationId },
133
+ ...e.context
134
+ };
135
+ }
136
+ static staticLog(t, n, ...r) {
137
+ if (n.developerOnly && !e.isDevelopment()) return;
138
+ let i = e.buildLogData(n);
139
+ e.transport.log(t, {
140
+ ...i,
141
+ msg: r
142
+ });
143
+ }
144
+ static staticErrorLog(t, n, ...r) {
145
+ if (n.developerOnly && !e.isDevelopment()) return;
146
+ let i = n.error ? { error: e.formatError(n.error) } : {}, a = {
147
+ ...e.buildLogData(n),
148
+ ...i
149
+ };
150
+ e.transport.log(t, {
151
+ ...a,
152
+ msg: r
153
+ });
154
+ }
155
+ static info(t, ...n) {
156
+ let [r, i] = e.normalizeArgs(t, n);
157
+ e.staticLog("info", r, ...i);
158
+ }
159
+ static debug(t, ...n) {
160
+ let [r, i] = e.normalizeArgs(t, n);
161
+ e.staticLog("debug", r, ...i);
162
+ }
163
+ static trace(t, ...n) {
164
+ let [r, i] = e.normalizeArgs(t, n);
165
+ e.staticLog("trace", r, ...i);
166
+ }
167
+ static warn(t, ...n) {
168
+ let [r, i] = e.normalizeArgs(t, n);
169
+ e.staticLog("warn", r, ...i);
170
+ }
171
+ static error(t, ...n) {
172
+ let [r, i] = e.normalizeArgs(t, n);
173
+ e.staticErrorLog("error", r, ...i);
174
+ }
175
+ static fatal(t, ...n) {
176
+ let [r, i] = e.normalizeArgs(t, n);
177
+ e.staticErrorLog("fatal", r, ...i);
178
+ }
179
+ static create(t = {}) {
180
+ return new e(t);
181
+ }
182
+ logInstance(t, n, r) {
183
+ let i = this.childTransport ?? e.transport;
184
+ typeof n == "string" ? i.log(t, {}, n) : r ? i.log(t, n ?? {}, r) : i.log(t, n ?? {});
185
+ }
186
+ trace(e, t) {
187
+ this.logInstance("trace", e, t);
188
+ }
189
+ debug(e, t) {
190
+ this.logInstance("debug", e, t);
191
+ }
192
+ info(e, t) {
193
+ this.logInstance("info", e, t);
194
+ }
195
+ warn(e, t) {
196
+ this.logInstance("warn", e, t);
197
+ }
198
+ error(t, n) {
199
+ let r = this.childTransport ?? e.transport;
200
+ 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 ?? {});
201
+ }
202
+ fatal(t, n) {
203
+ let r = this.childTransport ?? e.transport;
204
+ 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 ?? {});
205
+ }
206
+ };
207
+ //#endregion
208
+ export { i as n, t as r, l as t };
package/dist/Logger.d.ts CHANGED
@@ -28,8 +28,9 @@ export declare class Logger {
28
28
  */
29
29
  static getTransport(): LogTransport;
30
30
  /**
31
- * @deprecated Use `Logger.getTransport()` instead. If you need the raw
32
- * Pino instance, cast the transport: `(Logger.getTransport() as PinoTransport).pino`
31
+ * @deprecated Since 0.7 — will be removed in 1.0. Use `Logger.getTransport()`
32
+ * instead. If you need the raw Pino instance, cast the transport:
33
+ * `(Logger.getTransport() as PinoTransport).pino`.
33
34
  */
34
35
  static getPinoInstance(): import('pino').Logger;
35
36
  /**
@@ -66,7 +67,6 @@ export declare class Logger {
66
67
  static fatal(options: ErrorLoggerOptions, ...msg: unknown[]): void;
67
68
  /** Log at fatal level with just a message string. */
68
69
  static fatal(msg: string, ...args: unknown[]): void;
69
- private static rebindStaticMethods;
70
70
  /**
71
71
  * Create a scoped logger instance with predefined options.
72
72
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EAEb,YAAY,EACb,MAAM,SAAS,CAAC;AAoCjB,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAe;IACvC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAoB;IAGzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAe;IAM/C,OAAO;IAaP;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAOrD;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,IAAI,YAAY;IAInC;;;OAGG;IACH,MAAM,CAAC,eAAe,IAAI,OAAO,MAAM,EAAE,MAAM;IAW/C;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAU5B,OAAO,CAAC,MAAM,CAAC,aAAa;IAI5B,OAAO,CAAC,MAAM,CAAC,WAAW;IAO1B,OAAO,CAAC,MAAM,CAAC,YAAY;IAQ3B,OAAO,CAAC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CAAC,EAAE,MAAM,GAAG,IAAI;IAIlE,2BAA2B;IAC3B,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAIjE,2BAA2B;IAC3B,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAIjE;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAahD;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;CAYjD"}
package/dist/index.js CHANGED
@@ -1,212 +1,6 @@
1
- import { t as e } from "./pretty-sMlW_evX.js";
2
- import t from "pino";
3
- //#region src/transports/pino.ts
4
- var n = class {
5
- pino;
6
- constructor(n = {}) {
7
- let r = {
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 e, r as t, t as n } from "./Logger-CcNEmm6u.js";
2
+ //#region src/httpLogger.ts
3
+ var r = [
210
4
  "authorization",
211
5
  "cookie",
212
6
  "set-cookie",
@@ -214,15 +8,15 @@ var u = class e {
214
8
  "x-auth-token",
215
9
  "proxy-authorization"
216
10
  ];
217
- function f(e) {
11
+ function i(e) {
218
12
  let t = {};
219
13
  return e instanceof Headers ? e.forEach((e, n) => {
220
- t[n] = d.includes(n.toLowerCase()) ? "[REDACTED]" : e;
14
+ t[n] = r.includes(n.toLowerCase()) ? "[REDACTED]" : e;
221
15
  }) : Array.isArray(e) ? e.forEach(([e, n]) => {
222
- t[e] = d.includes(e.toLowerCase()) ? "[REDACTED]" : String(n);
16
+ t[e] = r.includes(e.toLowerCase()) ? "[REDACTED]" : String(n);
223
17
  }) : Object.entries(e).forEach(([e, n]) => {
224
- t[e] = d.includes(e.toLowerCase()) ? "[REDACTED]" : String(n);
18
+ t[e] = r.includes(e.toLowerCase()) ? "[REDACTED]" : String(n);
225
19
  }), t;
226
20
  }
227
21
  //#endregion
228
- export { a as ConsoleTransport, u as Logger, n as PinoTransport, f as redactHeaders };
22
+ export { e as ConsoleTransport, n as Logger, t as PinoTransport, i as redactHeaders };
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.js-only exports for @eventuras/logger.
3
- *
4
- * These utilities depend on `node:stream` and must not be imported in browser
5
- * or edge runtime environments. Import from the root entry point
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
- * import { createPrettyStream, formatLogLine } from '@eventuras/logger/node';
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 { formatLogLine, createPrettyStream } from './transports/pretty';
25
+ export declare function configureNodeLogger(options?: NodeLoggerOptions): void;
12
26
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
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,130 @@
1
- import { n as e, t } from "./pretty-sMlW_evX.js";
2
- export { t as createPrettyStream, e as formatLogLine };
1
+ import { r as e, t } from "./Logger-CcNEmm6u.js";
2
+ import { Writable as n } from "node:stream";
3
+ //#region src/transports/pretty.ts
4
+ var r = {
5
+ reset: "\x1B[0m",
6
+ dim: "\x1B[2m",
7
+ bold: "\x1B[1m",
8
+ red: "\x1B[31m",
9
+ yellow: "\x1B[33m",
10
+ green: "\x1B[32m",
11
+ cyan: "\x1B[36m",
12
+ magenta: "\x1B[35m",
13
+ gray: "\x1B[90m"
14
+ }, i = {
15
+ 10: {
16
+ label: "TRACE",
17
+ color: r.gray
18
+ },
19
+ 20: {
20
+ label: "DEBUG",
21
+ color: r.cyan
22
+ },
23
+ 30: {
24
+ label: "INFO ",
25
+ color: r.green
26
+ },
27
+ 40: {
28
+ label: "WARN ",
29
+ color: r.yellow
30
+ },
31
+ 50: {
32
+ label: "ERROR",
33
+ color: r.red
34
+ },
35
+ 60: {
36
+ label: "FATAL",
37
+ color: `${r.bold}${r.red}`
38
+ }
39
+ }, a = {
40
+ trace: {
41
+ label: "TRACE",
42
+ color: r.gray
43
+ },
44
+ debug: {
45
+ label: "DEBUG",
46
+ color: r.cyan
47
+ },
48
+ info: {
49
+ label: "INFO ",
50
+ color: r.green
51
+ },
52
+ warn: {
53
+ label: "WARN ",
54
+ color: r.yellow
55
+ },
56
+ error: {
57
+ label: "ERROR",
58
+ color: r.red
59
+ },
60
+ fatal: {
61
+ label: "FATAL",
62
+ color: `${r.bold}${r.red}`
63
+ }
64
+ }, o = new Set([
65
+ "level",
66
+ "time",
67
+ "pid",
68
+ "hostname",
69
+ "msg",
70
+ "name",
71
+ "ns",
72
+ "namespace"
73
+ ]);
74
+ function s(e) {
75
+ if (typeof e == "string") {
76
+ let t = new Date(e);
77
+ return Number.isNaN(t.getTime()) ? "" : t.toLocaleTimeString("en-GB", { hour12: !1 });
78
+ }
79
+ return typeof e == "number" ? new Date(e).toLocaleTimeString("en-GB", { hour12: !1 }) : (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: !1 });
80
+ }
81
+ function c(e) {
82
+ let t = {}, n = !1;
83
+ for (let [r, i] of Object.entries(e)) o.has(r) || (t[r] = i, n = !0);
84
+ return n ? ` ${r.dim}${JSON.stringify(t)}${r.reset}` : "";
85
+ }
86
+ function l(e) {
87
+ let t = e.trim();
88
+ if (!t) return "";
89
+ let n;
90
+ try {
91
+ n = JSON.parse(t);
92
+ } catch {
93
+ return t;
94
+ }
95
+ let o = n.level, l = typeof o == "string" ? a[o] ?? {
96
+ label: o.toUpperCase().padEnd(5),
97
+ color: r.gray
98
+ } : i[o] ?? {
99
+ label: `L${o}`,
100
+ color: r.gray
101
+ }, u = s(n.time), d = n.msg ?? "", f = n.namespace || n.ns || n.name || "", p = f ? ` ${r.magenta}(${f})${r.reset}` : "", m = `${r.dim}→${r.reset}`, h = c(n);
102
+ return `${r.dim}${u}${r.reset} ${l.color}${l.label}${r.reset}${p} ${m} ${d}${h}`;
103
+ }
104
+ function u() {
105
+ return new n({ write(e, t, n) {
106
+ let r = e.toString().split("\n");
107
+ for (let e of r) {
108
+ let t = l(e);
109
+ t && process.stdout.write(t + "\n");
110
+ }
111
+ n();
112
+ } });
113
+ }
114
+ //#endregion
115
+ //#region src/node.ts
116
+ function d(n = {}) {
117
+ let { prettyPrint: r, pinoOptions: i, ...a } = n;
118
+ t.configure({
119
+ ...a,
120
+ transport: new e({
121
+ level: a.level,
122
+ redact: a.redact,
123
+ destination: a.destination,
124
+ destinationStream: r ? u() : void 0,
125
+ pinoOptions: i
126
+ })
127
+ });
128
+ }
129
+ //#endregion
130
+ export { d as configureNodeLogger, u as createPrettyStream, l as formatLogLine };
@@ -1 +1 @@
1
- {"version":3,"file":"opentelemetry.d.ts","sourceRoot":"","sources":["../src/opentelemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;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,CA+Df;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBjE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,kBAAkB,GAAG,IAAI,CAO7D"}
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"}
@@ -1,6 +1,7 @@
1
1
  import { a as e } from "./chunk-NnHqS4_Y.js";
2
+ import { t } from "./Logger-CcNEmm6u.js";
2
3
  //#region src/opentelemetry.ts
3
- async function t() {
4
+ async function n() {
4
5
  try {
5
6
  let [t, n] = await Promise.all([import("./src-15l0SmY8.js").then((t) => /* @__PURE__ */ e(t.default, 1)), import("./esm-CIhYjsQQ.js")]);
6
7
  return {
@@ -11,34 +12,37 @@ async function t() {
11
12
  return null;
12
13
  }
13
14
  }
14
- var n = null, r = null;
15
- async function i(e = {}) {
15
+ var r = null, i = null;
16
+ async function a(e = {}) {
16
17
  if (typeof window < "u") {
17
- console.warn("[logger] OpenTelemetry integration is server-side only - skipping in browser");
18
+ t.warn({ namespace: "logger:otel" }, "OpenTelemetry integration is server-side only, skipping");
18
19
  return;
19
20
  }
20
- let { logRecordProcessor: i, loggerProvider: a, serviceName: o, enabled: s = !0 } = e;
21
- if (!s) {
22
- console.log("[logger] OpenTelemetry integration disabled");
21
+ let { logRecordProcessor: a, loggerProvider: o, serviceName: s, enabled: c = !0 } = e;
22
+ if (!c) {
23
+ t.debug({ namespace: "logger:otel" }, "OpenTelemetry integration disabled");
23
24
  return;
24
25
  }
25
- let c = await t();
26
- if (!c) {
27
- console.warn("[logger] OpenTelemetry packages not available - integration disabled"), console.warn("[logger] Install @opentelemetry/* packages to enable OpenTelemetry integration");
26
+ let l = await n();
27
+ if (!l) {
28
+ t.warn({ namespace: "logger:otel" }, "OpenTelemetry packages not available integration disabled. Install @opentelemetry/api, @opentelemetry/api-logs, @opentelemetry/instrumentation-pino, and @opentelemetry/sdk-logs to enable.");
28
29
  return;
29
30
  }
30
- let { PinoInstrumentation: l, LoggerProvider: u } = c;
31
- n &&= (n.disable(), null), r = a ?? new u(), i && r && r.addLogRecordProcessor(i);
32
- let d = o ?? (typeof process < "u" ? process.env?.OTEL_SERVICE_NAME : void 0) ?? "unknown-service";
33
- n = new l({ logHook: (e, t) => {
34
- t["service.name"] = d;
35
- } }), n.enable(), console.log("[logger] OpenTelemetry integration enabled"), i && console.log("[logger] Log record processor registered");
31
+ let { PinoInstrumentation: u, LoggerProvider: d } = l;
32
+ r &&= (r.disable(), null), i = o ?? new d(), a && i && i.addLogRecordProcessor(a);
33
+ let f = s ?? (typeof process < "u" ? process.env?.OTEL_SERVICE_NAME : void 0) ?? "unknown-service";
34
+ r = new u({ logHook: (e, t) => {
35
+ t["service.name"] = f;
36
+ } }), r.enable(), t.info({
37
+ namespace: "logger:otel",
38
+ context: { hasProcessor: !!a }
39
+ }, "OpenTelemetry integration enabled");
36
40
  }
37
- async function a() {
38
- typeof window < "u" || (n &&= (n.disable(), null), r &&= (await r.shutdown(), null), console.log("[logger] OpenTelemetry integration shut down"));
41
+ async function o() {
42
+ typeof window < "u" || (r &&= (r.disable(), null), i &&= (await i.shutdown(), null), t.info({ namespace: "logger:otel" }, "OpenTelemetry integration shut down"));
39
43
  }
40
- function o() {
41
- return typeof window < "u" ? null : r;
44
+ function s() {
45
+ return typeof window < "u" ? null : i;
42
46
  }
43
47
  //#endregion
44
- export { o as getLoggerProvider, i as setupOpenTelemetryLogger, a as shutdownOpenTelemetryLogger };
48
+ export { s as getLoggerProvider, a as setupOpenTelemetryLogger, o as shutdownOpenTelemetryLogger };
@@ -1,15 +1,27 @@
1
1
  import { Logger as PinoLogger, LoggerOptions as PinoLoggerOptions } from 'pino';
2
2
  import { LogLevel, LogTransport } from '../types';
3
+ /**
4
+ * Minimal structural type for a Pino destination stream — accepts anything
5
+ * with a `write` method. Defined locally so this file (re-exported from the
6
+ * universal `@eventuras/logger` entry) doesn't pull `NodeJS.*` types into
7
+ * browser/edge consumers that don't ship `@types/node`.
8
+ */
9
+ export interface PinoDestinationStream {
10
+ write(chunk: string | Uint8Array): unknown;
11
+ }
3
12
  /** Options for creating a PinoTransport. */
4
13
  export type PinoTransportOptions = {
5
14
  /** Minimum log level. Defaults to `'info'`. */
6
15
  level?: LogLevel;
7
16
  /** Field paths to redact from output. */
8
17
  redact?: string[];
9
- /** Enable pretty-printed, human-readable output. */
10
- prettyPrint?: boolean;
11
18
  /** File path destination (omit for stdout). */
12
19
  destination?: string;
20
+ /**
21
+ * Writable stream destination (e.g. a pretty-print stream from
22
+ * `@eventuras/logger/node`). Takes precedence over `destination`.
23
+ */
24
+ destinationStream?: PinoDestinationStream;
13
25
  /** Raw Pino options for advanced tuning (merged after built-in defaults). */
14
26
  pinoOptions?: PinoLoggerOptions;
15
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../../src/transports/pino.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAa,EAAE,KAAK,MAAM,IAAI,UAAU,EAAE,KAAK,aAAa,IAAI,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAChG,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGvD,4CAA4C;AAC5C,MAAM,MAAM,oBAAoB,GAAG;IACjC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAEF,qBAAa,aAAc,YAAW,YAAY;IAChD,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;gBAEd,OAAO,GAAE,oBAAyB;IAwB9C,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQvE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAKhD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
1
+ {"version":3,"file":"pino.d.ts","sourceRoot":"","sources":["../../src/transports/pino.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAa,EAAE,KAAK,MAAM,IAAI,UAAU,EAAE,KAAK,aAAa,IAAI,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAChG,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;CAC5C;AAED,4CAA4C;AAC5C,MAAM,MAAM,oBAAoB,GAAG;IACjC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;IAC1C,6EAA6E;IAC7E,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAEF,qBAAa,aAAc,YAAW,YAAY;IAChD,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;gBAEd,OAAO,GAAE,oBAAyB;IA2B9C,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQvE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAKhD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
package/dist/types.d.ts CHANGED
@@ -52,11 +52,15 @@ export type LoggerConfig = {
52
52
  level?: LogLevel;
53
53
  /** Field paths to redact from log output (e.g., ['password', 'token']). */
54
54
  redact?: string[];
55
- /** Enable pretty-printed output (auto-enabled in development). */
56
- prettyPrint?: boolean;
57
55
  /** Optional file path for log output (Pino only). */
58
56
  destination?: string;
59
- /** Custom transport implementation. Defaults to PinoTransport. */
57
+ /**
58
+ * Custom transport implementation. The default depends on the runtime:
59
+ * `PinoTransport` (JSON output) on Node.js, and `ConsoleTransport`
60
+ * (browser-safe `console.*` calls) in browser/edge runtimes. For
61
+ * pretty-printed dev output, use `configureNodeLogger` from
62
+ * `@eventuras/logger/node`.
63
+ */
60
64
  transport?: LogTransport;
61
65
  };
62
66
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExE,6DAA6D;IAC7D,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC;IAEvD,sCAAsC;IACtC,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG;IAC1B,8CAA8C;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,C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8CAA8C;IAC9C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,0CAA0C;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,YAAY,GAAG;IACzB,gCAAgC;IAChC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventuras/logger",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Structured logging with Pino and optional OpenTelemetry integration",
5
5
  "keywords": [
6
6
  "logger",
@@ -54,9 +54,9 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@opentelemetry/api": "^1.9.0",
57
- "@opentelemetry/api-logs": ">=0.200.0",
58
- "@opentelemetry/instrumentation-pino": ">=0.50.0",
59
- "@opentelemetry/sdk-logs": ">=0.200.0"
57
+ "@opentelemetry/api-logs": ">=0.200.0 <1.0.0",
58
+ "@opentelemetry/instrumentation-pino": ">=0.50.0 <1.0.0",
59
+ "@opentelemetry/sdk-logs": ">=0.200.0 <1.0.0"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@opentelemetry/api": {
@@ -1,114 +0,0 @@
1
- import { Writable as e } from "node:stream";
2
- //#region src/transports/pretty.ts
3
- var t = {
4
- reset: "\x1B[0m",
5
- dim: "\x1B[2m",
6
- bold: "\x1B[1m",
7
- red: "\x1B[31m",
8
- yellow: "\x1B[33m",
9
- green: "\x1B[32m",
10
- cyan: "\x1B[36m",
11
- magenta: "\x1B[35m",
12
- gray: "\x1B[90m"
13
- }, n = {
14
- 10: {
15
- label: "TRACE",
16
- color: t.gray
17
- },
18
- 20: {
19
- label: "DEBUG",
20
- color: t.cyan
21
- },
22
- 30: {
23
- label: "INFO ",
24
- color: t.green
25
- },
26
- 40: {
27
- label: "WARN ",
28
- color: t.yellow
29
- },
30
- 50: {
31
- label: "ERROR",
32
- color: t.red
33
- },
34
- 60: {
35
- label: "FATAL",
36
- color: `${t.bold}${t.red}`
37
- }
38
- }, r = {
39
- trace: {
40
- label: "TRACE",
41
- color: t.gray
42
- },
43
- debug: {
44
- label: "DEBUG",
45
- color: t.cyan
46
- },
47
- info: {
48
- label: "INFO ",
49
- color: t.green
50
- },
51
- warn: {
52
- label: "WARN ",
53
- color: t.yellow
54
- },
55
- error: {
56
- label: "ERROR",
57
- color: t.red
58
- },
59
- fatal: {
60
- label: "FATAL",
61
- color: `${t.bold}${t.red}`
62
- }
63
- }, i = new Set([
64
- "level",
65
- "time",
66
- "pid",
67
- "hostname",
68
- "msg",
69
- "name",
70
- "ns",
71
- "namespace"
72
- ]);
73
- function a(e) {
74
- if (typeof e == "string") {
75
- let t = new Date(e);
76
- return Number.isNaN(t.getTime()) ? "" : t.toLocaleTimeString("en-GB", { hour12: !1 });
77
- }
78
- return typeof e == "number" ? new Date(e).toLocaleTimeString("en-GB", { hour12: !1 }) : (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", { hour12: !1 });
79
- }
80
- function o(e) {
81
- let n = {}, r = !1;
82
- for (let [t, a] of Object.entries(e)) i.has(t) || (n[t] = a, r = !0);
83
- return r ? ` ${t.dim}${JSON.stringify(n)}${t.reset}` : "";
84
- }
85
- function s(e) {
86
- let i = e.trim();
87
- if (!i) return "";
88
- let s;
89
- try {
90
- s = JSON.parse(i);
91
- } catch {
92
- return i;
93
- }
94
- let c = s.level, l = typeof c == "string" ? r[c] ?? {
95
- label: c.toUpperCase().padEnd(5),
96
- color: t.gray
97
- } : n[c] ?? {
98
- label: `L${c}`,
99
- color: t.gray
100
- }, u = a(s.time), d = s.msg ?? "", f = s.namespace || s.ns || s.name || "", p = f ? ` ${t.magenta}(${f})${t.reset}` : "", m = `${t.dim}→${t.reset}`, h = o(s);
101
- return `${t.dim}${u}${t.reset} ${l.color}${l.label}${t.reset}${p} ${m} ${d}${h}`;
102
- }
103
- function c() {
104
- return new e({ write(e, t, n) {
105
- let r = e.toString().split("\n");
106
- for (let e of r) {
107
- let t = s(e);
108
- t && process.stdout.write(t + "\n");
109
- }
110
- n();
111
- } });
112
- }
113
- //#endregion
114
- export { s as n, c as t };