logan-logger 2.0.1 → 2.1.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/dist/node.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { c as e, d as t, l as n, n as r, o as i, r as a, s as o } from "./chunks/factory-CXO2aNcc.mjs";
2
- import { t as s } from "./chunks/file-transport-DRyxQq8t.mjs";
3
- export { e as ConsoleTransport, s as FileTransport, i as NodeLogger, r as createLogger, a as createLoggerForEnvironment, o as createMorganStream, n as createTransports, t as registerTransport };
1
+ import { c as e, f as t, i as n, l as r, r as i, s as a, t as o, u as s } from "./chunks/config-file-CvMv3rgc.mjs";
2
+ import { t as c } from "./chunks/file-transport-yIPiX8TP.mjs";
3
+ export { r as ConsoleTransport, c as FileTransport, a as NodeLogger, i as createLogger, n as createLoggerForEnvironment, e as createMorganStream, s as createTransports, o as loadConfigFromFile, t as registerTransport };
@@ -1,2 +1,48 @@
1
1
  import { LoggerConfig } from '../core/types.cjs';
2
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
2
+ /** Options accepted by {@link loadConfigFromFile}. */
3
+ export interface LoadConfigFileOptions {
4
+ /**
5
+ * Directory the search runs in, and the base a relative `configPath` resolves
6
+ * against. Defaults to the process working directory, which an empty string
7
+ * also falls back to.
8
+ *
9
+ * The working directory is not the package root in a monorepo, under
10
+ * pm2/systemd, or behind `pnpm -C`, and a search rooted there silently finds
11
+ * nothing. Pass the directory you actually mean.
12
+ */
13
+ cwd?: string;
14
+ }
15
+ /**
16
+ * Load logger configuration from a file.
17
+ *
18
+ * Without an explicit path, searches `logan.config.json`, then `.loganrc`, then
19
+ * a `logan` key in `package.json`, and returns the first one present. All are
20
+ * parsed as JSON.
21
+ *
22
+ * A file that is present but malformed **warns naming the path** and stops the
23
+ * search rather than silently falling through to defaults. A path that exists
24
+ * but is not a readable file — a directory named `.loganrc`, say — warns and
25
+ * the search continues, because that is not a config file at all. A runtime
26
+ * that refuses permission warns once and yields defaults without throwing;
27
+ * a sandbox is an environment problem, not a reason to fail startup.
28
+ *
29
+ * Every warning is emitted once per distinct message, so calling this per
30
+ * request does not repeat it forever.
31
+ *
32
+ * This is async, and `createLogger()` is not, so file configuration is not part
33
+ * of the automatic precedence chain. Apply it explicitly:
34
+ *
35
+ * ```typescript
36
+ * const logger = createLogger(await loadConfigFromFile());
37
+ * ```
38
+ *
39
+ * @param configPath - Load exactly this file, resolved against `options.cwd`.
40
+ * Unlike the search, a missing file here is a caller error and throws. It must
41
+ * not be built from untrusted input: it names a file to read, and a config file
42
+ * can name an absolute path for the file transport to write.
43
+ * @param options - Search options; see {@link LoadConfigFileOptions}
44
+ * @returns The configuration found, or `{}` when no candidate exists
45
+ * @throws When `configPath` is given and that file does not exist, carries no
46
+ * `logan` key (for a `package.json`), is not a readable file, or is malformed
47
+ */
48
+ export declare function loadConfigFromFile(configPath?: string, options?: LoadConfigFileOptions): Promise<Partial<LoggerConfig>>;
@@ -1,2 +1,48 @@
1
1
  import { LoggerConfig } from '../core/types.mjs';
