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
package/dist/deno.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as e, l as t, n, o as r, r as i, s as a } from "./chunks/factory-2po65gyH.mjs";
2
- import { a as o, d as s, f as c, i as l, l as u, n as d, o as f, p, r as m, t as h, u as g } from "./chunks/browser-D5QY2oJb.mjs";
3
- import { n as _, t as v } from "./chunks/formatting-CLctAPm9.mjs";
4
- export { h as BrowserLogger, d as ConsoleGroupLogger, m as PerformanceLogger, n as createLogger, i as createLoggerForEnvironment, u as detectRuntime, l as filterSensitiveData, v as formatLevel, _ as formatLogEntry, r as getDefaultConfig, g as isBrowser, s as isBun, c as isDeno, p as isNode, a as loadConfigFromEnvironment, e as loadConfigFromFile, t as mergeConfigs, o as safeStringify, f as serializeError };
1
+ import { _ as e, a as t, b as n, c as r, d as i, f as a, i as o, l as s, m as c, n as l, o as u, p as d, r as f, s as p, t as m, u as h, v as g, x as _, y as v } from "./chunks/config-Db6PTLH2.mjs";
2
+ import { c as y, d as b, l as x, n as S, r as C } from "./chunks/factory-CXO2aNcc.mjs";
3
+ import { t as w } from "./chunks/config-file-37L8z8Lm.mjs";
4
+ export { s as BrowserLogger, h as ConsoleGroupLogger, y as ConsoleTransport, i as PerformanceLogger, S as createLogger, C as createLoggerForEnvironment, x as createTransports, e as detectRuntime, a as filterSensitiveData, p as formatLevel, r as formatLogEntry, m as getDefaultConfig, g as isBrowser, v as isBun, n as isDeno, _ as isNode, l as loadConfigFromEnvironment, w as loadConfigFromFile, f as mergeConfigs, b as registerTransport, o as resetEnvironmentWarnings, d as safeStringify, c as serializeError, t as shouldColorize, u as tryParseLogLevel };
package/dist/index.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");var r=e.r(),i={debug:(e,t)=>r.debug(e,t),info:(e,t)=>r.info(e,t),warn:(e,t)=>r.warn(e,t),error:(e,t)=>r.error(e,t)};exports.BaseLogger=t.s,exports.BrowserLogger=t.t,exports.ConsoleGroupLogger=t.n,exports.LogLevel=t.c,exports.LoggerFactory=e.t,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.log=i,exports.logLevelToString=e.i,exports.logger=r,exports.mergeConfigs=e.l,exports.safeStringify=t.a,exports.serializeError=t.o,exports.stringToLogLevel=e.a;
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");var r=t.r(),i={debug:(e,t)=>r.debug(e,t),info:(e,t)=>r.info(e,t),warn:(e,t)=>r.warn(e,t),error:(e,t)=>r.error(e,t)};exports.BaseLogger=e.h,exports.BrowserLogger=e.l,exports.ConsoleGroupLogger=e.u,exports.ConsoleTransport=t.c,exports.LogLevel=e.g,exports.LoggerFactory=t.t,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.getTransportFactory=t.u,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.log=i,exports.logLevelToString=t.i,exports.logger=r,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.stringToLogLevel=t.a,exports.tryParseLogLevel=e.o;
package/dist/index.d.cts CHANGED
@@ -2,8 +2,10 @@ import { createLogger, createLoggerForEnvironment } from './core/factory.cjs';
2
2
  import { ILogger, LogLevel } from './core/types.cjs';
3
3
  export * from './core/factory.cjs';
4
4
  export * from './core/logger.cjs';
5
+ export * from './core/transport.cjs';
5
6
  export * from './core/types.cjs';
6
7
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser.cjs';
8
+ export * from './utils/config-file.cjs';
7
9
  export * from './utils/config.cjs';
8
10
  export * from './utils/formatting.cjs';
9
11
  export * from './utils/runtime.cjs';
package/dist/index.d.mts CHANGED
@@ -2,8 +2,10 @@ import { createLogger, createLoggerForEnvironment } from './core/factory.mjs';
2
2
  import { ILogger, LogLevel } from './core/types.mjs';
