logan-logger 1.1.2 → 1.1.6

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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Safely stringify an object to JSON, handling circular references,
3
+ * Error objects, functions, and other non-serializable values.
4
+ * @param obj - The object to stringify
5
+ * @param space - Number of spaces for pretty-printing (optional)
6
+ * @returns JSON string representation
7
+ */
8
+ export declare function safeStringify(obj: any, space?: number): string;
9
+ /**
10
+ * Filter out sensitive data from an object before logging.
11
+ * @param obj - The object to filter
12
+ * @param sensitiveKeys - Array of key names to redact (case-insensitive)
13
+ * @returns A new object with sensitive values replaced with '[REDACTED]'
14
+ * @example
15
+ * ```typescript
16
+ * const data = { username: 'john', password: 'secret123' };
17
+ * const filtered = filterSensitiveData(data);
18
+ * // Result: { username: 'john', password: '[REDACTED]' }
19
+ * ```
20
+ */
21
+ export declare function filterSensitiveData(obj: any, sensitiveKeys?: string[]): any;
22
+ /**
23
+ * Serialize Error objects to plain objects for logging.
24
+ * @param error - The error to serialize
25
+ * @returns Serialized error object or original value if not an Error
26
+ * @example
27
+ * ```typescript
28
+ * const error = new Error('Something went wrong');
29
+ * const serialized = serializeError(error);
30
+ * // Result: { name: 'Error', message: 'Something went wrong', stack: '...' }
31
+ * ```
32
+ */
33
+ export declare function serializeError(error: any): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logan-logger",
3
- "version": "1.1.2",
3
+ "version": "1.1.6",
4
4
  "description": "Universal TypeScript logging library for all JavaScript runtimes",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -83,6 +83,7 @@
83
83
  "test:coverage": "vitest run --coverage",
84
84
  "lint": "eslint src --ext .ts",
85
85
  "typecheck": "tsc --noEmit",
86
+ "bump": "npm version patch",
86
87
  "publish:jsr": "deno publish --set-version ${npm_package_version:-$(npm pkg get version | tr -d '\"')}"
87
88
  }
88
89
  }
