logan-logger 1.1.21 → 2.0.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.
Files changed (66) hide show
  1. package/README.md +83 -7
  2. package/dist/browser.cjs +1 -1
  3. package/dist/browser.mjs +20 -42
  4. package/dist/bun.cjs +1 -1
  5. package/dist/bun.d.cts +4 -1
  6. package/dist/bun.d.mts +4 -1
  7. package/dist/bun.d.ts +4 -1
  8. package/dist/bun.mjs +5 -4
  9. package/dist/chunks/{browser-D5QY2oJb.mjs → config-Db6PTLH2.mjs} +158 -23
  10. package/dist/chunks/config-PPDFSral.cjs +1 -0
  11. package/dist/chunks/config-file-37L8z8Lm.mjs +56 -0
  12. package/dist/chunks/config-file-Dvyi1e80.cjs +1 -0
  13. package/dist/chunks/factory-BPYE1-Nw.cjs +1 -0
  14. package/dist/chunks/factory-CXO2aNcc.mjs +169 -0
  15. package/dist/chunks/file-transport-DRyxQq8t.mjs +80 -0
  16. package/dist/chunks/file-transport-SA6KG1oM.cjs +1 -0
  17. package/dist/core/factory.d.cts +22 -0
  18. package/dist/core/factory.d.mts +22 -0
  19. package/dist/core/factory.d.ts +22 -0
  20. package/dist/core/transport.d.cts +73 -0
  21. package/dist/core/transport.d.mts +73 -0
  22. package/dist/core/transport.d.ts +73 -0
  23. package/dist/core/types.d.cts +9 -0
  24. package/dist/core/types.d.mts +9 -0
  25. package/dist/core/types.d.ts +9 -0
  26. package/dist/deno.cjs +1 -1
  27. package/dist/deno.d.cts +3 -1
  28. package/dist/deno.d.mts +3 -1
  29. package/dist/deno.d.ts +3 -1
  30. package/dist/deno.mjs +4 -4
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +2 -0
  33. package/dist/index.d.mts +2 -0
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.mjs +9 -9
  36. package/dist/node.cjs +1 -1
  37. package/dist/node.d.cts +3 -1
  38. package/dist/node.d.mts +3 -1
  39. package/dist/node.d.ts +3 -1
  40. package/dist/node.mjs +3 -2
  41. package/dist/runtime/file-transport.d.cts +62 -0
  42. package/dist/runtime/file-transport.d.mts +62 -0
  43. package/dist/runtime/file-transport.d.ts +62 -0
  44. package/dist/runtime/node.d.cts +39 -8
  45. package/dist/runtime/node.d.mts +39 -8
  46. package/dist/runtime/node.d.ts +39 -8
  47. package/dist/utils/config-file.d.cts +2 -0
  48. package/dist/utils/config-file.d.mts +2 -0
  49. package/dist/utils/config-file.d.ts +2 -0
  50. package/dist/utils/config.d.cts +33 -2
  51. package/dist/utils/config.d.mts +33 -2
  52. package/dist/utils/config.d.ts +33 -2
  53. package/dist/utils/formatting.d.cts +14 -1
  54. package/dist/utils/formatting.d.mts +14 -1
  55. package/dist/utils/formatting.d.ts +14 -1
  56. package/dist/utils/serialization.d.cts +30 -3
  57. package/dist/utils/serialization.d.mts +30 -3
  58. package/dist/utils/serialization.d.ts +30 -3
  59. package/package.json +3 -10
  60. package/dist/chunks/__vite-browser-external-BgoQtmXf.mjs +0 -7
  61. package/dist/chunks/__vite-browser-external-Bjj3r6ML.cjs +0 -1
  62. package/dist/chunks/browser-Bq67gUmd.cjs +0 -1
  63. package/dist/chunks/factory-2po65gyH.mjs +0 -262
  64. package/dist/chunks/factory-CluPoiZb.cjs +0 -1
  65. package/dist/chunks/formatting-CLctAPm9.mjs +0 -29
  66. package/dist/chunks/formatting-Cb_xXgov.cjs +0 -1