2
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
2
+ /** Options accepted by {@link loadConfigFromFile}. */
3
+ export interface LoadConfigFileOptions {
4
+ /**
5
+ * Directory the search runs in, and the base a relative `configPath` resolves
6
+ * against. Defaults to the process working directory, which an empty string
7
+ * also falls back to.
8
+ *
9
+ * The working directory is not the package root in a monorepo, under
10
+ * pm2/systemd, or behind `pnpm -C`, and a search rooted there silently finds
11
+ * nothing. Pass the directory you actually mean.
12
+ */
13
+ cwd?: string;
14
+ }
15
+ /**
16
+ * Load logger configuration from a file.
17
+ *
18
+ * Without an explicit path, searches `logan.config.json`, then `.loganrc`, then
19
+ * a `logan` key in `package.json`, and returns the first one present. All are
20
+ * parsed as JSON.
21
+ *
22
+ * A file that is present but malformed **warns naming the path** and stops the
23
+ * search rather than silently falling through to defaults. A path that exists
24
+ * but is not a readable file — a directory named `.loganrc`, say — warns and
25
+ * the search continues, because that is not a config file at all. A runtime
26
+ * that refuses permission warns once and yields defaults without throwing;
27
+ * a sandbox is an environment problem, not a reason to fail startup.
28
+ *
29
+ * Every warning is emitted once per distinct message, so calling this per
30
+ * request does not repeat it forever.
31
+ *
32
+ * This is async, and `createLogger()` is not, so file configuration is not part
33
+ * of the automatic precedence chain. Apply it explicitly:
34
+ *
35
+ * ```typescript
36
+ * const logger = createLogger(await loadConfigFromFile());
37
+ * ```
38
+ *
39
+ * @param configPath - Load exactly this file, resolved against `options.cwd`.
40
+ * Unlike the search, a missing file here is a caller error and throws. It must
41
+ * not be built from untrusted input: it names a file to read, and a config file
42
+ * can name an absolute path for the file transport to write.
43
+ * @param options - Search options; see {@link LoadConfigFileOptions}
44
+ * @returns The configuration found, or `{}` when no candidate exists
45
+ * @throws When `configPath` is given and that file does not exist, carries no
46
+ * `logan` key (for a `package.json`), is not a readable file, or is malformed
47
+ */
48
+ export declare function loadConfigFromFile(configPath?: string, options?: LoadConfigFileOptions): Promise<Partial<LoggerConfig>>;
@@ -1,2 +1,48 @@
1
1
  import { LoggerConfig } from '../core/types';
2
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
2
+ /** Options accepted by {@link loadConfigFromFile}. */
3
+ export interface LoadConfigFileOptions {
4
+ /**
5
+ * Directory the search runs in, and the base a relative `configPath` resolves
6
+ * against. Defaults to the process working directory, which an empty string
7
+ * also falls back to.
8
+ *
9
+ * The working directory is not the package root in a monorepo, under
10
+ * pm2/systemd, or behind `pnpm -C`, and a search rooted there silently finds
11
+ * nothing. Pass the directory you actually mean.
12
+ */
13
+ cwd?: string;
14
+ }
15
+ /**
16
+ * Load logger configuration from a file.
17
+ *
18
+ * Without an explicit path, searches `logan.config.json`, then `.loganrc`, then
19
+ * a `logan` key in `package.json`, and returns the first one present. All are
20
+ * parsed as JSON.
21
+ *
22
+ * A file that is present but malformed **warns naming the path** and stops the
23
+ * search rather than silently falling through to defaults. A path that exists
24
+ * but is not a readable file — a directory named `.loganrc`, say — warns and
25
+ * the search continues, because that is not a config file at all. A runtime
26
+ * that refuses permission warns once and yields defaults without throwing;
27
+ * a sandbox is an environment problem, not a reason to fail startup.
28
+ *
29
+ * Every warning is emitted once per distinct message, so calling this per
30
+ * request does not repeat it forever.
31
+ *
32
+ * This is async, and `createLogger()` is not, so file configuration is not part
33
+ * of the automatic precedence chain. Apply it explicitly:
34
+ *
35
+ * ```typescript
36
+ * const logger = createLogger(await loadConfigFromFile());
37
+ * ```
38
+ *
39
+ * @param configPath - Load exactly this file, resolved against `options.cwd`.
40
+ * Unlike the search, a missing file here is a caller error and throws. It must
41
+ * not be built from untrusted input: it names a file to read, and a config file
42
+ * can name an absolute path for the file transport to write.
43
+ * @param options - Search options; see {@link LoadConfigFileOptions}
44
+ * @returns The configuration found, or `{}` when no candidate exists
45
+ * @throws When `configPath` is given and that file does not exist, carries no
46
+ * `logan` key (for a `package.json`), is not a readable file, or is malformed
47
+ */
48
+ export declare function loadConfigFromFile(configPath?: string, options?: LoadConfigFileOptions): Promise<Partial<LoggerConfig>>;
@@ -12,7 +12,8 @@ import { LoggerConfig, LogLevel } from '../core/types.cjs';
12
12
  export declare function shouldColorize(): boolean;
13
13
  export declare function getDefaultConfig(): LoggerConfig;