3
3
  export * from './core/factory.mjs';
4
4
  export * from './core/logger.mjs';
5
+ export * from './core/transport.mjs';
5
6
  export * from './core/types.mjs';
6
7
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser.mjs';
8
+ export * from './utils/config-file.mjs';
7
9
  export * from './utils/config.mjs';
8
10
  export * from './utils/formatting.mjs';
9
11
  export * from './utils/runtime.mjs';
package/dist/index.d.ts CHANGED
@@ -2,8 +2,10 @@ import { createLogger, createLoggerForEnvironment } from './core/factory';
2
2
  import { ILogger, LogLevel } from './core/types';
3
3
  export * from './core/factory';
4
4
  export * from './core/logger';
5
+ export * from './core/transport';
5
6
  export * from './core/types';
6
7
  export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser';
8
+ export * from './utils/config-file';
7
9
  export * from './utils/config';
8
10
  export * from './utils/formatting';
9
11
  export * from './utils/runtime';
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./chunks/factory-2po65gyH.mjs";
2
- import { a as l, c as u, d, f, i as p, l as m, n as h, o as g, p as _, r as v, s as y, t as b, u as x } from "./chunks/browser-D5QY2oJb.mjs";
3
- import { n as S, t as C } from "./chunks/formatting-CLctAPm9.mjs";
1
+ import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v, x as y, y as b } from "./chunks/config-Db6PTLH2.mjs";
2
+ import { a as x, c as S, d as C, i as w, l as T, n as E, r as D, t as O, u as k } from "./chunks/factory-CXO2aNcc.mjs";
3
+ import { t as A } from "./chunks/config-file-37L8z8Lm.mjs";
4
4
  //#region src/index.ts
5
- var w = o(), T = {
6
- debug: (e, t) => w.debug(e, t),
7
- info: (e, t) => w.info(e, t),
8
- warn: (e, t) => w.warn(e, t),
9
- error: (e, t) => w.error(e, t)
5
+ var j = D(), M = {
6
+ debug: (e, t) => j.debug(e, t),
7
+ info: (e, t) => j.info(e, t),
8
+ warn: (e, t) => j.warn(e, t),
9
+ error: (e, t) => j.error(e, t)
10
10
  };
11
11
  //#endregion
12
- export { y as BaseLogger, b as BrowserLogger, h as ConsoleGroupLogger, u as LogLevel, c as LoggerFactory, v as PerformanceLogger, i as createLogger, o as createLoggerForEnvironment, m as detectRuntime, p as filterSensitiveData, C as formatLevel, S as formatLogEntry, a as getDefaultConfig, x as isBrowser, d as isBun, f as isDeno, _ as isNode, s as loadConfigFromEnvironment, t as loadConfigFromFile, T as log, n as logLevelToString, w as logger, r as mergeConfigs, l as safeStringify, g as serializeError, e as stringToLogLevel };
12
+ export { s as BaseLogger, l as BrowserLogger, _ as ConsoleGroupLogger, S as ConsoleTransport, o as LogLevel, O as LoggerFactory, i as PerformanceLogger, E as createLogger, D as createLoggerForEnvironment, T as createTransports, e as detectRuntime, a as filterSensitiveData, h as formatLevel, r as formatLogEntry, g as getDefaultConfig, k as getTransportFactory, v as isBrowser, b as isBun, n as isDeno, y as isNode, d as loadConfigFromEnvironment, A as loadConfigFromFile, M as log, w as logLevelToString, j as logger, m as mergeConfigs, C as registerTransport, c as resetEnvironmentWarnings, p as safeStringify, u as serializeError, t as shouldColorize, x as stringToLogLevel, f as tryParseLogLevel };
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/factory-CluPoiZb.cjs");exports.NodeLogger=e.u,exports.createLogger=e.n,exports.createLoggerForEnvironment=e.r,exports.createMorganStream=e.d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/factory-BPYE1-Nw.cjs"),t=require("./chunks/file-transport-SA6KG1oM.cjs");exports.ConsoleTransport=e.c,exports.FileTransport=t.t,exports.NodeLogger=e.o,exports.createLogger=e.n,exports.createLoggerForEnvironment=e.r,exports.createMorganStream=e.s,exports.createTransports=e.l,exports.registerTransport=e.d;
package/dist/node.d.cts CHANGED
@@ -1,3 +1,5 @@
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';
4
+ export { FileTransport, type FileTransportOptions } from './runtime/file-transport.cjs';
3
5
  export { createMorganStream, NodeLogger } from './runtime/node.cjs';