@@ -0,0 +1,169 @@
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 };
@@ -0,0 +1,80 @@
1
+ import { c as e } from "./config-Db6PTLH2.mjs";
2
+ import { d as t } from "./factory-CXO2aNcc.mjs";
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
+ import { dirname as u, resolve as d } from "node:path";
5
+ //#region src/runtime/file-transport.ts
6
+ var f = 5242880, p = 5, m = class {
7
+ constructor(e) {
8
+ if (this.type = "file", this.size = 0, this.warned = !1, !e?.filename) throw Error("file transport requires options.filename");
9
+ this.path = d(e.filename), this.maxsize = e.maxsize ?? f, this.maxFiles = e.maxFiles ?? p, this.format = e.format === "text" ? "text" : "json", this.timestamp = e.timestamp !== !1, this.level = e.level;
10
+ }
11
+ get filename() {
12
+ return this.path;
13
+ }
14
+ write(t) {
15
+ let n = `${e(t, this.format, {
16
+ timestamp: this.timestamp,
17
+ colorize: !1
18
+ })}\n`;
19
+ try {
20
+ this.open(), this.maxsize > 0 && this.size >= this.maxsize && (this.rotate(), this.open()), this.size += l(this.fd, n);
21
+ } catch (e) {
22
+ this.warnOnce(e);
23
+ }
24
+ }
25
+ close() {
26
+ if (this.fd !== void 0) try {
27
+ n(this.fd);
28
+ } finally {
29
+ this.fd = void 0;
30
+ }
31
+ }
32
+ open() {
33
+ if (this.fd !== void 0) return;
34
+ let e = u(this.path);
35
+ try {
36
+ a(e, { recursive: !0 });
37
+ } catch (t) {
38
+ throw h("create log directory", e, t);
39
+ }
40
+ try {
41
+ this.fd = o(this.path, "a");
42
+ } catch (e) {
43
+ throw h("open log file", this.path, e);
44
+ }
45
+ this.size = i(this.fd).size;
46
+ }
47
+ rotate() {
48
+ if (this.close(), this.maxFiles <= 0) {
49
+ r(this.path) && c(this.path), this.size = 0;
50
+ return;
51
+ }
52
+ let e = `${this.path}.${this.maxFiles}`;
53
+ r(e) && c(e);
54
+ for (let e = this.maxFiles - 1; e >= 1; e--) {
55
+ let t = `${this.path}.${e}`;
56
+ r(t) && s(t, `${this.path}.${e + 1}`);
57
+ }
58
+ r(this.path) && s(this.path, `${this.path}.1`), this.size = 0;
59
+ }
60
+ warnOnce(e) {
61
+ 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));
62
+ }
63
+ };
64
+ function h(e, t, n) {
65
+ let r = n, i = r?.code ? ` [${r.code}]` : "", a = r?.syscall ? ` during ${r.syscall}` : "", o = /* @__PURE__ */ Error(`could not ${e} '${t}'${i}${a}: ${r?.message ?? n}`);
66
+ return o.cause = n, o;
67
+ }
68
+ t("file", (e, t) => {
69
+ let n = e.options ?? {};
70
+ return new m({
71
+ filename: n.filename,
72
+ maxsize: n.maxsize,
73
+ maxFiles: n.maxFiles,
74
+ format: n.format,
75
+ timestamp: n.timestamp ?? t.timestamp,
76
+ level: e.level
77
+ });
78
+ });
79
+ //#endregion
80
+ export { m as t };
@@ -0,0 +1 @@
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}});
@@ -16,6 +16,20 @@ export declare class LoggerFactory {
16
16
  * @returns A new logger instance with the additional metadata
17
17
  */
18
18
  static createChild(parent: ILogger, metadata: Record<string, any>): ILogger;
19
+ /**
20
+ * Assemble the effective configuration.
21
+ *
22
+ * Precedence, lowest to highest:
23
+ *
24
+ * library defaults < explicit config < environment variables
25
+ *
26
+ * Environment variables win so that an operator can change logging on a
27
+ * running service without a deploy. A consumer that must not be overridden
28
+ * that way sets `ignoreEnvironment: true`.
29
+ *
30
+ * The config-file link of the chain documented in `docs/environment-variables.md`
31
+ * is still missing: `loadConfigFromFile` is async and this path is not.
32
+ */
19
33
  private static mergeConfig;
20
34
  }
