logan-logger 1.0.2 → 1.1.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/dist/index.esm.js CHANGED
@@ -1,667 +1,37 @@
1
- var n = /* @__PURE__ */ ((t) => (t[t.DEBUG = 0] = "DEBUG", t[t.INFO = 1] = "INFO", t[t.WARN = 2] = "WARN", t[t.ERROR = 3] = "ERROR", t[t.SILENT = 4] = "SILENT", t))(n || {});
2
- function d() {
3
- const t = u(), e = O(t), r = b(t);
4
- return {
5
- name: t,
6
- version: e,
7
- capabilities: r
8
- };
9
- }
10
- function u() {
11
- return typeof globalThis.Deno < "u" ? "deno" : typeof globalThis.Bun < "u" ? "bun" : typeof window < "u" && typeof document < "u" ? "browser" : typeof globalThis.importScripts == "function" && typeof window > "u" ? "webworker" : typeof process < "u" && process.versions && process.versions.node ? "node" : "unknown";
12
- }
13
- function O(t) {
14
- switch (t) {
15
- case "node":
16
- return typeof process < "u" ? process.version : void 0;
17
- case "deno":
18
- return typeof globalThis.Deno < "u" ? globalThis.Deno.version?.deno : void 0;
19
- case "bun":
20
- return typeof globalThis.Bun < "u" ? globalThis.Bun.version : void 0;
21
- case "browser":
22
- return typeof navigator < "u" ? navigator.userAgent : void 0;
23
- default:
24
- return;
25
- }
26
- }
27
- function b(t) {
28
- switch (t) {
29
- case "node":
30
- return {
31
- fileSystem: !0,
32
- colorSupport: !0,
33
- processInfo: !0,
34
- streams: !0
35
- };
36
- case "deno":
37
- return {
38
- fileSystem: !0,
39
- colorSupport: !0,
40
- processInfo: !0,
41
- streams: !0
42
- };
43
- case "bun":
44
- return {
45
- fileSystem: !0,
46
- colorSupport: !0,
47
- processInfo: !0,
48
- streams: !0
49
- };
50
- case "browser":
51
- return {
52
- fileSystem: !1,
53
- colorSupport: !0,
54
- // CSS styling in console
55
- processInfo: !1,
56
- streams: !1
57
- };
58
- case "webworker":
59
- return {
60
- fileSystem: !1,
61
- colorSupport: !1,
62
- processInfo: !1,
63
- streams: !1
64
- };
65
- default:
66
- return {
67
- fileSystem: !1,
68
- colorSupport: !1,
69
- processInfo: !1,
70
- streams: !1
71
- };
72
- }
73
- }
74
- function T() {
75
- return u() === "node";
76
- }
77
- function B() {
78
- return u() === "browser";
79
- }
80
- function D() {
81
- return u() === "deno";
82
- }
83
- function $() {
84
- return u() === "bun";
85
- }
86
- class p {
87
- constructor(e = {}) {
88
- this.childMetadata = {}, this.config = e, this.level = e.level ?? n.INFO, this.runtime = d().name;
89
- }
90
- debug(e, r) {
91
- this.log(n.DEBUG, e, r);
92
- }
93
- info(e, r) {
94
- this.log(n.INFO, e, r);
95
- }
96
- warn(e, r) {
97
- this.log(n.WARN, e, r);
98
- }
99
- error(e, r) {
100
- this.log(n.ERROR, e, r);
101
- }
102
- log(e, r, s) {
103
- if (!this.shouldLog(e))
104
- return;
105
- const o = typeof r == "function" ? r() : r, a = { ...this.childMetadata, ...s }, i = {
106
- timestamp: /* @__PURE__ */ new Date(),
107
- level: e,
108
- message: o,
109
- metadata: Object.keys(a).length > 0 ? a : void 0,
110
- runtime: this.runtime
111
- };
112
- this.writeLog(i);
113
- }
114
- setLevel(e) {
115
- this.level = e;
116
- }
117
- getLevel() {
118
- return this.level;
119
- }
120
- child(e) {
121
- const r = this.createChild();
122
- return r.childMetadata = { ...this.childMetadata, ...e }, r;
123
- }
124
- shouldLog(e) {
125
- return e >= this.level;
126
- }
127
- }
128
- function f(t, e) {
129
- const r = /* @__PURE__ */ new WeakSet();
130
- return JSON.stringify(t, (s, o) => {
131
- if (typeof o == "object" && o !== null) {
132
- if (r.has(o))
133
- return "[Circular]";
134
- r.add(o);
135
- }
136
- return o instanceof Error ? {
137
- name: o.name,
138
- message: o.message,
139
- stack: o.stack,
140
- ...Object.getOwnPropertyNames(o).reduce((a, i) => (i !== "name" && i !== "message" && i !== "stack" && (a[i] = o[i]), a), {})
141
- } : typeof o == "function" ? `[Function: ${o.name || "anonymous"}]` : o === void 0 ? "[undefined]" : typeof o == "bigint" ? `[BigInt: ${o.toString()}]` : typeof o == "symbol" ? `[Symbol: ${o.toString()}]` : o;
142
- }, e);
143
- }
144
- function N(t, e = ["password", "token", "secret", "key", "auth"]) {
145
- if (typeof t != "object" || t === null)
146
- return t;
147
- const r = Array.isArray(t) ? [] : {};
148
- for (const [s, o] of Object.entries(t))
149
- e.some(
150
- (i) => s.toLowerCase().includes(i.toLowerCase())
151
- ) ? r[s] = "[REDACTED]" : typeof o == "object" && o !== null ? r[s] = N(o, e) : r[s] = o;
152
- return r;
153
- }
154
- function M(t) {
155
- return t instanceof Error ? {
156
- name: t.name,
157
- message: t.message,
158
- stack: t.stack,
159
- ...t
160
- // Include any additional properties
161
- } : t;
162
- }
163
- class m extends p {
164
- constructor(e = {}) {
165
- super(e), this.initializeWinston();
166
- }
167
- async initializeWinston() {
168
- try {
169
- const e = await import("winston");
170
- this.winston = this.createWinstonLogger(e);
171
- } catch {
172
- console.warn("[logan-logger] Winston not found, falling back to console logging");
173
- }
174
- }
175
- createWinstonLogger(e) {
176
- const r = e.format.combine(
177
- e.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
178
- e.format.errors({ stack: !0 }),
179
- e.format.json(),
180
- e.format.prettyPrint()
181
- ), s = e.format.combine(
182
- e.format.colorize(),
183
- e.format.timestamp({ format: "HH:mm:ss" }),
184
- e.format.printf(({ timestamp: a, level: i, message: E, ...g }) => {
185
- const R = Object.keys(g).length ? JSON.stringify(g, null, 2) : "";
186
- return `${a} [${i}]: ${E} ${R}`;
187
- })
188
- ), o = e.createLogger({
189
- level: this.getWinstonLevel(this.level),
190
- format: r,
191
- transports: [
192
- new e.transports.Console({
193
- format: process.env.NODE_ENV === "production" ? r : s
194
- })
195
- ]
196
- });
197
- return process.env.NODE_ENV === "production" && (o.add(
198
- new e.transports.File({
199
- filename: "logs/error.log",
200
- level: "error",
201
- maxsize: 5242880,
202
- // 5MB
203
- maxFiles: 5
204
- })
205
- ), o.add(
206
- new e.transports.File({
207
- filename: "logs/combined.log",
208
- maxsize: 5242880,
209
- // 5MB
210
- maxFiles: 10
211
- })
212
- )), o;
213
- }
214
- writeLog(e) {
215
- this.winston ? this.winston.log({
216
- level: this.getWinstonLevel(e.level),
217
- message: e.message,
218
- timestamp: e.timestamp,
219
- ...e.metadata
220
- }) : this.writeToConsole(e);
221
- }
222
- createChild() {
223
- return new m(this.config);
224
- }
225
- writeToConsole(e) {
226
- const r = e.timestamp.toISOString(), s = n[e.level].toLowerCase(), o = e.metadata ? ` ${f(e.metadata)}` : "", a = `[${r}] ${s.toUpperCase()}: ${e.message}${o}`;
227
- switch (e.level) {
228
- case n.DEBUG:
229
- console.debug(a);
230
- break;
231
- case n.INFO:
232
- console.info(a);
233
- break;
234
- case n.WARN:
235
- console.warn(a);
236
- break;
237
- case n.ERROR:
238
- console.error(a);
239
- break;
240
- }
241
- }
242
- getWinstonLevel(e) {
243
- switch (e) {
244
- case n.DEBUG:
245
- return "debug";
246
- case n.INFO:
247
- return "info";
248
- case n.WARN:
249
- return "warn";
250
- case n.ERROR:
251
- return "error";
252
- default:
253
- return "info";
254
- }
255
- }
256
- setLevel(e) {
257
- super.setLevel(e), this.winston && (this.winston.level = this.getWinstonLevel(e));
258
- }
259
- }
260
- function W(t) {
261
- return {
262
- write: (e) => {
263
- t.info(e.trim());
264
- }
265
- };
266
- }
267
- class c extends p {
268
- constructor(e = {}) {
269
- super(e);
270
- }
271
- writeLog(e) {
272
- const r = this.formatMessage(e), s = this.getConsoleStyle(e.level), o = e.metadata ? ` ${f(e.metadata)}` : "", a = `%c${r}${o}`;
273
- switch (e.level) {
274
- case n.DEBUG:
275
- console.debug ? console.debug(a, s) : console.log(a, s);
276
- break;
277
- case n.INFO:
278
- console.info(a, s);
279
- break;
280
- case n.WARN:
281
- console.warn(a, s);
282
- break;
283
- case n.ERROR:
284
- console.error(a, s);
285
- break;
286
- }
287
- }
288
- createChild() {
289
- return new c(this.config);
290
- }
291
- formatMessage(e) {
292
- const r = e.timestamp.toISOString(), s = n[e.level].toUpperCase();
293
- return `[${r}] ${s}: ${e.message}`;
294
- }
295
- getConsoleStyle(e) {
296
- if (!this.config.colorize)
297
- return "";
298
- switch (e) {
299
- case n.DEBUG:
300
- return "color: #888; font-weight: normal;";
301
- case n.INFO:
302
- return "color: #007acc; font-weight: normal;";
303
- case n.WARN:
304
- return "color: #ff8c00; font-weight: bold;";
305
- case n.ERROR:
306
- return "color: #dc3545; font-weight: bold;";
307
- default:
308
- return "";
309
- }
310
- }
311
- shouldLogInProduction() {
312
- return (globalThis.process?.env?.NODE_ENV || globalThis.process?.env?.NEXT_PUBLIC_APP_ENV || "development") !== "production" || this.level <= n.ERROR;
313
- }
314
- shouldLog(e) {
315
- return !this.shouldLogInProduction() && e < n.ERROR ? !1 : super.shouldLog(e);
316
- }
317
- }
318
- class G extends c {
319
- constructor() {
320
- super(...arguments), this.groupStack = [];
321
- }
322
- group(e) {
323
- console.group(e), this.groupStack.push(e);
324
- }
325
- groupCollapsed(e) {
326
- console.groupCollapsed(e), this.groupStack.push(e);
327
- }
328
- groupEnd() {
329
- console.groupEnd(), this.groupStack.pop();
330
- }
331
- getCurrentGroupStack() {
332
- return [...this.groupStack];
333
- }
334
- getCurrentGroupPath() {
335
- return this.groupStack.join(" > ");
336
- }
337
- time(e) {
338
- console.time(e);
339
- }
340
- timeEnd(e) {
341
- console.timeEnd(e);
342
- }
343
- trace(e, r) {
344
- console.trace(e, r);
345
- }
346
- count(e) {
347
- console.count(e);
348
- }
349
- countReset(e) {
350
- console.countReset(e);
351
- }
352
- table(e) {
353
- console.table(e);
354
- }
355
- }
356
- class A extends c {
357
- mark(e) {
358
- typeof performance < "u" && performance.mark && performance.mark(e);
359
- }
360
- measure(e, r, s) {
361
- if (typeof performance < "u" && performance.measure)
362
- try {
363
- performance.measure(e, r, s);
364
- const o = performance.getEntriesByName(e, "measure");
365
- if (o.length > 0) {
366
- const a = o[o.length - 1];
367
- this.info(`Performance: ${e}`, {
368
- duration: a.duration,
369
- startTime: a.startTime
370
- });
371
- }
372
- } catch (o) {
373
- this.warn("Failed to measure performance", { name: e, error: o });
374
- }
375
- }
376
- clearMarks(e) {
377
- typeof performance < "u" && performance.clearMarks && performance.clearMarks(e);
378
- }
379
- clearMeasures(e) {
380
- typeof performance < "u" && performance.clearMeasures && performance.clearMeasures(e);
381
- }
382
- }
383
- function h() {
384
- const t = d();
385
- return {
386
- level: n.INFO,
387
- format: "text",
388
- timestamp: !0,
389
- colorize: t.capabilities.colorSupport,
390
- metadata: {},
391
- transports: [
392
- {
393
- type: "console",
394
- options: {}
395
- }
396
- ]
397
- };
398
- }
399
- function _() {
400
- const t = {};
401
- if (typeof process < "u" && process.env) {
402
- const e = process.env;
403
- e.LOG_LEVEL && (t.level = L(e.LOG_LEVEL)), e.LOG_FORMAT && ["json", "text"].includes(e.LOG_FORMAT) && (t.format = e.LOG_FORMAT), e.LOG_TIMESTAMP && (t.timestamp = e.LOG_TIMESTAMP.toLowerCase() === "true"), e.LOG_COLOR && (t.colorize = e.LOG_COLOR.toLowerCase() === "true");
404
- }
405
- return t;
406
- }
407
- async function x(t) {
408
- const e = d();
409
- if (!e.capabilities.fileSystem)
410
- return {};
411
- const r = t ? [t] : [
412
- "logan.config.json",
413
- "logan.config.js",
414
- ".loganrc",
415
- "package.json"
416
- // Check for logan config in package.json
417
- ];
418
- for (const s of r)
419
- try {
420
- if (e.name === "node")
421
- return await w(s);
422
- if (e.name === "deno")
423
- return await S(s);
424
- if (e.name === "bun")
425
- return await v(s);
426
- } catch {
427
- }
428
- return {};
429
- }
430
- async function w(t) {
431
- try {
432
- const e = await import("./__vite-browser-external-DYxpcVy9.mjs"), r = await import("./__vite-browser-external-DYxpcVy9.mjs");
433
- if (t.endsWith(".json")) {
434
- const s = await e.readFile(t, "utf-8"), o = JSON.parse(s);
435
- return t === "package.json" ? o.logan || {} : o;
436
- } else if (t.endsWith(".js")) {
437
- const s = r.resolve(t);
438
- delete require.cache[s];
439
- const o = require(s);
440
- return o.default || o;
441
- }
442
- } catch {
443
- }
444
- return {};
445
- }
446
- async function S(t) {
447
- try {
448
- if (t.endsWith(".json")) {
449
- const e = await globalThis.Deno.readTextFile(t), r = JSON.parse(e);
450
- return t === "package.json" ? r.logan || {} : r;
451
- } else if (t.endsWith(".js")) {
452
- const e = await import(
453
- /* @vite-ignore */
454
- `./${t}`
455
- );
456
- return e.default || e;
457
- }
458
- } catch {
459
- }
460
- return {};
461
- }
462
- async function v(t) {
463
- return w(t);
464
- }
465
- function L(t) {
466
- switch (t.toLowerCase()) {
467
- case "debug":
468
- return n.DEBUG;
469
- case "info":
470
- return n.INFO;
471
- case "warn":
472
- case "warning":
473
- return n.WARN;
474
- case "error":
475
- return n.ERROR;
476
- case "silent":
477
- case "none":
478
- return n.SILENT;
479
- default:
480
- return n.INFO;
481
- }
482
- }
483
- function j(...t) {
484
- const e = h();
485
- return t.reduce((r, s) => ({
486
- ...r,
487
- ...s,
488
- metadata: {
489
- ...r.metadata,
490
- ...s.metadata
491
- },
492
- transports: s.transports || r.transports
493
- }), e);
494
- }
495
- class C {
496
- /**
497
- * Create a logger instance appropriate for the current runtime.
498
- * @param config - Optional configuration for the logger
499
- * @returns A logger instance
500
- */
501
- static create(e = {}) {
502
- const r = d(), s = this.mergeConfig(e);
503
- switch (r.name) {
504
- case "node":
505
- return new m(s);
506
- case "deno":
507
- return new c(s);
508
- case "bun":
509
- return new m(s);
510
- case "browser":
511
- case "webworker":
512
- return new c(s);
513
- default:
514
- return new c(s);
515
- }
516
- }
517
- /**
518
- * Create a child logger with additional metadata.
519
- * @param parent - The parent logger instance
520
- * @param metadata - Additional metadata to include in all child log messages
521
- * @returns A new logger instance with the additional metadata
522
- */
523
- static createChild(e, r) {
524
- return e.child(r);
525
- }
526
- static mergeConfig(e) {
527
- const r = h();
528
- return {
529
- ...r,
530
- ...e,
531
- metadata: {
532
- ...r.metadata,
533
- ...e.metadata
534
- }
535
- };
536
- }
537
- }
538
- function k(t) {
539
- return C.create(t);
540
- }
541
- function y() {
542
- const t = I(), e = {
543
- level: F(t),
544
- colorize: t !== "production",
545
- timestamp: !0,
546
- format: t === "production" ? "json" : "text"
547
- };
548
- return k(e);
549
- }
550
- function I() {
551
- return typeof process < "u" && process.env ? process.env.NODE_ENV || process.env.NEXT_PUBLIC_APP_ENV || process.env.ENVIRONMENT || "development" : typeof window < "u" && globalThis.__ENV__ || "development";
552
- }
553
- function F(t) {
554
- switch (t) {
555
- case "production":
556
- return n.ERROR;
557
- case "staging":
558
- case "test":
559
- return n.WARN;
560
- case "development":
561
- case "dev":
562
- return n.DEBUG;
563
- default:
564
- return n.INFO;
565
- }
566
- }
567
- function U(t) {
568
- switch (t.toLowerCase()) {
569
- case "debug":
570
- return n.DEBUG;
571
- case "info":
572
- return n.INFO;
573
- case "warn":
574
- case "warning":
575
- return n.WARN;
576
- case "error":
577
- return n.ERROR;
578
- case "silent":
579
- case "none":
580
- return n.SILENT;
581
- default:
582
- return n.INFO;
583
- }
584
- }
585
- function P(t) {
586
- switch (t) {
587
- case n.DEBUG:
588
- return "debug";
589
- case n.INFO:
590
- return "info";
591
- case n.WARN:
592
- return "warn";
593
- case n.ERROR:
594
- return "error";
595
- case n.SILENT:
596
- return "silent";
597
- default:
598
- return "info";
599
- }
600
- }
601
- function V(t, e = "text") {
602
- if (e === "json") {
603
- const a = {
604
- timestamp: t.timestamp.toISOString(),
605
- level: n[t.level].toLowerCase(),
606
- message: t.message,
607
- runtime: t.runtime
608
- };
609
- return t.metadata !== void 0 && (a.metadata = t.metadata), f(a);
610
- }
611
- const r = t.timestamp.toISOString(), s = n[t.level].toUpperCase(), o = t.metadata ? ` ${f(t.metadata)}` : "";
612
- return `[${r}] ${s}: ${t.message}${o}`;
613
- }
614
- function z(t, e = !1) {
615
- const r = n[t].toUpperCase();
616
- if (!e)
617
- return r;
618
- const s = {
619
- [n.DEBUG]: "\x1B[36m",
620
- // Cyan
621
- [n.INFO]: "\x1B[32m",
622
- // Green
623
- [n.WARN]: "\x1B[33m",
624
- // Yellow
625
- [n.ERROR]: "\x1B[31m",
626
- // Red
627
- [n.SILENT]: "\x1B[37m"
628
- // White
629
- };
630
- return `${s[t] || s[n.INFO]}${r}\x1B[0m`;
631
- }
632
- const l = y(), H = {
633
- debug: (t, e) => l.debug(t, e),
634
- info: (t, e) => l.info(t, e),
635
- warn: (t, e) => l.warn(t, e),
636
- error: (t, e) => l.error(t, e)
1
+ import { c as a } from "./node-BqvVrzA_.mjs";
2
+ import { b as t, B as f, C as l, L, d as m, P as c, a as d, e as v, p, j as u, f as C, h as B, g as F, i as w, k as E, m as b, l as x, n as y, o as D, q as S, s as P } from "./node-BqvVrzA_.mjs";
3
+ import { formatLevel as h, formatLogEntry as j } from "./deno.esm.js";
4
+ const r = a(), g = {
5
+ debug: (e, o) => r.debug(e, o),
6
+ info: (e, o) => r.info(e, o),
7
+ warn: (e, o) => r.warn(e, o),
8
+ error: (e, o) => r.error(e, o)
637
9
  };
638
10
  export {
639
- p as BaseLogger,
640
- c as BrowserLogger,
641
- G as ConsoleGroupLogger,
642
- n as LogLevel,
643
- C as LoggerFactory,
644
- m as NodeLogger,
645
- A as PerformanceLogger,
646
- k as createLogger,
647
- y as createLoggerForEnvironment,
648
- W as createMorganStream,
649
- d as detectRuntime,
650
- N as filterSensitiveData,
651
- z as formatLevel,
652
- V as formatLogEntry,
653
- h as getDefaultConfig,
654
- B as isBrowser,
655
- $ as isBun,
656
- D as isDeno,
657
- T as isNode,
658
- _ as loadConfigFromEnvironment,
659
- x as loadConfigFromFile,
660
- H as log,
661
- P as logLevelToString,
662
- l as logger,
663
- j as mergeConfigs,
664
- f as safeStringify,
665
- M as serializeError,
666
- U as stringToLogLevel
11
+ t as BaseLogger,
12
+ f as BrowserLogger,
13
+ l as ConsoleGroupLogger,
14
+ L as LogLevel,
15
+ m as LoggerFactory,
16
+ c as PerformanceLogger,
17
+ d as createLogger,
18
+ a as createLoggerForEnvironment,
19
+ v as detectRuntime,
20
+ p as filterSensitiveData,
21
+ h as formatLevel,
22
+ j as formatLogEntry,
23
+ u as getDefaultConfig,
24
+ C as isBrowser,
25
+ B as isBun,
26
+ F as isDeno,
27
+ w as isNode,
28
+ E as loadConfigFromEnvironment,
29
+ b as loadConfigFromFile,
30
+ g as log,
31
+ x as logLevelToString,
32
+ r as logger,
33
+ y as mergeConfigs,
34
+ D as safeStringify,
35
+ S as serializeError,
36
+ P as stringToLogLevel
667
37
  };