package/dist/node.d.mts CHANGED
@@ -1,3 +1,5 @@
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';
4
+ export { FileTransport, type FileTransportOptions } from './runtime/file-transport.mjs';
3
5
  export { createMorganStream, NodeLogger } from './runtime/node.mjs';
package/dist/node.d.ts CHANGED
@@ -1,3 +1,5 @@
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';
4
+ export { FileTransport, type FileTransportOptions } from './runtime/file-transport';
3
5
  export { createMorganStream, NodeLogger } from './runtime/node';
package/dist/node.mjs CHANGED
@@ -1,2 +1,3 @@
1
- import { d as e, n as t, r as n, u as r } from "./chunks/factory-2po65gyH.mjs";
2
- export { r as NodeLogger, t as createLogger, n as createLoggerForEnvironment, e as createMorganStream };
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 };
@@ -0,0 +1,62 @@
1
+ import { Transport } from '../core/transport.cjs';
2
+ import { LogEntry, LogLevel } from '../core/types.cjs';
3
+ /** Options accepted by {@link FileTransport}. */
4
+ export interface FileTransportOptions {
5
+ /** Path to the active log file. Relative paths resolve against `process.cwd()`. */
6
+ filename: string;
7
+ /** Rotate once the active file reaches this many bytes. `0` disables rotation. */
8
+ maxsize?: number;
9
+ /** How many rotated archives to keep (`name.log.1` … `name.log.N`). */
10
+ maxFiles?: number;
11
+ /**
12
+ * Output shape written to the file. Defaults to `'json'` — files are read by
13
+ * machines, so the structured envelope wins even when the logger's own
14
+ * format is `'text'`. Set this explicitly to write human-readable lines.
15
+ */
16
+ format?: 'json' | 'text' | 'custom';
17
+ /** Include the timestamp in the text form. Defaults to `true`. */
18
+ timestamp?: boolean;
19
+ /** Minimum level this transport accepts. */
20
+ level?: LogLevel;
21
+ }
22
+ /**
23
+ * Appends log entries to a file, rotating by size.
24
+ *
25
+ * Design notes, all of which are deliberate:
26
+ *
27
+ * - **The directory and file handle are created lazily, on first write.** A
28
+ * logger that is constructed but never writes to a file touches the disk
29
+ * zero times, which is what makes file logging safe to configure in a
30
+ * read-only container.
31
+ * - **Writes are synchronous `writeSync` calls against a held file
32
+ * descriptor.** That costs one syscall per line, and in exchange nothing
33
+ * sits in a userland buffer waiting to be lost when the process exits.
34
+ * - **Failures warn once and never throw.** A logging destination going away
35
+ * must not take the application with it, and it must not spam the console
36
+ * on every subsequent line either.
37
+ */
38
+ export declare class FileTransport implements Transport {
39
+ readonly type = "file";
40
+ readonly level?: LogLevel;
41
+ private readonly path;
42
+ private readonly maxsize;
43
+ private readonly maxFiles;
44
+ private readonly format;
45
+ private readonly timestamp;
46
+ private fd?;
47
+ private size;
48
+ private warned;
49
+ constructor(options: FileTransportOptions);
50
+ /** Absolute path of the active log file. */
51
+ get filename(): string;
52
+ write(entry: LogEntry): void;
53
+ close(): void;
54
+ private open;
55
+ /**
56
+ * Shift the archives along by one and start a fresh active file.
57
+ * `name.log` becomes `name.log.1`, `name.log.1` becomes `name.log.2`, and
58
+ * whatever was at `name.log.<maxFiles>` is dropped.
59
+ */
60
+ private rotate;
61
+ private warnOnce;
62
+ }
@@ -0,0 +1,62 @@
1
+ import { Transport } from '../core/transport.mjs';
2
+ import { LogEntry, LogLevel } from '../core/types.mjs';
3
+ /** Options accepted by {@link FileTransport}. */
4
+ export interface FileTransportOptions {
5
+ /** Path to the active log file. Relative paths resolve against `process.cwd()`. */
6
+ filename: string;
7
+ /** Rotate once the active file reaches this many bytes. `0` disables rotation. */
8
+ maxsize?: number;
9
+ /** How many rotated archives to keep (`name.log.1` … `name.log.N`). */
10
+ maxFiles?: number;
11
+ /**
12
+ * Output shape written to the file. Defaults to `'json'` — files are read by
13
+ * machines, so the structured envelope wins even when the logger's own
14
+ * format is `'text'`. Set this explicitly to write human-readable lines.
15
+ */
16
+ format?: 'json' | 'text' | 'custom';
17
+ /** Include the timestamp in the text form. Defaults to `true`. */
18
+ timestamp?: boolean;
19
+ /** Minimum level this transport accepts. */
20
+ level?: LogLevel;
21
+ }
22
+ /**
23
+ * Appends log entries to a file, rotating by size.
24
+ *
25
+ * Design notes, all of which are deliberate:
26
+ *
27
+ * - **The directory and file handle are created lazily, on first write.** A
28
+ * logger that is constructed but never writes to a file touches the disk
29
+ * zero times, which is what makes file logging safe to configure in a
30
+ * read-only container.
31
+ * - **Writes are synchronous `writeSync` calls against a held file
32
+ * descriptor.** That costs one syscall per line, and in exchange nothing
33
+ * sits in a userland buffer waiting to be lost when the process exits.
34
+ * - **Failures warn once and never throw.** A logging destination going away
35
+ * must not take the application with it, and it must not spam the console
36
+ * on every subsequent line either.
37
+ */
38
+ export declare class FileTransport implements Transport {
39
+ readonly type = "file";
40
+ readonly level?: LogLevel;
41
+ private readonly path;
42
+ private readonly maxsize;
43
+ private readonly maxFiles;
44
+ private readonly format;
45
+ private readonly timestamp;
46
+ private fd?;
47
+ private size;
48
+ private warned;
49
+ constructor(options: FileTransportOptions);
50
+ /** Absolute path of the active log file. */
51
+ get filename(): string;
52
+ write(entry: LogEntry): void;
53
+ close(): void;
54
+ private open;
55
+ /**
56
+ * Shift the archives along by one and start a fresh active file.
57
+ * `name.log` becomes `name.log.1`, `name.log.1` becomes `name.log.2`, and
58
+ * whatever was at `name.log.<maxFiles>` is dropped.
59
+ */
60
+ private rotate;
61
+ private warnOnce;
62
+ }
@@ -0,0 +1,62 @@
1
+ import { Transport } from '../core/transport';
2
+ import { LogEntry, LogLevel } from '../core/types';
3
+ /** Options accepted by {@link FileTransport}. */
4
+ export interface FileTransportOptions {
5
+ /** Path to the active log file. Relative paths resolve against `process.cwd()`. */
6
+ filename: string;
7
+ /** Rotate once the active file reaches this many bytes. `0` disables rotation. */
8
+ maxsize?: number;
9
+ /** How many rotated archives to keep (`name.log.1` … `name.log.N`). */
10
+ maxFiles?: number;
11
+ /**
12
+ * Output shape written to the file. Defaults to `'json'` — files are read by
13
+ * machines, so the structured envelope wins even when the logger's own
14
+ * format is `'text'`. Set this explicitly to write human-readable lines.
15
+ */
16
+ format?: 'json' | 'text' | 'custom';
17
+ /** Include the timestamp in the text form. Defaults to `true`. */
18
+ timestamp?: boolean;
19
+ /** Minimum level this transport accepts. */
20
+ level?: LogLevel;
21
+ }
22
+ /**
23
+ * Appends log entries to a file, rotating by size.
24
+ *
25
+ * Design notes, all of which are deliberate:
26
+ *
27
+ * - **The directory and file handle are created lazily, on first write.** A
28
+ * logger that is constructed but never writes to a file touches the disk
29
+ * zero times, which is what makes file logging safe to configure in a
30
+ * read-only container.
31
+ * - **Writes are synchronous `writeSync` calls against a held file
32
+ * descriptor.** That costs one syscall per line, and in exchange nothing
33
+ * sits in a userland buffer waiting to be lost when the process exits.
34
+ * - **Failures warn once and never throw.** A logging destination going away
35
+ * must not take the application with it, and it must not spam the console
36
+ * on every subsequent line either.
37
+ */
38
+ export declare class FileTransport implements Transport {
39
+ readonly type = "file";
40
+ readonly level?: LogLevel;
41
+ private readonly path;
42
+ private readonly maxsize;
43
+ private readonly maxFiles;
44
+ private readonly format;
45
+ private readonly timestamp;
46
+ private fd?;
47
+ private size;
48
+ private warned;
49
+ constructor(options: FileTransportOptions);
50
+ /** Absolute path of the active log file. */
51
+ get filename(): string;
52
+ write(entry: LogEntry): void;
53
+ close(): void;
54
+ private open;
55
+ /**
56
+ * Shift the archives along by one and start a fresh active file.
57
+ * `name.log` becomes `name.log.1`, `name.log.1` becomes `name.log.2`, and
58
+ * whatever was at `name.log.<maxFiles>` is dropped.
59
+ */
60
+ private rotate;
61
+ private warnOnce;
62
+ }
@@ -1,16 +1,47 @@
1
1
  import { BaseLogger } from '../core/logger.cjs';