21
35
  /**
@@ -42,5 +56,13 @@ export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
42
56
  * @returns A logger instance configured for the current environment
43
57
  */
44
58
  export declare function createLoggerForEnvironment(): ILogger;
59
+ /**
60
+ * Convert a level string to a `LogLevel`, falling back to INFO.
61
+ *
62
+ * Delegates to the single parser in `utils/config.ts`; use `tryParseLogLevel`
63
+ * directly when an unrecognized value should be distinguishable from `info`.
64
+ * @param level - The value to convert
65
+ * @returns The matching level, or `LogLevel.INFO`
66
+ */
45
67
  export declare function stringToLogLevel(level: string): LogLevel;
46
68
  export declare function logLevelToString(level: LogLevel): string;
@@ -16,6 +16,20 @@ export declare class LoggerFactory {
16
16
  * @returns A new logger instance with the additional metadata
17
17
  */
18
18
  static createChild(parent: ILogger, metadata: Record<string, any>): ILogger;
19
+ /**
20
+ * Assemble the effective configuration.
21
+ *
22
+ * Precedence, lowest to highest:
23
+ *
24
+ * library defaults < explicit config < environment variables
25
+ *
26
+ * Environment variables win so that an operator can change logging on a
27
+ * running service without a deploy. A consumer that must not be overridden
28
+ * that way sets `ignoreEnvironment: true`.
29
+ *
30
+ * The config-file link of the chain documented in `docs/environment-variables.md`
31
+ * is still missing: `loadConfigFromFile` is async and this path is not.
32
+ */
19
33
  private static mergeConfig;
20
34
  }
21
35
  /**
@@ -42,5 +56,13 @@ export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
42
56
  * @returns A logger instance configured for the current environment
43
57
  */
44
58
  export declare function createLoggerForEnvironment(): ILogger;
59
+ /**
60
+ * Convert a level string to a `LogLevel`, falling back to INFO.
61
+ *
62
+ * Delegates to the single parser in `utils/config.ts`; use `tryParseLogLevel`
63
+ * directly when an unrecognized value should be distinguishable from `info`.
64
+ * @param level - The value to convert
65
+ * @returns The matching level, or `LogLevel.INFO`
66
+ */
45
67
  export declare function stringToLogLevel(level: string): LogLevel;
46
68
  export declare function logLevelToString(level: LogLevel): string;
@@ -16,6 +16,20 @@ export declare class LoggerFactory {
16
16
  * @returns A new logger instance with the additional metadata
17
17
  */
18
18
  static createChild(parent: ILogger, metadata: Record<string, any>): ILogger;
19
+ /**
20
+ * Assemble the effective configuration.
21
+ *
22
+ * Precedence, lowest to highest:
23
+ *
24
+ * library defaults < explicit config < environment variables
25
+ *
26
+ * Environment variables win so that an operator can change logging on a
27
+ * running service without a deploy. A consumer that must not be overridden
28
+ * that way sets `ignoreEnvironment: true`.
29
+ *
30
+ * The config-file link of the chain documented in `docs/environment-variables.md`
31
+ * is still missing: `loadConfigFromFile` is async and this path is not.
32
+ */
19
33
  private static mergeConfig;
20
34
  }
21
35
  /**
@@ -42,5 +56,13 @@ export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
42
56
  * @returns A logger instance configured for the current environment
43
57
  */
44
58
  export declare function createLoggerForEnvironment(): ILogger;
59
+ /**
60
+ * Convert a level string to a `LogLevel`, falling back to INFO.
61
+ *
62
+ * Delegates to the single parser in `utils/config.ts`; use `tryParseLogLevel`
63
+ * directly when an unrecognized value should be distinguishable from `info`.
64
+ * @param level - The value to convert
65
+ * @returns The matching level, or `LogLevel.INFO`
66
+ */
45
67
  export declare function stringToLogLevel(level: string): LogLevel;