14
14
  /**
15
- * Reset the warn-once state. Exposed for tests; not part of the public contract.
15
+ * Reset the warn-once state, config file warnings included. Exposed for tests;
16
+ * not part of the public contract.
16
17
  */
17
18
  export declare function resetEnvironmentWarnings(): void;
18
19
  /**
@@ -12,7 +12,8 @@ import { LoggerConfig, LogLevel } from '../core/types.mjs';
12
12
  export declare function shouldColorize(): boolean;
13
13
  export declare function getDefaultConfig(): LoggerConfig;
14
14
  /**
15
- * Reset the warn-once state. Exposed for tests; not part of the public contract.
15
+ * Reset the warn-once state, config file warnings included. Exposed for tests;
16
+ * not part of the public contract.
16
17
  */
17
18
  export declare function resetEnvironmentWarnings(): void;
18
19
  /**
@@ -12,7 +12,8 @@ import { LoggerConfig, LogLevel } from '../core/types';
12
12
  export declare function shouldColorize(): boolean;
13
13
  export declare function getDefaultConfig(): LoggerConfig;
14
14
  /**
15
- * Reset the warn-once state. Exposed for tests; not part of the public contract.
15
+ * Reset the warn-once state, config file warnings included. Exposed for tests;
16
+ * not part of the public contract.
16
17
  */
17
18
  export declare function resetEnvironmentWarnings(): void;