2
- import { LogEntry, LoggerConfig, LogLevel } from '../core/types.cjs';
2
+ import { Transport } from '../core/transport.cjs';
3
+ import { LogEntry, LoggerConfig } from '../core/types.cjs';
4
+ /**
5
+ * Logger for Node.js and Bun.
6
+ *
7
+ * Writes through an explicit list of transports built from
8
+ * `LoggerConfig.transports`. With no transports configured it writes to the
9
+ * console and nowhere else — file logging is opt-in, never implied by
10
+ * `NODE_ENV`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { NodeLogger, LogLevel } from 'logan-logger/node';
15
+ *
16
+ * const logger = new NodeLogger({
17
+ * level: LogLevel.INFO,
18
+ * transports: [
19
+ * { type: 'console', options: {} },
20
+ * { type: 'file', level: LogLevel.ERROR, options: { filename: 'logs/error.log' } },
21
+ * ],
22
+ * });
23
+ * ```
24
+ */
3
25
  export declare class NodeLogger extends BaseLogger {
4
- private winston?;
5
- constructor(config?: Partial<LoggerConfig>);
6
- private initializeWinston;
7
- private createWinstonLogger;
26
+ private readonly transports;
27
+ /**
28
+ * @param config - Logger configuration
29
+ * @param transports - Pre-built transports to adopt instead of building new
30
+ * ones. Used internally so a child logger shares its parent's destinations.
31
+ */
32
+ constructor(config?: Partial<LoggerConfig>, transports?: Transport[]);
33
+ /** The transports this logger writes through. */
34
+ getTransports(): readonly Transport[];
35
+ /** Release every transport's resources. */
36
+ close(): void;
8
37
  protected writeLog(entry: LogEntry): void;
9
38
  protected createChild(): BaseLogger;
10
- private writeToConsole;
11
- private getWinstonLevel;
12
- setLevel(level: LogLevel): void;
13
39
  }