46
68
  export declare function logLevelToString(level: LogLevel): string;
@@ -0,0 +1,73 @@
1
+ import { FormatOptions } from '../utils/formatting.cjs';
2
+ import { LogEntry, LoggerConfig, LogLevel, TransportConfig } from './types.cjs';
3
+ /**
4
+ * A destination log entries are written to.
5
+ *
6
+ * Transports are constructed once per logger and shared with every child
7
+ * logger, so a transport that owns a resource (a file handle, a socket) must
8
+ * open exactly one of them however many children are created.
9
+ */
10
+ export interface Transport {
11
+ /** Transport type, used in diagnostics. */
12
+ readonly type: string;
13
+ /** Minimum level this transport accepts. Undefined means "whatever the logger allows". */
14
+ readonly level?: LogLevel;
15
+ /** Write one entry. */
16
+ write(entry: LogEntry): void;
17
+ /** Release any resources held. Safe to call more than once. */
18
+ close?(): void;
19
+ }
20
+ /**
21
+ * The logger-level presentation settings a transport inherits unless its own
22
+ * options override them.
23
+ */
24
+ export interface TransportContext {
25
+ format: 'json' | 'text' | 'custom';
26
+ timestamp: boolean;
27
+ colorize: boolean;
28
+ }
29
+ /** Builds a transport from its configuration entry. */
30
+ export type TransportFactory = (config: TransportConfig, context: TransportContext) => Transport;
31
+ /**
32
+ * Register a factory for a transport type so it can be named in
33
+ * `LoggerConfig.transports`.
34
+ *
35
+ * Runtime-specific transports register themselves from their runtime entry
36
+ * point — the Node file transport is registered by `logan-logger/node`, which
37
+ * is what keeps `node:fs` out of the browser build.
38
+ *
39
+ * @param type - Value matched against `TransportConfig.type`
40
+ * @param factory - Builder invoked once per configured transport
41
+ */
42
+ export declare function registerTransport(type: string, factory: TransportFactory): void;
43
+ /** Look up a registered transport factory. */
44
+ export declare function getTransportFactory(type: string): TransportFactory | undefined;
45
+ /** Options accepted by {@link ConsoleTransport}. */
46
+ export interface ConsoleTransportOptions extends FormatOptions {
47
+ /** Output shape. `'custom'` is treated as `'text'`. */
48
+ format?: 'json' | 'text' | 'custom';
49
+ /** Minimum level this transport accepts. */
50
+ level?: LogLevel;
51
+ }
52
+ /**
53
+ * Writes formatted entries to the runtime console, routing each level to the
54
+ * matching console method so devtools and journald keep their severity.
55
+ */
56
+ export declare class ConsoleTransport implements Transport {
57
+ readonly type = "console";
58
+ readonly level?: LogLevel;
59
+ private readonly format;
60
+ private readonly formatOptions;
61
+ constructor(options?: ConsoleTransportOptions);
62
+ write(entry: LogEntry): void;
63
+ }
64
+ /**
65
+ * Build the transports described by a logger configuration.
66
+ *
67
+ * Each transport is constructed behind its own guard so that one failing to
68
+ * initialize cannot take the others down with it.
69
+ *
70
+ * @param config - The logger configuration
71
+ * @returns The transports that were built successfully
72
+ */
73
+ export declare function createTransports(config: Partial<LoggerConfig>): Transport[];
@@ -0,0 +1,73 @@
1
+ import { FormatOptions } from '../utils/formatting.mjs';
2
+ import { LogEntry, LoggerConfig, LogLevel, TransportConfig } from './types.mjs';
3
+ /**
4
+ * A destination log entries are written to.
5
+ *
6
+ * Transports are constructed once per logger and shared with every child
7
+ * logger, so a transport that owns a resource (a file handle, a socket) must
8
+ * open exactly one of them however many children are created.
9
+ */
10
+ export interface Transport {
11
+ /** Transport type, used in diagnostics. */
12
+ readonly type: string;
13
+ /** Minimum level this transport accepts. Undefined means "whatever the logger allows". */
14
+ readonly level?: LogLevel;
15
+ /** Write one entry. */
16
+ write(entry: LogEntry): void;
17
+ /** Release any resources held. Safe to call more than once. */
18
+ close?(): void;
19
+ }
20
+ /**
21
+ * The logger-level presentation settings a transport inherits unless its own
22
+ * options override them.
23
+ */
24
+ export interface TransportContext {
25
+ format: 'json' | 'text' | 'custom';
26
+ timestamp: boolean;
27
+ colorize: boolean;
28
+ }
29
+ /** Builds a transport from its configuration entry. */
30
+ export type TransportFactory = (config: TransportConfig, context: TransportContext) => Transport;
31
+ /**
32
+ * Register a factory for a transport type so it can be named in
33
+ * `LoggerConfig.transports`.
34
+ *
35
+ * Runtime-specific transports register themselves from their runtime entry
36
+ * point — the Node file transport is registered by `logan-logger/node`, which
37
+ * is what keeps `node:fs` out of the browser build.
38
+ *
39
+ * @param type - Value matched against `TransportConfig.type`
40
+ * @param factory - Builder invoked once per configured transport
41
+ */
42
+ export declare function registerTransport(type: string, factory: TransportFactory): void;
43
+ /** Look up a registered transport factory. */
44
+ export declare function getTransportFactory(type: string): TransportFactory | undefined;
45
+ /** Options accepted by {@link ConsoleTransport}. */
46
+ export interface ConsoleTransportOptions extends FormatOptions {
47
+ /** Output shape. `'custom'` is treated as `'text'`. */
48
+ format?: 'json' | 'text' | 'custom';
49
+ /** Minimum level this transport accepts. */
50
+ level?: LogLevel;
51
+ }
52
+ /**
53
+ * Writes formatted entries to the runtime console, routing each level to the
54
+ * matching console method so devtools and journald keep their severity.
55
+ */
56
+ export declare class ConsoleTransport implements Transport {
57
+ readonly type = "console";
58
+ readonly level?: LogLevel;
59
+ private readonly format;
60
+ private readonly formatOptions;
61
+ constructor(options?: ConsoleTransportOptions);
62
+ write(entry: LogEntry): void;
63
+ }
64
+ /**
65
+ * Build the transports described by a logger configuration.
66
+ *
67
+ * Each transport is constructed behind its own guard so that one failing to
68
+ * initialize cannot take the others down with it.
69
+ *
70
+ * @param config - The logger configuration
71
+ * @returns The transports that were built successfully
72
+ */
73
+ export declare function createTransports(config: Partial<LoggerConfig>): Transport[];
@@ -0,0 +1,73 @@
1
+ import { FormatOptions } from '../utils/formatting';
2
+ import { LogEntry, LoggerConfig, LogLevel, TransportConfig } from './types';
3
+ /**
4
+ * A destination log entries are written to.
5
+ *
6
+ * Transports are constructed once per logger and shared with every child
7
+ * logger, so a transport that owns a resource (a file handle, a socket) must
8
+ * open exactly one of them however many children are created.
9
+ */
10
+ export interface Transport {
11
+ /** Transport type, used in diagnostics. */
12
+ readonly type: string;
13
+ /** Minimum level this transport accepts. Undefined means "whatever the logger allows". */
14
+ readonly level?: LogLevel;
15
+ /** Write one entry. */
16
+ write(entry: LogEntry): void;
17
+ /** Release any resources held. Safe to call more than once. */
18
+ close?(): void;
19
+ }
20
+ /**
21
+ * The logger-level presentation settings a transport inherits unless its own
22
+ * options override them.
23
+ */
24
+ export interface TransportContext {
25
+ format: 'json' | 'text' | 'custom';
26
+ timestamp: boolean;
27
+ colorize: boolean;
28
+ }
29
+ /** Builds a transport from its configuration entry. */
30
+ export type TransportFactory = (config: TransportConfig, context: TransportContext) => Transport;
31
+ /**
32
+ * Register a factory for a transport type so it can be named in
33
+ * `LoggerConfig.transports`.
34
+ *
35
+ * Runtime-specific transports register themselves from their runtime entry
36
+ * point — the Node file transport is registered by `logan-logger/node`, which
37
+ * is what keeps `node:fs` out of the browser build.
38
+ *
39
+ * @param type - Value matched against `TransportConfig.type`
40
+ * @param factory - Builder invoked once per configured transport
41
+ */
42
+ export declare function registerTransport(type: string, factory: TransportFactory): void;
43
+ /** Look up a registered transport factory. */
44
+ export declare function getTransportFactory(type: string): TransportFactory | undefined;
45
+ /** Options accepted by {@link ConsoleTransport}. */
46
+ export interface ConsoleTransportOptions extends FormatOptions {
47
+ /** Output shape. `'custom'` is treated as `'text'`. */
48
+ format?: 'json' | 'text' | 'custom';
49
+ /** Minimum level this transport accepts. */
50
+ level?: LogLevel;
51
+ }
52
+ /**
53
+ * Writes formatted entries to the runtime console, routing each level to the
54
+ * matching console method so devtools and journald keep their severity.
55
+ */
56
+ export declare class ConsoleTransport implements Transport {
57
+ readonly type = "console";
58
+ readonly level?: LogLevel;
59
+ private readonly format;
60
+ private readonly formatOptions;
61
+ constructor(options?: ConsoleTransportOptions);
62
+ write(entry: LogEntry): void;
63
+ }
64
+ /**
65
+ * Build the transports described by a logger configuration.
66
+ *
67
+ * Each transport is constructed behind its own guard so that one failing to
68
+ * initialize cannot take the others down with it.
69
+ *
70
+ * @param config - The logger configuration
71
+ * @returns The transports that were built successfully
72
+ */
73
+ export declare function createTransports(config: Partial<LoggerConfig>): Transport[];
@@ -62,6 +62,15 @@ export interface LoggerConfig {
62
62
  metadata: Record<string, any>;
63
63
  /** Transport configurations for log output */
64
64
  transports?: TransportConfig[];
65
+ /**
66
+ * Ignore `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP` and `LOG_COLOR`.
67
+ *
68
+ * Environment variables normally sit at the top of the precedence chain so an
69
+ * operator can raise verbosity on a running service without a deploy. A
70
+ * library that must pin its own logging regardless of the host application's
71
+ * environment sets this instead.
72
+ */
73
+ ignoreEnvironment?: boolean;
65
74
  }
