logan-logger 2.5.1 → 2.5.2
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/browser.cjs +1 -1
- package/dist/browser.mjs +20 -20
- package/dist/bun.cjs +1 -1
- package/dist/bun.mjs +4 -4
- package/dist/chunks/{config-file-z0J0xfos.mjs → config-file-B2bCuTsh.mjs} +158 -149
- package/dist/chunks/config-file-Bi7lhPHV.cjs +1 -0
- package/dist/chunks/{file-transport-DF_YtZ1J.mjs → file-transport-DtEHuVUw.mjs} +2 -2
- package/dist/chunks/file-transport-jelqRjCs.cjs +1 -0
- package/dist/chunks/{config-DsFnr-rq.mjs → formatting-DTrgGC8g.mjs} +62 -56
- package/dist/chunks/{config-BoVokyIX.cjs → formatting-pzIQGL_7.cjs} +1 -1
- package/dist/core/types.d.cts +12 -0
- package/dist/core/types.d.mts +12 -0
- package/dist/core/types.d.ts +12 -0
- package/dist/deno.cjs +1 -1
- package/dist/deno.mjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +8 -8
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +2 -2
- package/dist/utils/config.d.cts +87 -4
- package/dist/utils/config.d.mts +87 -4
- package/dist/utils/config.d.ts +87 -4
- package/package.json +1 -1
- package/dist/chunks/config-file-C_hoT1V-.cjs +0 -1
- package/dist/chunks/file-transport-93M9zaPy.cjs +0 -1
package/dist/browser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/formatting-pzIQGL_7.cjs");function t(){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 n(t){switch(t){case`production`:return e.y.ERROR;case`staging`:case`test`:return e.y.WARN;case`development`:case`dev`:return e.y.DEBUG;default:return e.y.INFO}}function r(t={}){let n=t.ignoreEnvironment?{}:e.a();return new e.f(e.r(e.o(t,n)))}function i(){let e=t();return r({level:n(e),colorize:e!==`production`,timestamp:!0,format:e===`production`?`json`:`text`})}var a=i(),o={debug:(e,t)=>a.debug(e,t),info:(e,t)=>a.info(e,t),warn:(e,t)=>a.warn(e,t),error:(e,t)=>a.error(e,t)};exports.BrowserLogger=e.f,exports.ConsoleGroupLogger=e.p,exports.LogLevel=e.y,exports.PerformanceLogger=e.m,exports.createLogger=r,exports.createLoggerForEnvironment=i,exports.detectRuntime=e.b,exports.filterSensitiveData=e.h,exports.formatLevel=e.t,exports.formatLogEntry=e.n,exports.isBrowser=e.x,exports.isBun=e.S,exports.isDeno=e.C,exports.isNode=e.w,exports.log=o,exports.logger=a,exports.safeStringify=e.g,exports.serializeError=e._;
|
package/dist/browser.mjs
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as e, S as t, _ as n, a as r, b as i, f as a, g as o, h as s, m as c, n as l, o as u, p as d, r as f, t as p, w as m, x as h, y as g } from "./chunks/formatting-DTrgGC8g.mjs";
|
|
2
2
|
//#region src/browser.ts
|
|
3
|
-
function
|
|
3
|
+
function _() {
|
|
4
4
|
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";
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function v(e) {
|
|
7
7
|
switch (e) {
|
|
8
|
-
case "production": return
|
|
8
|
+
case "production": return g.ERROR;
|
|
9
9
|
case "staging":
|
|
10
|
-
case "test": return
|
|
10
|
+
case "test": return g.WARN;
|
|
11
11
|
case "development":
|
|
12
|
-
case "dev": return
|
|
13
|
-
default: return
|
|
12
|
+
case "dev": return g.DEBUG;
|
|
13
|
+
default: return g.INFO;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
let t = e.ignoreEnvironment ? {} :
|
|
18
|
-
return new f(
|
|
16
|
+
function y(e = {}) {
|
|
17
|
+
let t = e.ignoreEnvironment ? {} : r();
|
|
18
|
+
return new a(f(u(e, t)));
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
let e =
|
|
22
|
-
return
|
|
23
|
-
level:
|
|
20
|
+
function b() {
|
|
21
|
+
let e = _();
|
|
22
|
+
return y({
|
|
23
|
+
level: v(e),
|
|
24
24
|
colorize: e !== "production",
|
|
25
25
|
timestamp: !0,
|
|
26
26
|
format: e === "production" ? "json" : "text"
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
var
|
|
30
|
-
debug: (e, t) =>
|
|
31
|
-
info: (e, t) =>
|
|
32
|
-
warn: (e, t) =>
|
|
33
|
-
error: (e, t) =>
|
|
29
|
+
var x = b(), S = {
|
|
30
|
+
debug: (e, t) => x.debug(e, t),
|
|
31
|
+
info: (e, t) => x.info(e, t),
|
|
32
|
+
warn: (e, t) => x.warn(e, t),
|
|
33
|
+
error: (e, t) => x.error(e, t)
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
36
|
-
export {
|
|
36
|
+
export { a as BrowserLogger, d as ConsoleGroupLogger, g as LogLevel, c as PerformanceLogger, y as createLogger, b as createLoggerForEnvironment, i as detectRuntime, s as filterSensitiveData, p as formatLevel, l as formatLogEntry, h as isBrowser, t as isBun, e as isDeno, m as isNode, S as log, x as logger, o as safeStringify, n as serializeError };
|
package/dist/bun.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/formatting-pzIQGL_7.cjs"),t=require("./chunks/config-file-Bi7lhPHV.cjs"),n=require("./chunks/file-transport-jelqRjCs.cjs");exports.ConsoleTransport=t.l,exports.FileTransport=n.t,exports.NodeLogger=t.s,exports.applyNoColorOverride=e.r,exports.createLogger=t.r,exports.createLoggerForEnvironment=t.i,exports.createTransports=t.u,exports.detectRuntime=e.b,exports.filterSensitiveData=e.h,exports.formatLevel=e.t,exports.formatLogEntry=e.n,exports.getDefaultConfig=e.i,exports.isBrowser=e.x,exports.isBun=e.S,exports.isDeno=e.C,exports.isNode=e.w,exports.loadConfigFromEnvironment=e.a,exports.loadConfigFromFile=t.t,exports.mergeConfigs=e.o,exports.noColorRequested=e.s,exports.registerTransport=t.f,exports.resetEnvironmentWarnings=e.c,exports.safeStringify=e.g,exports.serializeError=e._,exports.shouldColorize=e.l,exports.tryParseLogLevel=e.u;
|
package/dist/bun.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as
|
|
3
|
-
import { t as
|
|
4
|
-
export {
|
|
1
|
+
import { C as e, S as t, _ as n, a as r, b as i, c as a, g as o, h as s, i as c, l, n as u, o as d, r as f, s as p, t as m, u as h, w as g, x as _ } from "./chunks/formatting-DTrgGC8g.mjs";
|
|
2
|
+
import { f as v, i as y, l as b, r as x, s as S, t as C, u as w } from "./chunks/config-file-B2bCuTsh.mjs";
|
|
3
|
+
import { t as T } from "./chunks/file-transport-DtEHuVUw.mjs";
|
|
4
|
+
export { b as ConsoleTransport, T as FileTransport, S as NodeLogger, f as applyNoColorOverride, x as createLogger, y as createLoggerForEnvironment, w as createTransports, i as detectRuntime, s as filterSensitiveData, m as formatLevel, u as formatLogEntry, c as getDefaultConfig, _ as isBrowser, t as isBun, e as isDeno, g as isNode, r as loadConfigFromEnvironment, C as loadConfigFromFile, d as mergeConfigs, p as noColorRequested, v as registerTransport, a as resetEnvironmentWarnings, o as safeStringify, n as serializeError, l as shouldColorize, h as tryParseLogLevel };
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e, b as t, d as n, f as r, l as i, n as a, o, r as s, s as c, u as l, v as u, y as d } from "./formatting-DTrgGC8g.mjs";
|
|
2
2
|
//#region src/core/transport.ts
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
var f = /* @__PURE__ */ new Map();
|
|
4
|
+
function p(e, t) {
|
|
5
|
+
f.set(e, t);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
return
|
|
7
|
+
function m(e) {
|
|
8
|
+
return f.get(e);
|
|
9
9
|
}
|
|
10
|
-
var
|
|
10
|
+
var h = class {
|
|
11
11
|
constructor(e = {}) {
|
|
12
12
|
this.type = "console", this.level = e.level, this.format = e.format === "json" ? "json" : "text", this.formatOptions = {
|
|
13
13
|
timestamp: e.timestamp !== !1,
|
|
14
14
|
colorize: e.colorize === !0
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
write(
|
|
18
|
-
let
|
|
19
|
-
switch (
|
|
20
|
-
case
|
|
21
|
-
console.debug(
|
|
17
|
+
write(e) {
|
|
18
|
+
let t = a(e, this.format, this.formatOptions);
|
|
19
|
+
switch (e.level) {
|
|
20
|
+
case d.DEBUG:
|
|
21
|
+
console.debug(t);
|
|
22
22
|
break;
|
|
23
|
-
case
|
|
24
|
-
console.warn(
|
|
23
|
+
case d.WARN:
|
|
24
|
+
console.warn(t);
|
|
25
25
|
break;
|
|
26
|
-
case
|
|
27
|
-
console.error(
|
|
26
|
+
case d.ERROR:
|
|
27
|
+
console.error(t);
|
|
28
28
|
break;
|
|
29
|
-
default: console.info(
|
|
29
|
+
default: console.info(t);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
p("console", (e, t) => {
|
|
34
34
|
let n = e.options ?? {};
|
|
35
|
-
return new
|
|
35
|
+
return new h({
|
|
36
36
|
format: n.format ?? t.format,
|
|
37
37
|
timestamp: n.timestamp ?? t.timestamp,
|
|
38
38
|
colorize: n.colorize ?? t.colorize,
|
|
39
39
|
level: e.level
|
|
40
40
|
});
|
|
41
|
-
}),
|
|
41
|
+
}), p("custom", (e, t) => {
|
|
42
42
|
let n = e.options?.transport, r = typeof n == "function" ? n(t) : n;
|
|
43
43
|
if (!r || typeof r.write != "function") throw Error(`custom transport requires options.transport to be an object with a write(entry) method, or a function returning one; ${typeof n == "function" ? "the function it was given returned no write(entry) method" : "it was given no object with a write(entry) method"}`);
|
|
44
44
|
return e.level === void 0 ? r : {
|
|
@@ -48,40 +48,49 @@ d("console", (e, t) => {
|
|
|
48
48
|
close: r.close ? () => r.close?.() : void 0
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
|
-
function
|
|
52
|
-
|
|
51
|
+
function g(e) {
|
|
52
|
+
return {
|
|
53
|
+
...e,
|
|
54
|
+
options: {
|
|
55
|
+
...e.options,
|
|
56
|
+
colorize: !1
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function _(e) {
|
|
61
|
+
let t = c(), n = {
|
|
53
62
|
format: e.format ?? "text",
|
|
54
63
|
timestamp: e.timestamp ?? !0,
|
|
55
|
-
colorize: e.colorize ?? !1
|
|
64
|
+
colorize: t ? !1 : e.colorize ?? !1
|
|
56
65
|
};
|
|
57
|
-
if (e.transports === void 0) return [new
|
|
58
|
-
format:
|
|
59
|
-
timestamp:
|
|
60
|
-
colorize:
|
|
66
|
+
if (e.transports === void 0) return [new h({
|
|
67
|
+
format: n.format,
|
|
68
|
+
timestamp: n.timestamp,
|
|
69
|
+
colorize: n.colorize
|
|
61
70
|
})];
|
|
62
|
-
let
|
|
63
|
-
for (let
|
|
64
|
-
let e =
|
|
71
|
+
let r = [];
|
|
72
|
+
for (let i of e.transports) {
|
|
73
|
+
let e = m(i.type);
|
|
65
74
|
if (!e) {
|
|
66
|
-
console.warn(`[logan-logger] ${
|
|
75
|
+
console.warn(`[logan-logger] ${v(i.type)}`);
|
|
67
76
|
continue;
|
|
68
77
|
}
|
|
69
78
|
try {
|
|
70
|
-
|
|
79
|
+
r.push(e(t ? g(i) : i, n));
|
|
71
80
|
} catch (e) {
|
|
72
|
-
console.warn(`[logan-logger] transport '${
|
|
81
|
+
console.warn(`[logan-logger] transport '${i.type}' failed to initialize:`, e);
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
|
-
return
|
|
84
|
+
return r;
|
|
76
85
|
}
|
|
77
|
-
function
|
|
86
|
+
function v(e) {
|
|
78
87
|
return e === "file" ? "the 'file' transport is not registered; import from 'logan-logger/node' (or 'logan-logger/bun') rather than the main entry point to use file logging" : e === "http" ? "the 'http' transport is not built in; supply one with { type: 'custom', options: { transport } }" : `unknown transport type '${e}'; skipping`;
|
|
79
88
|
}
|
|
80
89
|
//#endregion
|
|
81
90
|
//#region src/runtime/node.ts
|
|
82
|
-
var
|
|
91
|
+
var y = class e extends u {
|
|
83
92
|
constructor(e = {}, t) {
|
|
84
|
-
super(e), this.transports = t ??
|
|
93
|
+
super(e), this.transports = t ?? _(e);
|
|
85
94
|
}
|
|
86
95
|
getTransports() {
|
|
87
96
|
return this.transports;
|
|
@@ -100,81 +109,81 @@ var g = class e extends n {
|
|
|
100
109
|
return new e(this.config, this.transports);
|
|
101
110
|
}
|
|
102
111
|
};
|
|
103
|
-
function
|
|
112
|
+
function b(e) {
|
|
104
113
|
return { write: (t) => {
|
|
105
114
|
e.info(t.trim());
|
|
106
115
|
} };
|
|
107
116
|
}
|
|
108
117
|
//#endregion
|
|
109
118
|
//#region src/core/factory.ts
|
|
110
|
-
var
|
|
111
|
-
static create(
|
|
112
|
-
let
|
|
113
|
-
switch (
|
|
114
|
-
case "node": return new
|
|
115
|
-
case "deno": return new
|
|
116
|
-
case "bun": return new
|
|
119
|
+
var x = class n {
|
|
120
|
+
static create(e = {}) {
|
|
121
|
+
let i = t(), a = n.mergeConfig(e);
|
|
122
|
+
switch (i.name) {
|
|
123
|
+
case "node": return new y(a);
|
|
124
|
+
case "deno": return new r(a);
|
|
125
|
+
case "bun": return new y(a);
|
|
117
126
|
case "browser":
|
|
118
|
-
case "webworker": return new
|
|
119
|
-
default: return new
|
|
127
|
+
case "webworker": return new r(a);
|
|
128
|
+
default: return new r(a);
|
|
120
129
|
}
|
|
121
130
|
}
|
|
122
131
|
static createChild(e, t) {
|
|
123
132
|
return e.child(t);
|
|
124
133
|
}
|
|
125
|
-
static mergeConfig(
|
|
126
|
-
let
|
|
127
|
-
return o(
|
|
134
|
+
static mergeConfig(t) {
|
|
135
|
+
let n = t.ignoreEnvironment ? {} : e();
|
|
136
|
+
return s(o(t, n));
|
|
128
137
|
}
|
|
129
138
|
};
|
|
130
|
-
function
|
|
131
|
-
return
|
|
139
|
+
function S(e) {
|
|
140
|
+
return x.create(e);
|
|
132
141
|
}
|
|
133
|
-
function
|
|
134
|
-
let e =
|
|
135
|
-
return
|
|
136
|
-
level:
|
|
137
|
-
colorize: e !== "production" &&
|
|
142
|
+
function C() {
|
|
143
|
+
let e = w();
|
|
144
|
+
return S({
|
|
145
|
+
level: T(e),
|
|
146
|
+
colorize: e !== "production" && i(),
|
|
138
147
|
timestamp: !0,
|
|
139
148
|
format: e === "production" ? "json" : "text"
|
|
140
149
|
});
|
|
141
150
|
}
|
|
142
|
-
function
|
|
151
|
+
function w() {
|
|
143
152
|
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";
|
|
144
153
|
}
|
|
145
|
-
function
|
|
146
|
-
switch (
|
|
147
|
-
case "production": return
|
|
154
|
+
function T(e) {
|
|
155
|
+
switch (e) {
|
|
156
|
+
case "production": return d.ERROR;
|
|
148
157
|
case "staging":
|
|
149
|
-
case "test": return
|
|
158
|
+
case "test": return d.WARN;
|
|
150
159
|
case "development":
|
|
151
|
-
case "dev": return
|
|
152
|
-
default: return
|
|
160
|
+
case "dev": return d.DEBUG;
|
|
161
|
+
default: return d.INFO;
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
164
|
+
function E(e) {
|
|
165
|
+
return l(e) ?? d.INFO;
|
|
157
166
|
}
|
|
158
|
-
function
|
|
159
|
-
switch (
|
|
160
|
-
case
|
|
161
|
-
case
|
|
162
|
-
case
|
|
163
|
-
case
|
|
164
|
-
case
|
|
167
|
+
function D(e) {
|
|
168
|
+
switch (e) {
|
|
169
|
+
case d.DEBUG: return "debug";
|
|
170
|
+
case d.INFO: return "info";
|
|
171
|
+
case d.WARN: return "warn";
|
|
172
|
+
case d.ERROR: return "error";
|
|
173
|
+
case d.SILENT: return "silent";
|
|
165
174
|
default: return "info";
|
|
166
175
|
}
|
|
167
176
|
}
|
|
168
177
|
//#endregion
|
|
169
178
|
//#region src/utils/config-file.ts
|
|
170
|
-
var
|
|
179
|
+
var O = [
|
|
171
180
|
{ path: "logan.config.json" },
|
|
172
181
|
{ path: ".loganrc" },
|
|
173
182
|
{
|
|
174
183
|
path: "package.json",
|
|
175
184
|
key: "logan"
|
|
176
185
|
}
|
|
177
|
-
],
|
|
186
|
+
], k = /* @__PURE__ */ new Set([
|
|
178
187
|
"level",
|
|
179
188
|
"format",
|
|
180
189
|
"timestamp",
|
|
@@ -183,38 +192,38 @@ var T = [
|
|
|
183
192
|
"metadata",
|
|
184
193
|
"transports",
|
|
185
194
|
"$schema"
|
|
186
|
-
]),
|
|
195
|
+
]), A = /* @__PURE__ */ new Set([
|
|
187
196
|
"EACCES",
|
|
188
197
|
"EPERM",
|
|
189
198
|
"NotCapable",
|
|
190
199
|
"PermissionDenied"
|
|
191
200
|
]);
|
|
192
|
-
function
|
|
201
|
+
function j(e) {
|
|
193
202
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
194
203
|
}
|
|
195
|
-
function
|
|
204
|
+
function M(e) {
|
|
196
205
|
return e instanceof Error ? e.message : String(e);
|
|
197
206
|
}
|
|
198
|
-
function
|
|
199
|
-
let t = /at position \d+(?: \(line \d+ column \d+\))?/.exec(
|
|
207
|
+
function N(e) {
|
|
208
|
+
let t = /at position \d+(?: \(line \d+ column \d+\))?/.exec(M(e));
|
|
200
209
|
return t ? `not valid JSON (${t[0]})` : "not valid JSON";
|
|
201
210
|
}
|
|
202
|
-
function
|
|
211
|
+
function P(e) {
|
|
203
212
|
return e.startsWith("/") || e.startsWith("\\") || /^[A-Za-z]:/.test(e);
|
|
204
213
|
}
|
|
205
|
-
function
|
|
206
|
-
return t === void 0 || t === "" ||
|
|
214
|
+
function F(e, t) {
|
|
215
|
+
return t === void 0 || t === "" || P(e) ? e : `${t.replace(/[\\/]+$/, "")}/${e}`;
|
|
207
216
|
}
|
|
208
|
-
async function
|
|
209
|
-
if (e === "deno") return (e) =>
|
|
217
|
+
async function I(e, t) {
|
|
218
|
+
if (e === "deno") return (e) => F(e, t);
|
|
210
219
|
let { resolve: n } = await import("node:path");
|
|
211
220
|
return t === void 0 ? (e) => n(e) : (e) => n(t, e);
|
|
212
221
|
}
|
|
213
|
-
function
|
|
222
|
+
function L(e) {
|
|
214
223
|
let t = e.split(/[\\/]/);
|
|
215
224
|
return t[t.length - 1] || e;
|
|
216
225
|
}
|
|
217
|
-
function
|
|
226
|
+
function R(e) {
|
|
218
227
|
if (e === "deno") try {
|
|
219
228
|
return globalThis.Deno?.cwd?.();
|
|
220
229
|
} catch {
|
|
@@ -222,17 +231,17 @@ function F(e) {
|
|
|
222
231
|
}
|
|
223
232
|
return typeof process < "u" && typeof process.cwd == "function" ? process.cwd() : void 0;
|
|
224
233
|
}
|
|
225
|
-
function
|
|
234
|
+
function z(e) {
|
|
226
235
|
let t = e?.code ?? "", n = e?.name ?? "";
|
|
227
|
-
return t === "ENOENT" || n === "NotFound" ? { kind: "absent" } :
|
|
236
|
+
return t === "ENOENT" || n === "NotFound" ? { kind: "absent" } : A.has(t) || A.has(n) ? {
|
|
228
237
|
kind: "denied",
|
|
229
|
-
reason:
|
|
238
|
+
reason: M(e)
|
|
230
239
|
} : {
|
|
231
240
|
kind: "unreadable",
|
|
232
|
-
reason:
|
|
241
|
+
reason: M(e)
|
|
233
242
|
};
|
|
234
243
|
}
|
|
235
|
-
async function
|
|
244
|
+
async function B(e, t) {
|
|
236
245
|
let n = t === "deno" ? () => globalThis.Deno.readTextFile(e) : async () => (await import("node:fs/promises")).readFile(e, "utf-8");
|
|
237
246
|
try {
|
|
238
247
|
return {
|
|
@@ -240,62 +249,62 @@ async function L(e, t) {
|
|
|
240
249
|
content: await n()
|
|
241
250
|
};
|
|
242
251
|
} catch (e) {
|
|
243
|
-
return
|
|
252
|
+
return z(e);
|
|
244
253
|
}
|
|
245
254
|
}
|
|
246
|
-
function
|
|
247
|
-
if (typeof
|
|
248
|
-
if (typeof
|
|
255
|
+
function V(e) {
|
|
256
|
+
if (typeof e == "string") return l(e);
|
|
257
|
+
if (typeof e == "number" && d[e] !== void 0) return e;
|
|
249
258
|
}
|
|
250
|
-
function
|
|
251
|
-
let
|
|
252
|
-
|
|
259
|
+
function H(e, t, r) {
|
|
260
|
+
let i = (e) => {
|
|
261
|
+
n(`[logan-logger] ${r}: ignoring transports[${t}]: ${e}.`);
|
|
253
262
|
};
|
|
254
|
-
if (!
|
|
255
|
-
|
|
263
|
+
if (!j(e)) {
|
|
264
|
+
i(`expected an object, got ${JSON.stringify(e) ?? typeof e}`);
|
|
256
265
|
return;
|
|
257
266
|
}
|
|
258
267
|
if (typeof e.type != "string") {
|
|
259
|
-
|
|
268
|
+
i("\"type\" is required and must be a string");
|
|
260
269
|
return;
|
|
261
270
|
}
|
|
262
|
-
if (e.options !== void 0 && !
|
|
263
|
-
|
|
271
|
+
if (e.options !== void 0 && !j(e.options)) {
|
|
272
|
+
i("\"options\" must be an object");
|
|
264
273
|
return;
|
|
265
274
|
}
|
|
266
|
-
let
|
|
275
|
+
let a = {
|
|
267
276
|
type: e.type,
|
|
268
277
|
options: e.options ?? {}
|
|
269
278
|
};
|
|
270
279
|
if (e.level !== void 0) {
|
|
271
|
-
let
|
|
272
|
-
|
|
280
|
+
let i = V(e.level);
|
|
281
|
+
i === void 0 ? n(`[logan-logger] ${r}: ignoring transports[${t}].level=${JSON.stringify(e.level)}. Accepted: debug, info, warn, error, silent.`) : a.level = i;
|
|
273
282
|
}
|
|
274
|
-
return
|
|
283
|
+
return a;
|
|
275
284
|
}
|
|
276
|
-
function
|
|
277
|
-
let
|
|
278
|
-
|
|
285
|
+
function U(e, t) {
|
|
286
|
+
let r = {}, i = (e, r, i) => {
|
|
287
|
+
n(`[logan-logger] ${t}: ignoring ${e}=${JSON.stringify(r)}. Accepted: ${i}.`);
|
|
279
288
|
};
|
|
280
|
-
for (let
|
|
289
|
+
for (let r of Object.keys(e)) k.has(r) || n(`[logan-logger] ${t}: ignoring unknown field "${r}". Known fields: level, format, timestamp, colorize, ignoreEnvironment, metadata, transports.`);
|
|
281
290
|
if (e.level !== void 0) {
|
|
282
|
-
let t =
|
|
283
|
-
t === void 0 ?
|
|
291
|
+
let t = V(e.level);
|
|
292
|
+
t === void 0 ? i("level", e.level, "debug, info, warn, error, silent") : r.level = t;
|
|
284
293
|
}
|
|
285
|
-
e.format !== void 0 && (e.format === "json" || e.format === "text" || e.format === "custom" ?
|
|
294
|
+
e.format !== void 0 && (e.format === "json" || e.format === "text" || e.format === "custom" ? r.format = e.format : i("format", e.format, "json, text, custom"));
|
|
286
295
|
for (let t of [
|
|
287
296
|
"timestamp",
|
|
288
297
|
"colorize",
|
|
289
298
|
"ignoreEnvironment"
|
|
290
|
-
]) e[t] !== void 0 && (typeof e[t] == "boolean" ?
|
|
291
|
-
if (e.metadata !== void 0 && (
|
|
292
|
-
let
|
|
293
|
-
(
|
|
294
|
-
} else e.transports !== void 0 &&
|
|
295
|
-
return
|
|
299
|
+
]) e[t] !== void 0 && (typeof e[t] == "boolean" ? r[t] = e[t] : i(t, e[t], "true, false"));
|
|
300
|
+
if (e.metadata !== void 0 && (j(e.metadata) ? r.metadata = e.metadata : i("metadata", e.metadata, "an object")), Array.isArray(e.transports)) {
|
|
301
|
+
let n = e.transports.map((e, n) => H(e, n, t)).filter((e) => e !== void 0);
|
|
302
|
+
(n.length > 0 || e.transports.length === 0) && (r.transports = n);
|
|
303
|
+
} else e.transports !== void 0 && i("transports", e.transports, "an array of transport configs");
|
|
304
|
+
return r;
|
|
296
305
|
}
|
|
297
|
-
async function
|
|
298
|
-
let n = await
|
|
306
|
+
async function W(e, t) {
|
|
307
|
+
let n = await B(e.path, t);
|
|
299
308
|
if (n.kind === "absent") return n;
|
|
300
309
|
if (n.kind !== "content") return {
|
|
301
310
|
kind: n.kind,
|
|
@@ -309,12 +318,12 @@ async function V(e, t) {
|
|
|
309
318
|
return {
|
|
310
319
|
kind: "invalid",
|
|
311
320
|
path: e.path,
|
|
312
|
-
reason:
|
|
321
|
+
reason: N(t)
|
|
313
322
|
};
|
|
314
323
|
}
|
|
315
324
|
let i = r;
|
|
316
325
|
if (e.key) {
|
|
317
|
-
if (!
|
|
326
|
+
if (!j(r)) return {
|
|
318
327
|
kind: "invalid",
|
|
319
328
|
path: e.path,
|
|
320
329
|
reason: "expected a JSON object"
|
|
@@ -326,7 +335,7 @@ async function V(e, t) {
|
|
|
326
335
|
};
|
|
327
336
|
i = r[e.key];
|
|
328
337
|
}
|
|
329
|
-
if (!
|
|
338
|
+
if (!j(i)) {
|
|
330
339
|
let t = e.key ? `the "${e.key}" key` : "the file";
|
|
331
340
|
return {
|
|
332
341
|
kind: "invalid",
|
|
@@ -336,42 +345,42 @@ async function V(e, t) {
|
|
|
336
345
|
}
|
|
337
346
|
return {
|
|
338
347
|
kind: "found",
|
|
339
|
-
config:
|
|
348
|
+
config: U(i, e.path)
|
|
340
349
|
};
|
|
341
350
|
}
|
|
342
|
-
function
|
|
343
|
-
let t =
|
|
351
|
+
function G(e) {
|
|
352
|
+
let t = O.find((t) => t.path === L(e));
|
|
344
353
|
return t ? {
|
|
345
354
|
...t,
|
|
346
355
|
path: e
|
|
347
356
|
} : { path: e };
|
|
348
357
|
}
|
|
349
|
-
function
|
|
350
|
-
|
|
358
|
+
function K(e, t) {
|
|
359
|
+
n(`[logan-logger] cannot read config at ${e} — no permission; using defaults instead: ${t}`);
|
|
351
360
|
}
|
|
352
|
-
async function
|
|
353
|
-
let
|
|
354
|
-
if (!
|
|
355
|
-
let
|
|
361
|
+
async function q(e, r = {}) {
|
|
362
|
+
let i = t();
|
|
363
|
+
if (!i.capabilities.fileSystem) return {};
|
|
364
|
+
let a = r.cwd || R(i.name), o = await I(i.name, a);
|
|
356
365
|
if (e !== void 0) {
|
|
357
|
-
let t =
|
|
358
|
-
if (
|
|
359
|
-
if (
|
|
360
|
-
if (
|
|
361
|
-
if (
|
|
362
|
-
throw
|
|
366
|
+
let t = o(e), n = await W(G(t), i.name);
|
|
367
|
+
if (n.kind === "found") return n.config;
|
|
368
|
+
if (n.kind === "absent") throw Error(`[logan-logger] config file not found: ${t}`);
|
|
369
|
+
if (n.kind === "keyless") throw Error(`[logan-logger] no "${n.key}" key in ${n.path}`);
|
|
370
|
+
if (n.kind === "denied") return K(n.path, n.reason), {};
|
|
371
|
+
throw n.kind === "unreadable" ? Error(`[logan-logger] config at ${n.path} is not a readable file: ${n.reason}`) : Error(`[logan-logger] config at ${n.path} is invalid: ${n.reason}`);
|
|
363
372
|
}
|
|
364
|
-
for (let e of
|
|
365
|
-
let t = await
|
|
373
|
+
for (let e of O) {
|
|
374
|
+
let t = await W({
|
|
366
375
|
...e,
|
|
367
|
-
path:
|
|
368
|
-
},
|
|
376
|
+
path: o(e.path)
|
|
377
|
+
}, i.name);
|
|
369
378
|
if (t.kind === "found") return t.config;
|
|
370
|
-
if (t.kind === "invalid") return
|
|
371
|
-
if (t.kind === "denied") return
|
|
372
|
-
t.kind === "unreadable" &&
|
|
379
|
+
if (t.kind === "invalid") return n(`[logan-logger] config at ${t.path} is invalid: ${t.reason}`), {};
|
|
380
|
+
if (t.kind === "denied") return K(t.path, t.reason), {};
|
|
381
|
+
t.kind === "unreadable" && n(`[logan-logger] skipping ${t.path}: not a readable file (${t.reason})`);
|
|
373
382
|
}
|
|
374
383
|
return {};
|
|
375
384
|
}
|
|
376
385
|
//#endregion
|
|
377
|
-
export {
|
|
386
|
+
export { D as a, b as c, m as d, p as f, C as i, h as l, x as n, E as o, S as r, y as s, q as t, _ as u };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./formatting-pzIQGL_7.cjs");var t=new Map;function n(e,n){t.set(e,n)}function r(e){return t.get(e)}var i=class{constructor(e={}){this.type=`console`,this.level=e.level,this.format=e.format===`json`?`json`:`text`,this.formatOptions={timestamp:e.timestamp!==!1,colorize:e.colorize===!0}}write(t){let n=e.n(t,this.format,this.formatOptions);switch(t.level){case e.y.DEBUG:console.debug(n);break;case e.y.WARN:console.warn(n);break;case e.y.ERROR:console.error(n);break;default:console.info(n)}}};n(`console`,(e,t)=>{let n=e.options??{};return new i({format:n.format??t.format,timestamp:n.timestamp??t.timestamp,colorize:n.colorize??t.colorize,level:e.level})}),n(`custom`,(e,t)=>{let n=e.options?.transport,r=typeof n==`function`?n(t):n;if(!r||typeof r.write!=`function`)throw Error(`custom transport requires options.transport to be an object with a write(entry) method, or a function returning one; ${typeof n==`function`?`the function it was given returned no write(entry) method`:`it was given no object with a write(entry) method`}`);return e.level===void 0?r:{type:r.type??`custom`,level:e.level,write:e=>r.write(e),close:r.close?()=>r.close?.():void 0}});function a(e){return{...e,options:{...e.options,colorize:!1}}}function o(t){let n=e.s(),o={format:t.format??`text`,timestamp:t.timestamp??!0,colorize:n?!1:t.colorize??!1};if(t.transports===void 0)return[new i({format:o.format,timestamp:o.timestamp,colorize:o.colorize})];let c=[];for(let e of t.transports){let t=r(e.type);if(!t){console.warn(`[logan-logger] ${s(e.type)}`);continue}try{c.push(t(n?a(e):e,o))}catch(t){console.warn(`[logan-logger] transport '${e.type}' failed to initialize:`,t)}}return c}function s(e){return e===`file`?`the 'file' transport is not registered; import from 'logan-logger/node' (or 'logan-logger/bun') rather than the main entry point to use file logging`:e===`http`?`the 'http' transport is not built in; supply one with { type: 'custom', options: { transport } }`:`unknown transport type '${e}'; skipping`}var c=class t extends e.v{constructor(e={},t){super(e),this.transports=t??o(e)}getTransports(){return this.transports}close(){for(let e of this.transports)e.close?.()}writeLog(e){for(let t of this.transports)if(!(t.level!==void 0&&e.level<t.level))try{t.write(e)}catch(e){console.warn(`[logan-logger] transport '${t.type}' failed to write:`,e)}}createChild(){return new t(this.config,this.transports)}};function l(e){return{write:t=>{e.info(t.trim())}}}var u=class t{static create(n={}){let r=e.b(),i=t.mergeConfig(n);switch(r.name){case`node`:return new c(i);case`deno`:return new e.f(i);case`bun`:return new c(i);case`browser`:case`webworker`:return new e.f(i);default:return new e.f(i)}}static createChild(e,t){return e.child(t)}static mergeConfig(t){let n=t.ignoreEnvironment?{}:e.a();return e.r(e.o(t,n))}};function d(e){return u.create(e)}function f(){let t=p();return d({level:m(t),colorize:t!==`production`&&e.l(),timestamp:!0,format:t===`production`?`json`:`text`})}function p(){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 m(t){switch(t){case`production`:return e.y.ERROR;case`staging`:case`test`:return e.y.WARN;case`development`:case`dev`:return e.y.DEBUG;default:return e.y.INFO}}function h(t){return e.u(t)??e.y.INFO}function g(t){switch(t){case e.y.DEBUG:return`debug`;case e.y.INFO:return`info`;case e.y.WARN:return`warn`;case e.y.ERROR:return`error`;case e.y.SILENT:return`silent`;default:return`info`}}var _=[{path:`logan.config.json`},{path:`.loganrc`},{path:`package.json`,key:`logan`}],v=new Set([`level`,`format`,`timestamp`,`colorize`,`ignoreEnvironment`,`metadata`,`transports`,`$schema`]),y=new Set([`EACCES`,`EPERM`,`NotCapable`,`PermissionDenied`]);function b(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function x(e){return e instanceof Error?e.message:String(e)}function S(e){let t=/at position \d+(?: \(line \d+ column \d+\))?/.exec(x(e));return t?`not valid JSON (${t[0]})`:`not valid JSON`}function C(e){return e.startsWith(`/`)||e.startsWith(`\\`)||/^[A-Za-z]:/.test(e)}function w(e,t){return t===void 0||t===``||C(e)?e:`${t.replace(/[\\/]+$/,``)}/${e}`}async function T(e,t){if(e===`deno`)return e=>w(e,t);let{resolve:n}=await import(`node:path`);return t===void 0?e=>n(e):e=>n(t,e)}function E(e){let t=e.split(/[\\/]/);return t[t.length-1]||e}function D(e){if(e===`deno`)try{return globalThis.Deno?.cwd?.()}catch{return}return typeof process<`u`&&typeof process.cwd==`function`?process.cwd():void 0}function O(e){let t=e?.code??``,n=e?.name??``;return t===`ENOENT`||n===`NotFound`?{kind:`absent`}:y.has(t)||y.has(n)?{kind:`denied`,reason:x(e)}:{kind:`unreadable`,reason:x(e)}}async function k(e,t){let n=t===`deno`?()=>globalThis.Deno.readTextFile(e):async()=>(await import(`node:fs/promises`)).readFile(e,`utf-8`);try{return{kind:`content`,content:await n()}}catch(e){return O(e)}}function A(t){if(typeof t==`string`)return e.u(t);if(typeof t==`number`&&e.y[t]!==void 0)return t}function j(t,n,r){let i=t=>{e.d(`[logan-logger] ${r}: ignoring transports[${n}]: ${t}.`)};if(!b(t)){i(`expected an object, got ${JSON.stringify(t)??typeof t}`);return}if(typeof t.type!=`string`){i(`"type" is required and must be a string`);return}if(t.options!==void 0&&!b(t.options)){i(`"options" must be an object`);return}let a={type:t.type,options:t.options??{}};if(t.level!==void 0){let i=A(t.level);i===void 0?e.d(`[logan-logger] ${r}: ignoring transports[${n}].level=${JSON.stringify(t.level)}. Accepted: debug, info, warn, error, silent.`):a.level=i}return a}function M(t,n){let r={},i=(t,r,i)=>{e.d(`[logan-logger] ${n}: ignoring ${t}=${JSON.stringify(r)}. Accepted: ${i}.`)};for(let r of Object.keys(t))v.has(r)||e.d(`[logan-logger] ${n}: ignoring unknown field "${r}". Known fields: level, format, timestamp, colorize, ignoreEnvironment, metadata, transports.`);if(t.level!==void 0){let e=A(t.level);e===void 0?i(`level`,t.level,`debug, info, warn, error, silent`):r.level=e}t.format!==void 0&&(t.format===`json`||t.format===`text`||t.format===`custom`?r.format=t.format:i(`format`,t.format,`json, text, custom`));for(let e of[`timestamp`,`colorize`,`ignoreEnvironment`])t[e]!==void 0&&(typeof t[e]==`boolean`?r[e]=t[e]:i(e,t[e],`true, false`));if(t.metadata!==void 0&&(b(t.metadata)?r.metadata=t.metadata:i(`metadata`,t.metadata,`an object`)),Array.isArray(t.transports)){let e=t.transports.map((e,t)=>j(e,t,n)).filter(e=>e!==void 0);(e.length>0||t.transports.length===0)&&(r.transports=e)}else t.transports!==void 0&&i(`transports`,t.transports,`an array of transport configs`);return r}async function N(e,t){let n=await k(e.path,t);if(n.kind===`absent`)return n;if(n.kind!==`content`)return{kind:n.kind,path:e.path,reason:n.reason};let r;try{r=JSON.parse(n.content)}catch(t){return{kind:`invalid`,path:e.path,reason:S(t)}}let i=r;if(e.key){if(!b(r))return{kind:`invalid`,path:e.path,reason:`expected a JSON object`};if(!Object.hasOwn(r,e.key))return{kind:`keyless`,path:e.path,key:e.key};i=r[e.key]}if(!b(i)){let t=e.key?`the "${e.key}" key`:`the file`;return{kind:`invalid`,path:e.path,reason:`expected ${t} to be an object`}}return{kind:`found`,config:M(i,e.path)}}function P(e){let t=_.find(t=>t.path===E(e));return t?{...t,path:e}:{path:e}}function F(t,n){e.d(`[logan-logger] cannot read config at ${t} — no permission; using defaults instead: ${n}`)}async function I(t,n={}){let r=e.b();if(!r.capabilities.fileSystem)return{};let i=n.cwd||D(r.name),a=await T(r.name,i);if(t!==void 0){let e=a(t),n=await N(P(e),r.name);if(n.kind===`found`)return n.config;if(n.kind===`absent`)throw Error(`[logan-logger] config file not found: ${e}`);if(n.kind===`keyless`)throw Error(`[logan-logger] no "${n.key}" key in ${n.path}`);if(n.kind===`denied`)return F(n.path,n.reason),{};throw n.kind===`unreadable`?Error(`[logan-logger] config at ${n.path} is not a readable file: ${n.reason}`):Error(`[logan-logger] config at ${n.path} is invalid: ${n.reason}`)}for(let t of _){let n=await N({...t,path:a(t.path)},r.name);if(n.kind===`found`)return n.config;if(n.kind===`invalid`)return e.d(`[logan-logger] config at ${n.path} is invalid: ${n.reason}`),{};if(n.kind===`denied`)return F(n.path,n.reason),{};n.kind===`unreadable`&&e.d(`[logan-logger] skipping ${n.path}: not a readable file (${n.reason})`)}return{}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return o}});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as t } from "./config-file-
|
|
1
|
+
import { n as e } from "./formatting-DTrgGC8g.mjs";
|
|
2
|
+
import { f as t } from "./config-file-B2bCuTsh.mjs";
|
|
3
3
|
import { closeSync as n, existsSync as r, fstatSync as i, mkdirSync as a, openSync as o, renameSync as s, unlinkSync as c, writeSync as l } from "node:fs";
|
|
4
4
|
import { dirname as u, resolve as d } from "node:path";
|
|
5
5
|
//#region src/runtime/file-transport.ts
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./formatting-pzIQGL_7.cjs"),t=require("./config-file-Bi7lhPHV.cjs");let n=require("node:fs"),r=require("node:path");var i=5242880,a=5,o=class{constructor(e){if(this.type=`file`,this.size=0,this.warned=!1,!e?.filename)throw Error(`file transport requires options.filename`);this.path=(0,r.resolve)(e.filename),this.maxsize=e.maxsize??i,this.maxFiles=e.maxFiles??a,this.format=e.format===`text`?`text`:`json`,this.timestamp=e.timestamp!==!1,this.level=e.level}get filename(){return this.path}write(t){let r=`${e.n(t,this.format,{timestamp:this.timestamp,colorize:!1})}\n`;try{this.open(),this.maxsize>0&&this.size>=this.maxsize&&(this.rotate(),this.open()),this.size+=(0,n.writeSync)(this.fd,r)}catch(e){this.warnOnce(e)}}close(){if(this.fd!==void 0)try{(0,n.closeSync)(this.fd)}finally{this.fd=void 0}}open(){if(this.fd!==void 0)return;let e=(0,r.dirname)(this.path);try{(0,n.mkdirSync)(e,{recursive:!0})}catch(t){throw s(`create log directory`,e,t)}try{this.fd=(0,n.openSync)(this.path,`a`)}catch(e){throw s(`open log file`,this.path,e)}this.size=(0,n.fstatSync)(this.fd).size}rotate(){if(this.close(),this.maxFiles<=0){(0,n.existsSync)(this.path)&&(0,n.unlinkSync)(this.path),this.size=0;return}let e=`${this.path}.${this.maxFiles}`;(0,n.existsSync)(e)&&(0,n.unlinkSync)(e);for(let e=this.maxFiles-1;e>=1;e--){let t=`${this.path}.${e}`;(0,n.existsSync)(t)&&(0,n.renameSync)(t,`${this.path}.${e+1}`)}(0,n.existsSync)(this.path)&&(0,n.renameSync)(this.path,`${this.path}.1`),this.size=0}warnOnce(e){this.close(),!this.warned&&(this.warned=!0,console.warn(`[logan-logger] file transport for '${this.path}' failed and will keep retrying quietly:`,e instanceof Error?e.message:e))}};function s(e,t,n){let r=n,i=r?.code?` [${r.code}]`:``,a=r?.syscall?` during ${r.syscall}`:``,o=Error(`could not ${e} '${t}'${i}${a}: ${r?.message??n}`);return o.cause=n,o}t.f(`file`,(e,t)=>{let n=e.options??{};return new o({filename:n.filename,maxsize:n.maxsize,maxFiles:n.maxFiles,format:n.format,timestamp:n.timestamp??t.timestamp,level:e.level})}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|