40
+ /**
41
+ * Create a Morgan-compatible stream that forwards HTTP access logs to a logger.
42
+ * @param logger - The logger to write through
43
+ * @returns An object with a `write` method Morgan can use
44
+ */
14
45
  export declare function createMorganStream(logger: NodeLogger): {
15
46
  write: (message: string) => void;
16
47
  };
@@ -1,16 +1,47 @@
1
1
  import { BaseLogger } from '../core/logger.mjs';
2
- import { LogEntry, LoggerConfig, LogLevel } from '../core/types.mjs';
2
+ import { Transport } from '../core/transport.mjs';
3
+ import { LogEntry, LoggerConfig } from '../core/types.mjs';
4
+ /**
5
+ * Logger for Node.js and Bun.
6
+ *
7
+ * Writes through an explicit list of transports built from
8
+ * `LoggerConfig.transports`. With no transports configured it writes to the
9
+ * console and nowhere else — file logging is opt-in, never implied by
10
+ * `NODE_ENV`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { NodeLogger, LogLevel } from 'logan-logger/node';
15
+ *
16
+ * const logger = new NodeLogger({
17
+ * level: LogLevel.INFO,
18
+ * transports: [
19
+ * { type: 'console', options: {} },
20
+ * { type: 'file', level: LogLevel.ERROR, options: { filename: 'logs/error.log' } },
21
+ * ],
22
+ * });
23
+ * ```
24
+ */
3
25
  export declare class NodeLogger extends BaseLogger {
4
- private winston?;
5
- constructor(config?: Partial<LoggerConfig>);
6
- private initializeWinston;
7
- private createWinstonLogger;
26
+ private readonly transports;
27
+ /**
28
+ * @param config - Logger configuration
29
+ * @param transports - Pre-built transports to adopt instead of building new
30
+ * ones. Used internally so a child logger shares its parent's destinations.
31
+ */
32
+ constructor(config?: Partial<LoggerConfig>, transports?: Transport[]);
33
+ /** The transports this logger writes through. */
34
+ getTransports(): readonly Transport[];
35
+ /** Release every transport's resources. */
36
+ close(): void;
8
37
  protected writeLog(entry: LogEntry): void;
9
38
  protected createChild(): BaseLogger;
10
- private writeToConsole;
11
- private getWinstonLevel;
12
- setLevel(level: LogLevel): void;
13
39
  }