66
75
  /**
67
76
  * Configuration for a specific log transport (output destination).
@@ -62,6 +62,15 @@ export interface LoggerConfig {
62
62
  metadata: Record<string, any>;
63
63
  /** Transport configurations for log output */
64
64
  transports?: TransportConfig[];
65
+ /**
66
+ * Ignore `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP` and `LOG_COLOR`.
67
+ *
68
+ * Environment variables normally sit at the top of the precedence chain so an
69
+ * operator can raise verbosity on a running service without a deploy. A
70
+ * library that must pin its own logging regardless of the host application's
71
+ * environment sets this instead.
72
+ */
73
+ ignoreEnvironment?: boolean;
65
74
  }
66
75
  /**
67
76
  * Configuration for a specific log transport (output destination).
@@ -62,6 +62,15 @@ export interface LoggerConfig {
62
62
  metadata: Record<string, any>;
63
63
  /** Transport configurations for log output */
64
64
  transports?: TransportConfig[];
65
+ /**
66
+ * Ignore `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP` and `LOG_COLOR`.
67
+ *
68
+ * Environment variables normally sit at the top of the precedence chain so an
69
+ * operator can raise verbosity on a running service without a deploy. A
70
+ * library that must pin its own logging regardless of the host application's
71
+ * environment sets this instead.
72
+ */
73
+ ignoreEnvironment?: boolean;
65
74
  }