18
19
  /**
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Emit a diagnostic at most once per distinct message.
3
+ * @param message - The warning, used verbatim as the dedupe key
4
+ */
5
+ export declare function warnOnce(message: string): void;
6
+ /** Forget every message emitted so far. Exposed for tests. */
7
+ export declare function resetWarnings(): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Emit a diagnostic at most once per distinct message.
3
+ * @param message - The warning, used verbatim as the dedupe key
4
+ */
5
+ export declare function warnOnce(message: string): void;
6
+ /** Forget every message emitted so far. Exposed for tests. */
7
+ export declare function resetWarnings(): void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Emit a diagnostic at most once per distinct message.
3
+ * @param message - The warning, used verbatim as the dedupe key
4
+ */
5
+ export declare function warnOnce(message: string): void;
6
+ /** Forget every message emitted so far. Exposed for tests. */
7
+ export declare function resetWarnings(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logan-logger",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "packageManager": "pnpm@11.9.0",
5
5
  "description": "Universal TypeScript logging library for all JavaScript runtimes",
6
6
  "main": "dist/index.cjs",
@@ -1,56 +0,0 @@
1
- import { _ as e } from "./config-Db6PTLH2.mjs";
2
- //#region src/utils/config-file.ts
3
- async function t(t) {
4
- let a = e();
5
- if (!a.capabilities.fileSystem) return {};
6
- let o = t ? [t] : [
7
- "logan.config.json",
8
- "logan.config.js",
9
- ".loganrc",
10
- "package.json"
11
- ];
12
- for (let e of o) try {
13
- if (a.name === "node") return await n(e);
14
- if (a.name === "deno") return await r(e);
15
- if (a.name === "bun") return await i(e);
16
- } catch {}
17
- return {};
18
- }
19
- async function n(e) {
20
- try {
21
- let t = await import("node:fs/promises"), n = await import("node:path");
22
- if (e.endsWith(".json")) {
23
- let n = await t.readFile(e, "utf-8"), r = JSON.parse(n);
24
- return e === "package.json" ? r.logan || {} : r;
25
- }
26
- if (e.endsWith(".js")) {
27
- let t = await import(
28
- /* @vite-ignore */
29
- `file://${n.resolve(e)}`
30
- );
31
- return t.default || t;
32
- }
33
- } catch {}
34
- return {};
35
- }
36
- async function r(e) {
37
- try {
38
- if (e.endsWith(".json")) {
39
- let t = await globalThis.Deno.readTextFile(e), n = JSON.parse(t);
40
- return e === "package.json" ? n.logan || {} : n;
41
- }
42
- if (e.endsWith(".js")) {
43
- let t = await import(
44
- /* @vite-ignore */
45
- `./${e}`
46
- );
47
- return t.default || t;
48
- }
49
- } catch {}
50
- return {};
51
- }
52
- async function i(e) {
53
- return n(e);
54
- }
55
- //#endregion
56
- export { t };
@@ -1 +0,0 @@
1
- const e=require("./config-PPDFSral.cjs");async function t(t){let a=e._();if(!a.capabilities.fileSystem)return{};let o=t?[t]:[`logan.config.json`,`logan.config.js`,`.loganrc`,`package.json`];for(let e of o)try{if(a.name===`node`)return await n(e);if(a.name===`deno`)return await r(e);if(a.name===`bun`)return await i(e)}catch{}return{}}async function n(e){try{let t=await import(`node:fs/promises`),n=await import(`node:path`);if(e.endsWith(`.json`)){let n=await t.readFile(e,`utf-8`),r=JSON.parse(n);return e===`package.json`?r.logan||{}:r}if(e.endsWith(`.js`)){let t=await import(`file://${n.resolve(e)}`);return t.default||t}}catch{}return{}}async function r(e){try{if(e.endsWith(`.json`)){let t=await globalThis.Deno.readTextFile(e),n=JSON.parse(t);return e===`package.json`?n.logan||{}:n}if(e.endsWith(`.js`)){let t=await import(`./${e}`);return t.default||t}}catch{}return{}}async function i(e){return n(e)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
@@ -1 +0,0 @@
1
- const e=require("./config-PPDFSral.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.c(t,this.format,this.formatOptions);switch(t.level){case e.g.DEBUG:console.debug(n);break;case e.g.WARN:console.warn(n);break;case e.g.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=>{let t=e.options?.transport;if(!t||typeof t.write!=`function`)throw Error(`custom transport requires options.transport to be an object with a write(entry) method`);return e.level===void 0?t:{type:t.type??`custom`,level:e.level,write:e=>t.write(e),close:t.close?()=>t.close?.():void 0}});function a(e){let t={format:e.format??`text`,timestamp:e.timestamp??!0,colorize:e.colorize??!1};if(e.transports===void 0)return[new i({format:t.format,timestamp:t.timestamp,colorize:t.colorize})];let n=[];for(let i of e.transports){let e=r(i.type);if(!e){console.warn(`[logan-logger] ${o(i.type)}`);continue}try{n.push(e(i,t))}catch(e){console.warn(`[logan-logger] transport '${i.type}' failed to initialize:`,e)}}return n}function o(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 s=class t extends e.h{constructor(e={},t){super(e),this.transports=t??a(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 c(e){return{write:t=>{e.info(t.trim())}}}var l=class t{static create(n={}){let r=e._(),i=t.mergeConfig(n);switch(r.name){case`node`:return new s(i);case`deno`:return new e.l(i);case`bun`:return new s(i);case`browser`:case`webworker`:return new e.l(i);default:return new e.l(i)}}static createChild(e,t){return e.child(t)}static mergeConfig(t){let n=t.ignoreEnvironment?{}:e.n();return e.r(t,n)}};function u(e){return l.create(e)}function d(){let t=f();return u({level:p(t),colorize:t!==`production`&&e.a(),timestamp:!0,format:t===`production`?`json`:`text`})}function f(){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 p(t){switch(t){case`production`:return e.g.ERROR;case`staging`:case`test`:return e.g.WARN;case`development`:case`dev`:return e.g.DEBUG;default:return e.g.INFO}}function m(t){return e.o(t)??e.g.INFO}function h(t){switch(t){case e.g.DEBUG:return`debug`;case e.g.INFO:return`info`;case e.g.WARN:return`warn`;case e.g.ERROR:return`error`;case e.g.SILENT:return`silent`;default:return`info`}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return s}}),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 l}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return r}});
@@ -1,169 +0,0 @@
1
- import { _ as e, a as t, c as n, g as r, h as i, l as a, n as o, o as s, r as c } from "./config-Db6PTLH2.mjs";
2
- //#region src/core/transport.ts
3
- var l = /* @__PURE__ */ new Map();
4
- function u(e, t) {
5
- l.set(e, t);
6
- }
7
- function d(e) {
8
- return l.get(e);
9
- }
10
- var f = class {
11
- constructor(e = {}) {
12
- this.type = "console", this.level = e.level, this.format = e.format === "json" ? "json" : "text", this.formatOptions = {
13
- timestamp: e.timestamp !== !1,
14
- colorize: e.colorize === !0
15
- };
16
- }
17
- write(e) {
18
- let t = n(e, this.format, this.formatOptions);
19
- switch (e.level) {
20
- case r.DEBUG:
21
- console.debug(t);
22
- break;
23
- case r.WARN:
24
- console.warn(t);
25
- break;
26
- case r.ERROR:
27
- console.error(t);
28
- break;
29
- default: console.info(t);
30
- }
31
- }
32
- };
33
- u("console", (e, t) => {
34
- let n = e.options ?? {};
35
- return new f({
36
- format: n.format ?? t.format,
37
- timestamp: n.timestamp ?? t.timestamp,
38
- colorize: n.colorize ?? t.colorize,
39
- level: e.level
40
- });
41
- }), u("custom", (e) => {
42
- let t = e.options?.transport;
43
- if (!t || typeof t.write != "function") throw Error("custom transport requires options.transport to be an object with a write(entry) method");
44
- return e.level === void 0 ? t : {
45
- type: t.type ?? "custom",
46
- level: e.level,
47
- write: (e) => t.write(e),
48
- close: t.close ? () => t.close?.() : void 0
49
- };
50
- });
51
- function p(e) {
52
- let t = {
53
- format: e.format ?? "text",
54
- timestamp: e.timestamp ?? !0,
55
- colorize: e.colorize ?? !1
56
- };
57
- if (e.transports === void 0) return [new f({
58
- format: t.format,
59
- timestamp: t.timestamp,
60
- colorize: t.colorize
61
- })];
62
- let n = [];
63
- for (let r of e.transports) {
64
- let e = d(r.type);
65
- if (!e) {
66
- console.warn(`[logan-logger] ${m(r.type)}`);
67
- continue;
68
- }
69
- try {
70
- n.push(e(r, t));
71
- } catch (e) {
72
- console.warn(`[logan-logger] transport '${r.type}' failed to initialize:`, e);
73
- }
74
- }
75
- return n;
76
- }
77
- function m(e) {
78
- 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
- }
80
- //#endregion
81
- //#region src/runtime/node.ts
82
- var h = class e extends i {
83
- constructor(e = {}, t) {
84
- super(e), this.transports = t ?? p(e);
85
- }
86
- getTransports() {
87
- return this.transports;
88
- }
89
- close() {
90
- for (let e of this.transports) e.close?.();
91
- }
92
- writeLog(e) {
93
- for (let t of this.transports) if (!(t.level !== void 0 && e.level < t.level)) try {
94
- t.write(e);
95
- } catch (e) {
96
- console.warn(`[logan-logger] transport '${t.type}' failed to write:`, e);
97
- }
98
- }
99
- createChild() {
100
- return new e(this.config, this.transports);
101
- }
102
- };
103
- function g(e) {
104
- return { write: (t) => {
105
- e.info(t.trim());
106
- } };
107
- }
108
- //#endregion
109
- //#region src/core/factory.ts
110
- var _ = class t {
111
- static create(n = {}) {
112
- let r = e(), i = t.mergeConfig(n);
113
- switch (r.name) {
114
- case "node": return new h(i);
115
- case "deno": return new a(i);
116
- case "bun": return new h(i);
117
- case "browser":
118
- case "webworker": return new a(i);
119
- default: return new a(i);
120
- }
121
- }
122
- static createChild(e, t) {
123
- return e.child(t);
124
- }
125
- static mergeConfig(e) {
126
- let t = e.ignoreEnvironment ? {} : o();
127
- return c(e, t);
128
- }
129
- };
130
- function v(e) {
131
- return _.create(e);
132
- }
133
- function y() {
134
- let e = b();
135
- return v({
136
- level: x(e),
137
- colorize: e !== "production" && t(),
138
- timestamp: !0,
139
- format: e === "production" ? "json" : "text"
140
- });
141
- }
142
- function b() {
143
- 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
- }
145
- function x(e) {
146
- switch (e) {
147
- case "production": return r.ERROR;
148
- case "staging":
149
- case "test": return r.WARN;
150
- case "development":
151
- case "dev": return r.DEBUG;
152
- default: return r.INFO;
153
- }
154
- }
155
- function S(e) {
156
- return s(e) ?? r.INFO;
157
- }
158
- function C(e) {
159
- switch (e) {
160
- case r.DEBUG: return "debug";
161
- case r.INFO: return "info";
162
- case r.WARN: return "warn";
163
- case r.ERROR: return "error";
164
- case r.SILENT: return "silent";
165
- default: return "info";
166
- }
167
- }
168
- //#endregion
169
- export { S as a, f as c, u as d, C as i, p as l, v as n, h as o, y as r, g as s, _ as t, d as u };
@@ -1 +0,0 @@
1
- const e=require("./config-PPDFSral.cjs"),t=require("./factory-BPYE1-Nw.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.c(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.d(`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}});