@@ -1 +0,0 @@
1
- "use strict";var N=Object.create;var h=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var k=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!C.call(t,n)&&n!==r&&h(t,n,{get:()=>e[n],enumerable:!(s=v(e,n))||s.enumerable});return t};var F=(t,e,r)=>(r=t!=null?N(y(t)):{},k(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t));var o=(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))(o||{});function l(){const t=f(),e=T(t),r=I(t);return{name:t,version:e,capabilities:r}}function f(){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"}function T(t){switch(t){case"node":return typeof process<"u"?process.version:void 0;case"deno":return typeof globalThis.Deno<"u"?globalThis.Deno.version?.deno:void 0;case"bun":return typeof globalThis.Bun<"u"?globalThis.Bun.version:void 0;case"browser":return typeof navigator<"u"?navigator.userAgent:void 0;default:return}}function I(t){switch(t){case"node":return{fileSystem:!0,colorSupport:!0,processInfo:!0,streams:!0};case"deno":return{fileSystem:!0,colorSupport:!0,processInfo:!0,streams:!0};case"bun":return{fileSystem:!0,colorSupport:!0,processInfo:!0,streams:!0};case"browser":return{fileSystem:!1,colorSupport:!0,processInfo:!1,streams:!1};case"webworker":return{fileSystem:!1,colorSupport:!1,processInfo:!1,streams:!1};default:return{fileSystem:!1,colorSupport:!1,processInfo:!1,streams:!1}}}function D(){return f()==="node"}function M(){return f()==="browser"}function B(){return f()==="deno"}function W(){return f()==="bun"}class g{constructor(e={}){this.childMetadata={},this.config=e,this.level=e.level??o.INFO,this.runtime=l().name}debug(e,r){this.log(o.DEBUG,e,r)}info(e,r){this.log(o.INFO,e,r)}warn(e,r){this.log(o.WARN,e,r)}error(e,r){this.log(o.ERROR,e,r)}log(e,r,s){if(!this.shouldLog(e))return;const n=typeof r=="function"?r():r,a={...this.childMetadata,...s},i={timestamp:new Date,level:e,message:n,metadata:Object.keys(a).length>0?a:void 0,runtime:this.runtime};this.writeLog(i)}setLevel(e){this.level=e}getLevel(){return this.level}child(e){const r=this.createChild();return r.childMetadata={...this.childMetadata,...e},r}shouldLog(e){return e>=this.level}}function d(t,e){const r=new WeakSet;return JSON.stringify(t,(s,n)=>{if(typeof n=="object"&&n!==null){if(r.has(n))return"[Circular]";r.add(n)}return n instanceof Error?{name:n.name,message:n.message,stack:n.stack,...Object.getOwnPropertyNames(n).reduce((a,i)=>(i!=="name"&&i!=="message"&&i!=="stack"&&(a[i]=n[i]),a),{})}:typeof n=="function"?`[Function: ${n.name||"anonymous"}]`:n===void 0?"[undefined]":typeof n=="bigint"?`[BigInt: ${n.toString()}]`:typeof n=="symbol"?`[Symbol: ${n.toString()}]`:n},e)}function w(t,e=["password","token","secret","key","auth"]){if(typeof t!="object"||t===null)return t;const r=Array.isArray(t)?[]:{};for(const[s,n]of Object.entries(t))e.some(i=>s.toLowerCase().includes(i.toLowerCase()))?r[s]="[REDACTED]":typeof n=="object"&&n!==null?r[s]=w(n,e):r[s]=n;return r}function G(t){return t instanceof Error?{name:t.name,message:t.message,stack:t.stack,...t}:t}class u extends g{constructor(e={}){super(e),this.initializeWinston()}async initializeWinston(){try{const e=await import("winston");this.winston=this.createWinstonLogger(e)}catch{console.warn("[logan-logger] Winston not found, falling back to console logging")}}createWinstonLogger(e){const r=e.format.combine(e.format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),e.format.errors({stack:!0}),e.format.json(),e.format.prettyPrint()),s=e.format.combine(e.format.colorize(),e.format.timestamp({format:"HH:mm:ss"}),e.format.printf(({timestamp:a,level:i,message:b,...p})=>{const L=Object.keys(p).length?JSON.stringify(p,null,2):"";return`${a} [${i}]: ${b} ${L}`})),n=e.createLogger({level:this.getWinstonLevel(this.level),format:r,transports:[new e.transports.Console({format:process.env.NODE_ENV==="production"?r:s})]});return process.env.NODE_ENV==="production"&&(n.add(new e.transports.File({filename:"logs/error.log",level:"error",maxsize:5242880,maxFiles:5})),n.add(new e.transports.File({filename:"logs/combined.log",maxsize:5242880,maxFiles:10}))),n}writeLog(e){this.winston?this.winston.log({level:this.getWinstonLevel(e.level),message:e.message,timestamp:e.timestamp,...e.metadata}):this.writeToConsole(e)}createChild(){return new u(this.config)}writeToConsole(e){const r=e.timestamp.toISOString(),s=o[e.level].toLowerCase(),n=e.metadata?` ${d(e.metadata)}`:"",a=`[${r}] ${s.toUpperCase()}: ${e.message}${n}`;switch(e.level){case o.DEBUG:console.debug(a);break;case o.INFO:console.info(a);break;case o.WARN:console.warn(a);break;case o.ERROR:console.error(a);break}}getWinstonLevel(e){switch(e){case o.DEBUG:return"debug";case o.INFO:return"info";case o.WARN:return"warn";case o.ERROR:return"error";default:return"info"}}setLevel(e){super.setLevel(e),this.winston&&(this.winston.level=this.getWinstonLevel(e))}}function A(t){return{write:e=>{t.info(e.trim())}}}class c extends g{constructor(e={}){super(e)}writeLog(e){const r=this.formatMessage(e),s=this.getConsoleStyle(e.level),n=e.metadata?` ${d(e.metadata)}`:"",a=`%c${r}${n}`;switch(e.level){case o.DEBUG:console.debug?console.debug(a,s):console.log(a,s);break;case o.INFO:console.info(a,s);break;case o.WARN:console.warn(a,s);break;case o.ERROR:console.error(a,s);break}}createChild(){return new c(this.config)}formatMessage(e){const r=e.timestamp.toISOString(),s=o[e.level].toUpperCase();return`[${r}] ${s}: ${e.message}`}getConsoleStyle(e){if(!this.config.colorize)return"";switch(e){case o.DEBUG:return"color: #888; font-weight: normal;";case o.INFO:return"color: #007acc; font-weight: normal;";case o.WARN:return"color: #ff8c00; font-weight: bold;";case o.ERROR:return"color: #dc3545; font-weight: bold;";default:return""}}shouldLogInProduction(){return(globalThis.process?.env?.NODE_ENV||globalThis.process?.env?.NEXT_PUBLIC_APP_ENV||"development")!=="production"||this.level<=o.ERROR}shouldLog(e){return!this.shouldLogInProduction()&&e<o.ERROR?!1:super.shouldLog(e)}}class _ extends c{constructor(){super(...arguments),this.groupStack=[]}group(e){console.group(e),this.groupStack.push(e)}groupCollapsed(e){console.groupCollapsed(e),this.groupStack.push(e)}groupEnd(){console.groupEnd(),this.groupStack.pop()}getCurrentGroupStack(){return[...this.groupStack]}getCurrentGroupPath(){return this.groupStack.join(" > ")}time(e){console.time(e)}timeEnd(e){console.timeEnd(e)}trace(e,r){console.trace(e,r)}count(e){console.count(e)}countReset(e){console.countReset(e)}table(e){console.table(e)}}class $ extends c{mark(e){typeof performance<"u"&&performance.mark&&performance.mark(e)}measure(e,r,s){if(typeof performance<"u"&&performance.measure)try{performance.measure(e,r,s);const n=performance.getEntriesByName(e,"measure");if(n.length>0){const a=n[n.length-1];this.info(`Performance: ${e}`,{duration:a.duration,startTime:a.startTime})}}catch(n){this.warn("Failed to measure performance",{name:e,error:n})}}clearMarks(e){typeof performance<"u"&&performance.clearMarks&&performance.clearMarks(e)}clearMeasures(e){typeof performance<"u"&&performance.clearMeasures&&performance.clearMeasures(e)}}function m(){const t=l();return{level:o.INFO,format:"text",timestamp:!0,colorize:t.capabilities.colorSupport,metadata:{},transports:[{type:"console",options:{}}]}}function P(){const t={};if(typeof process<"u"&&process.env){const e=process.env;e.LOG_LEVEL&&(t.level=z(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")}return t}async function j(t){const e=l();if(!e.capabilities.fileSystem)return{};const r=t?[t]:["logan.config.json","logan.config.js",".loganrc","package.json"];for(const s of r)try{if(e.name==="node")return await E(s);if(e.name==="deno")return await U(s);if(e.name==="bun")return await x(s)}catch{}return{}}async function E(t){try{const e=await Promise.resolve().then(()=>require("./__vite-browser-external-BcPniuRQ.js")),r=await Promise.resolve().then(()=>require("./__vite-browser-external-BcPniuRQ.js"));if(t.endsWith(".json")){const s=await e.readFile(t,"utf-8"),n=JSON.parse(s);return t==="package.json"?n.logan||{}:n}else if(t.endsWith(".js")){const s=r.resolve(t);delete require.cache[s];const n=require(s);return n.default||n}}catch{}return{}}async function U(t){try{if(t.endsWith(".json")){const e=await globalThis.Deno.readTextFile(t),r=JSON.parse(e);return t==="package.json"?r.logan||{}:r}else if(t.endsWith(".js")){const e=await import(`./${t}`);return e.default||e}}catch{}return{}}async function x(t){return E(t)}function z(t){switch(t.toLowerCase()){case"debug":return o.DEBUG;case"info":return o.INFO;case"warn":case"warning":return o.WARN;case"error":return o.ERROR;case"silent":case"none":return o.SILENT;default:return o.INFO}}function V(...t){const e=m();return t.reduce((r,s)=>({...r,...s,metadata:{...r.metadata,...s.metadata},transports:s.transports||r.transports}),e)}class R{static create(e={}){const r=l(),s=this.mergeConfig(e);switch(r.name){case"node":return new u(s);case"deno":return new c(s);case"bun":return new u(s);case"browser":case"webworker":return new c(s);default:return new c(s)}}static createChild(e,r){return e.child(r)}static mergeConfig(e){const r=m();return{...r,...e,metadata:{...r.metadata,...e.metadata}}}}function O(t){return R.create(t)}function q(){const t=H(),e={level:J(t),colorize:t!=="production",timestamp:!0,format:t==="production"?"json":"text"};return O(e)}function H(){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"}function J(t){switch(t){case"production":return o.ERROR;case"staging":case"test":return o.WARN;case"development":case"dev":return o.DEBUG;default:return o.INFO}}function Y(t){switch(t.toLowerCase()){case"debug":return o.DEBUG;case"info":return o.INFO;case"warn":case"warning":return o.WARN;case"error":return o.ERROR;case"silent":case"none":return o.SILENT;default:return o.INFO}}function X(t){switch(t){case o.DEBUG:return"debug";case o.INFO:return"info";case o.WARN:return"warn";case o.ERROR:return"error";case o.SILENT:return"silent";default:return"info"}}exports.BaseLogger=g;exports.BrowserLogger=c;exports.ConsoleGroupLogger=_;exports.LogLevel=o;exports.LoggerFactory=R;exports.NodeLogger=u;exports.PerformanceLogger=$;exports.createLogger=O;exports.createLoggerForEnvironment=q;exports.createMorganStream=A;exports.detectRuntime=l;exports.filterSensitiveData=w;exports.getDefaultConfig=m;exports.isBrowser=M;exports.isBun=W;exports.isDeno=B;exports.isNode=D;exports.loadConfigFromEnvironment=P;exports.loadConfigFromFile=j;exports.logLevelToString=X;exports.mergeConfigs=V;exports.safeStringify=d;exports.serializeError=G;exports.stringToLogLevel=Y;
@@ -1,626 +0,0 @@
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 f() {
3
- const t = u(), e = R(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 R(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 F() {
75
- return u() === "node";
76
- }
77
- function I() {
78
- return u() === "browser";
79
- }
80
- function T() {
81
- return u() === "deno";
82
- }
83
- function D() {
84
- return u() === "bun";
85
- }
86
- class m {
87
- constructor(e = {}) {
88
- this.childMetadata = {}, this.config = e, this.level = e.level ?? n.INFO, this.runtime = f().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 g(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 O(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] = O(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 l extends m {
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: w, ...d }) => {
185
- const E = Object.keys(d).length ? JSON.stringify(d, null, 2) : "";
186
- return `${a} [${i}]: ${w} ${E}`;
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 l(this.config);
224
- }
225
- writeToConsole(e) {
226
- const r = e.timestamp.toISOString(), s = n[e.level].toLowerCase(), o = e.metadata ? ` ${g(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 m {
268
- constructor(e = {}) {
269
- super(e);
270
- }
271
- writeLog(e) {
272
- const r = this.formatMessage(e), s = this.getConsoleStyle(e.level), o = e.metadata ? ` ${g(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 B 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 G 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 p() {
384
- const t = f();
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 A() {
400
- const t = {};
401
- if (typeof process < "u" && process.env) {
402
- const e = process.env;
403
- e.LOG_LEVEL && (t.level = y(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 _(t) {
408
- const e = f();
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 h(s);
422
- if (e.name === "deno")
423
- return await N(s);
424
- if (e.name === "bun")
425
- return await S(s);
426
- } catch {
427
- }
428
- return {};
429
- }
430
- async function h(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 N(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 S(t) {
463
- return h(t);
464
- }
465
- function y(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 $(...t) {
484
- const e = p();
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 v {
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 = f(), s = this.mergeConfig(e);
503
- switch (r.name) {
504
- case "node":
505
- return new l(s);
506
- case "deno":
507
- return new c(s);
508
- case "bun":
509
- return new l(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 = p();
528
- return {
529
- ...r,
530
- ...e,
531
- metadata: {
532
- ...r.metadata,
533
- ...e.metadata
534
- }
535
- };
536
- }
537
- }
538
- function L(t) {
539
- return v.create(t);
540
- }
541
- function j() {
542
- const t = k(), e = {
543
- level: C(t),
544
- colorize: t !== "production",
545
- timestamp: !0,
546
- format: t === "production" ? "json" : "text"
547
- };
548
- return L(e);
549
- }
550
- function k() {
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 C(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 P(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 U(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
- export {
602
- c as B,
603
- B as C,
604
- n as L,
605
- l as N,
606
- G as P,
607
- L as a,
608
- m as b,
609
- j as c,
610
- v as d,
611
- f as e,
612
- I as f,
613
- T as g,
614
- D as h,
615
- F as i,
616
- p as j,
617
- A as k,
618
- U as l,
619
- _ as m,
620
- $ as n,
621
- g as o,
622
- O as p,
623
- M as q,
624
- W as r,
625
- P as s
626
- };