66
75
  /**
67
76
  * Configuration for a specific log transport (output destination).
package/dist/deno.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/factory-CluPoiZb.cjs"),t=require("./chunks/browser-Bq67gUmd.cjs"),n=require("./chunks/formatting-Cb_xXgov.cjs");exports.BrowserLogger=t.t,exports.ConsoleGroupLogger=t.n,exports.PerformanceLogger=t.r,exports.createLogger=e.n,exports.createLoggerForEnvironment=e.r,exports.detectRuntime=t.l,exports.filterSensitiveData=t.i,exports.formatLevel=n.t,exports.formatLogEntry=n.n,exports.getDefaultConfig=e.o,exports.isBrowser=t.u,exports.isBun=t.d,exports.isDeno=t.f,exports.isNode=t.p,exports.loadConfigFromEnvironment=e.s,exports.loadConfigFromFile=e.c,exports.mergeConfigs=e.l,exports.safeStringify=t.a,exports.serializeError=t.o;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/config-PPDFSral.cjs"),t=require("./chunks/factory-BPYE1-Nw.cjs"),n=require("./chunks/config-file-Dvyi1e80.cjs");exports.BrowserLogger=e.l,exports.ConsoleGroupLogger=e.u,exports.ConsoleTransport=t.c,exports.PerformanceLogger=e.d,exports.createLogger=t.n,exports.createLoggerForEnvironment=t.r,exports.createTransports=t.l,exports.detectRuntime=e._,exports.filterSensitiveData=e.f,exports.formatLevel=e.s,exports.formatLogEntry=e.c,exports.getDefaultConfig=e.t,exports.isBrowser=e.v,exports.isBun=e.y,exports.isDeno=e.b,exports.isNode=e.x,exports.loadConfigFromEnvironment=e.n,exports.loadConfigFromFile=n.t,exports.mergeConfigs=e.r,exports.registerTransport=t.d,exports.resetEnvironmentWarnings=e.i,exports.safeStringify=e.p,exports.serializeError=e.m,exports.shouldColorize=e.a,exports.tryParseLogLevel=e.o;
package/dist/deno.d.cts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { createLogger, createLoggerForEnvironment } from './core/factory.cjs';
2
- export type { ILogger, LoggerConfig, LogLevel } from './core/types.cjs';
2
+ export { ConsoleTransport, createTransports, registerTransport, type Transport, type TransportFactory, } from './core/transport.cjs';
3
+ export type { ILogger, LoggerConfig, LogLevel, TransportConfig } from './core/types.cjs';
3
4
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser.cjs';
5
+ export * from './utils/config-file.cjs';
4
6
  export * from './utils/config.cjs';
5
7
  export * from './utils/formatting.cjs';
6
8
  export * from './utils/runtime.cjs';
package/dist/deno.d.mts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { createLogger, createLoggerForEnvironment } from './core/factory.mjs';
2
- export type { ILogger, LoggerConfig, LogLevel } from './core/types.mjs';
2
+ export { ConsoleTransport, createTransports, registerTransport, type Transport, type TransportFactory, } from './core/transport.mjs';
3
+ export type { ILogger, LoggerConfig, LogLevel, TransportConfig } from './core/types.mjs';
3
4
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser.mjs';
5
+ export * from './utils/config-file.mjs';
4
6
  export * from './utils/config.mjs';
5
7
  export * from './utils/formatting.mjs';
6
8
  export * from './utils/runtime.mjs';
package/dist/deno.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { createLogger, createLoggerForEnvironment } from './core/factory';
2
- export type { ILogger, LoggerConfig, LogLevel } from './core/types';
2
+ export { ConsoleTransport, createTransports, registerTransport, type Transport, type TransportFactory, } from './core/transport';
3
+ export type { ILogger, LoggerConfig, LogLevel, TransportConfig } from './core/types';
3
4
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser';
5
+ export * from './utils/config-file';
4
6
  export * from './utils/config';
5
7
  export * from './utils/formatting';
6
8
  export * from './utils/runtime';