40
+ /**
41
+ * Create a Morgan-compatible stream that forwards HTTP access logs to a logger.
42
+ * @param logger - The logger to write through
43
+ * @returns An object with a `write` method Morgan can use
44
+ */
14
45
  export declare function createMorganStream(logger: NodeLogger): {
15
46
  write: (message: string) => void;
16
47
  };
@@ -1,16 +1,47 @@
1
1
  import { BaseLogger } from '../core/logger';
2
- import { LogEntry, LoggerConfig, LogLevel } from '../core/types';
2
+ import { Transport } from '../core/transport';
3
+ import { LogEntry, LoggerConfig } from '../core/types';
4
+ /**
5
+ * Logger for Node.js and Bun.
6
+ *
7
+ * Writes through an explicit list of transports built from
8
+ * `LoggerConfig.transports`. With no transports configured it writes to the
9
+ * console and nowhere else — file logging is opt-in, never implied by
10
+ * `NODE_ENV`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { NodeLogger, LogLevel } from 'logan-logger/node';
15
+ *
16
+ * const logger = new NodeLogger({
17
+ * level: LogLevel.INFO,
18
+ * transports: [
19
+ * { type: 'console', options: {} },
20
+ * { type: 'file', level: LogLevel.ERROR, options: { filename: 'logs/error.log' } },
21
+ * ],
22
+ * });
23
+ * ```
24
+ */
3
25
  export declare class NodeLogger extends BaseLogger {
4
- private winston?;
5
- constructor(config?: Partial<LoggerConfig>);
6
- private initializeWinston;
7
- private createWinstonLogger;
26
+ private readonly transports;
27
+ /**
28
+ * @param config - Logger configuration
29
+ * @param transports - Pre-built transports to adopt instead of building new
30
+ * ones. Used internally so a child logger shares its parent's destinations.
31
+ */
32
+ constructor(config?: Partial<LoggerConfig>, transports?: Transport[]);
33
+ /** The transports this logger writes through. */
34
+ getTransports(): readonly Transport[];
35
+ /** Release every transport's resources. */
36
+ close(): void;
8
37
  protected writeLog(entry: LogEntry): void;
9
38
  protected createChild(): BaseLogger;
10
- private writeToConsole;
11
- private getWinstonLevel;
12
- setLevel(level: LogLevel): void;
13
39
  }
40
+ /**
41
+ * Create a Morgan-compatible stream that forwards HTTP access logs to a logger.
42
+ * @param logger - The logger to write through
43
+ * @returns An object with a `write` method Morgan can use
44
+ */
14
45
  export declare function createMorganStream(logger: NodeLogger): {
15
46
  write: (message: string) => void;
16
47
  };
