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.
- package/README.md +83 -7
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +20 -42
- package/dist/bun.cjs +1 -1
- package/dist/bun.d.cts +4 -1
- package/dist/bun.d.mts +4 -1
- package/dist/bun.d.ts +4 -1
- package/dist/bun.mjs +5 -4
- package/dist/chunks/{browser-D5QY2oJb.mjs → config-Db6PTLH2.mjs} +158 -23
- package/dist/chunks/config-PPDFSral.cjs +1 -0
- package/dist/chunks/config-file-37L8z8Lm.mjs +56 -0
- package/dist/chunks/config-file-Dvyi1e80.cjs +1 -0
- package/dist/chunks/factory-BPYE1-Nw.cjs +1 -0
- package/dist/chunks/factory-CXO2aNcc.mjs +169 -0
- package/dist/chunks/file-transport-DRyxQq8t.mjs +80 -0
- package/dist/chunks/file-transport-SA6KG1oM.cjs +1 -0
- package/dist/core/factory.d.cts +22 -0
- package/dist/core/factory.d.mts +22 -0
- package/dist/core/factory.d.ts +22 -0
- package/dist/core/transport.d.cts +73 -0
- package/dist/core/transport.d.mts +73 -0
- package/dist/core/transport.d.ts +73 -0
- package/dist/core/types.d.cts +9 -0
- package/dist/core/types.d.mts +9 -0
- package/dist/core/types.d.ts +9 -0
- package/dist/deno.cjs +1 -1
- package/dist/deno.d.cts +3 -1
- package/dist/deno.d.mts +3 -1
- package/dist/deno.d.ts +3 -1
- package/dist/deno.mjs +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +9 -9
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +3 -1
- package/dist/node.d.mts +3 -1
- package/dist/node.d.ts +3 -1
- package/dist/node.mjs +3 -2
- package/dist/runtime/file-transport.d.cts +62 -0
- package/dist/runtime/file-transport.d.mts +62 -0
- package/dist/runtime/file-transport.d.ts +62 -0
- package/dist/runtime/node.d.cts +39 -8
- package/dist/runtime/node.d.mts +39 -8
- package/dist/runtime/node.d.ts +39 -8
- package/dist/utils/config-file.d.cts +2 -0
- package/dist/utils/config-file.d.mts +2 -0
- package/dist/utils/config-file.d.ts +2 -0
- package/dist/utils/config.d.cts +33 -2
- package/dist/utils/config.d.mts +33 -2
- package/dist/utils/config.d.ts +33 -2
- package/dist/utils/formatting.d.cts +14 -1
- package/dist/utils/formatting.d.mts +14 -1
- package/dist/utils/formatting.d.ts +14 -1
- package/dist/utils/serialization.d.cts +30 -3
- package/dist/utils/serialization.d.mts +30 -3
- package/dist/utils/serialization.d.ts +30 -3
- package/package.json +3 -10
- package/dist/chunks/__vite-browser-external-BgoQtmXf.mjs +0 -7
- package/dist/chunks/__vite-browser-external-Bjj3r6ML.cjs +0 -1
- package/dist/chunks/browser-Bq67gUmd.cjs +0 -1
- package/dist/chunks/factory-2po65gyH.mjs +0 -262
- package/dist/chunks/factory-CluPoiZb.cjs +0 -1
- package/dist/chunks/formatting-CLctAPm9.mjs +0 -29
- package/dist/chunks/formatting-Cb_xXgov.cjs +0 -1
package/dist/deno.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
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/
|
|
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 {
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
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
|
|
6
|
-
debug: (e, t) =>
|
|
7
|
-
info: (e, t) =>
|
|
8
|
-
warn: (e, t) =>
|
|
9
|
-
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 {
|
|
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-
|
|
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
|
|
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
|
|
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
|
|
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 {
|
|
2
|
-
|
|
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
|
+
}
|
package/dist/runtime/node.d.cts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import { BaseLogger } from '../core/logger.cjs';
|
|
2
|
-
import {
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
};
|
package/dist/runtime/node.d.mts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import { BaseLogger } from '../core/logger.mjs';
|
|
2
|
-
import {
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
};
|
package/dist/runtime/node.d.ts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import { BaseLogger } from '../core/logger';
|
|
2
|
-
import {
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
};
|
package/dist/utils/config.d.cts
CHANGED
|
@@ -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;
|
package/dist/utils/config.d.mts
CHANGED
|
@@ -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;
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -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
|