@@ -0,0 +1,2 @@
1
+ import { LoggerConfig } from '../core/types.cjs';
2
+ export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
@@ -0,0 +1,2 @@
1
+ import { LoggerConfig } from '../core/types.mjs';
2
+ export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
@@ -0,0 +1,2 @@
1
+ import { LoggerConfig } from '../core/types';
2
+ export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
@@ -1,5 +1,36 @@
1
- import { LoggerConfig } from '../core/types.cjs';
1
+ import { LoggerConfig, LogLevel } from '../core/types.cjs';
2
+ /**
3
+ * Whether colored output is appropriate right now.
4
+ *
5
+ * `capabilities.colorSupport` answers whether the runtime *can* colorize.
6
+ * This answers whether it *should*: writing ANSI escapes into a redirected
7
+ * file or a log shipper is worse than writing none, so a non-TTY stdout
8
+ * disables color unless the caller forces it. Honors the `NO_COLOR` and
9
+ * `FORCE_COLOR` conventions.
10
+ * @returns True when the level token should carry ANSI color
11
+ */
12
+ export declare function shouldColorize(): boolean;
2
13
  export declare function getDefaultConfig(): LoggerConfig;
14
+ /**
15
+ * Reset the warn-once state. Exposed for tests; not part of the public contract.
16
+ */
17
+ export declare function resetEnvironmentWarnings(): void;
18
+ /**
19
+ * Parse a log level string, reporting failure rather than guessing.
20
+ * @param level - The value to parse
21
+ * @returns The matching level, or undefined if the value is not recognized
22
+ */
23
+ export declare function tryParseLogLevel(level: string): LogLevel | undefined;
24
+ /**
25
+ * Read logger configuration from `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP`
26
+ * and `LOG_COLOR`.
27
+ *
28
+ * Only variables that are set and parse successfully appear in the result, so
29
+ * an absent or malformed variable leaves lower-precedence sources untouched.
30
+ *
31
+ * In a browser these values exist only if the bundler inlined them at build
32
+ * time; otherwise this returns an empty object.
33
+ * @returns The subset of configuration the environment specifies
34
+ */
3
35
  export declare function loadConfigFromEnvironment(): Partial<LoggerConfig>;
4
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
5
36
  export declare function mergeConfigs(...configs: Partial<LoggerConfig>[]): LoggerConfig;
@@ -1,5 +1,36 @@
1
- import { LoggerConfig } from '../core/types.mjs';
1
+ import { LoggerConfig, LogLevel } from '../core/types.mjs';
2
+ /**
3
+ * Whether colored output is appropriate right now.
4
+ *
5
+ * `capabilities.colorSupport` answers whether the runtime *can* colorize.
6
+ * This answers whether it *should*: writing ANSI escapes into a redirected
7
+ * file or a log shipper is worse than writing none, so a non-TTY stdout
8
+ * disables color unless the caller forces it. Honors the `NO_COLOR` and
9
+ * `FORCE_COLOR` conventions.
10
+ * @returns True when the level token should carry ANSI color
11
+ */
12
+ export declare function shouldColorize(): boolean;
2
13
  export declare function getDefaultConfig(): LoggerConfig;
14
+ /**
15
+ * Reset the warn-once state. Exposed for tests; not part of the public contract.
16
+ */
17
+ export declare function resetEnvironmentWarnings(): void;
18
+ /**
19
+ * Parse a log level string, reporting failure rather than guessing.
20
+ * @param level - The value to parse
21
+ * @returns The matching level, or undefined if the value is not recognized
22
+ */
23
+ export declare function tryParseLogLevel(level: string): LogLevel | undefined;
24
+ /**
25
+ * Read logger configuration from `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP`
26
+ * and `LOG_COLOR`.
27
+ *
28
+ * Only variables that are set and parse successfully appear in the result, so
29
+ * an absent or malformed variable leaves lower-precedence sources untouched.
30
+ *
31
+ * In a browser these values exist only if the bundler inlined them at build
32
+ * time; otherwise this returns an empty object.
33
+ * @returns The subset of configuration the environment specifies
34
+ */
3
35
  export declare function loadConfigFromEnvironment(): Partial<LoggerConfig>;
4
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
5
36
  export declare function mergeConfigs(...configs: Partial<LoggerConfig>[]): LoggerConfig;
@@ -1,5 +1,36 @@
1
- import { LoggerConfig } from '../core/types';
1
+ import { LoggerConfig, LogLevel } from '../core/types';
2
+ /**
3
+ * Whether colored output is appropriate right now.
4
+ *
5
+ * `capabilities.colorSupport` answers whether the runtime *can* colorize.
6
+ * This answers whether it *should*: writing ANSI escapes into a redirected
7
+ * file or a log shipper is worse than writing none, so a non-TTY stdout
8
+ * disables color unless the caller forces it. Honors the `NO_COLOR` and
9
+ * `FORCE_COLOR` conventions.
10
+ * @returns True when the level token should carry ANSI color
11
+ */
12
+ export declare function shouldColorize(): boolean;
2
13
  export declare function getDefaultConfig(): LoggerConfig;
14
+ /**
15
+ * Reset the warn-once state. Exposed for tests; not part of the public contract.
16
+ */
17
+ export declare function resetEnvironmentWarnings(): void;
18
+ /**
19
+ * Parse a log level string, reporting failure rather than guessing.
20
+ * @param level - The value to parse
21
+ * @returns The matching level, or undefined if the value is not recognized
22
+ */
23
+ export declare function tryParseLogLevel(level: string): LogLevel | undefined;
24
+ /**
25
+ * Read logger configuration from `LOG_LEVEL`, `LOG_FORMAT`, `LOG_TIMESTAMP`
26
+ * and `LOG_COLOR`.
27
+ *
28
+ * Only variables that are set and parse successfully appear in the result, so
29
+ * an absent or malformed variable leaves lower-precedence sources untouched.
30
+ *
31
+ * In a browser these values exist only if the bundler inlined them at build
32
+ * time; otherwise this returns an empty object.
33
+ * @returns The subset of configuration the environment specifies
34
+ */
3
35
  export declare function loadConfigFromEnvironment(): Partial<LoggerConfig>;
4
- export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
5
36
  export declare function mergeConfigs(...configs: Partial<LoggerConfig>[]): LoggerConfig;
@@ -1,8 +1,18 @@
1
1
  import { LogEntry, LogLevel } from '../core/types.cjs';
2
+ /**
3
+ * Presentation options for {@link formatLogEntry}, drawn from `LoggerConfig`.
4
+ */
5
+ export interface FormatOptions {
6
+ /** Include the timestamp in the text form. Defaults to `true`. */
7
+ timestamp?: boolean;
8
+ /** Apply ANSI colour to the level token in the text form. Defaults to `false`. */
9
+ colorize?: boolean;
10
+ }
2
11
  /**
3
12
  * Format a log entry for output in different formats.
4
13
  * @param entry - The log entry to format
5
14
  * @param format - Output format ('json' or 'text')
15
+ * @param options - Presentation options; they affect the text form only
6
16
  * @returns Formatted log string
7
17
  * @example
8
18
  * ```typescript
@@ -17,11 +27,14 @@ import { LogEntry, LogLevel } from '../core/types.cjs';
17
27
  * const textFormat = formatLogEntry(entry, 'text');
18
28
  * // Result: "[2024-01-01T12:00:00.000Z] INFO: User logged in {\"userId\":123}"
19
29
  *
30
+ * const bare = formatLogEntry(entry, 'text', { timestamp: false });
31
+ * // Result: "INFO: User logged in {\"userId\":123}"
32
+ *
20
33
  * const jsonFormat = formatLogEntry(entry, 'json');
21
34
  * // Result: {"timestamp":"2024-01-01T12:00:00.000Z","level":"info","message":"User logged in","metadata":{"userId":123},"runtime":"node"}
22
35
  * ```
23
36
  */
24
- export declare function formatLogEntry(entry: LogEntry, format?: 'json' | 'text'): string;
37
+ export declare function formatLogEntry(entry: LogEntry, format?: 'json' | 'text', options?: FormatOptions): string;
25
38
  /**
26
39
  * Format log level as a colored string for terminal output.
27
40
  * @param level - The log level to format