@visulima/pail 3.0.3 → 3.2.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/CHANGELOG.md +47 -0
- package/LICENSE.md +18 -391
- package/README.md +578 -0
- package/dist/index.browser.d.ts +4 -3
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +19 -74
- package/dist/index.server.js +535 -5
- package/dist/interactive/index.d.ts +28 -0
- package/dist/interactive/index.js +2 -0
- package/dist/object-tree.d.ts +17 -0
- package/dist/object-tree.js +89 -0
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/{abstract-json-reporter-wUti0B3k.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +3 -3
- package/dist/packem_shared/{abstract-pretty-reporter-MOYolfGR.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/{pail.browser-Bs2ng_Qj.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
- package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
- package/dist/packem_shared/{types-RidvA4RN.d.ts → types-D3ycu8-x.d.ts} +2 -29
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/processor/caller/caller-processor.d.ts +2 -1
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/message-formatter-processor.d.ts +2 -1
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +19 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +2 -1
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +76 -0
- package/dist/progress-bar.js +404 -0
- package/dist/reporter/file/json-file-reporter.d.ts +3 -2
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +13 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/json/index.browser.d.ts +3 -2
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -2
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/pretty/index.browser.d.ts +3 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +3 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +3 -2
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/spinner.d.ts +154 -0
- package/dist/spinner.js +2150 -0
- package/package.json +69 -3
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-APmxUrnh.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-DqvZRRR6.js +0 -33
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/getBarChar-mKDZW32R.js +0 -1
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
package/dist/index.server.d.ts
CHANGED
|
@@ -1,74 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import '
|
|
1
|
+
import { InteractiveManager } from './interactive/index.js';
|
|
2
|
+
import { a as PailBrowserImpl } from './packem_shared/pail.browser-By9KjOH7.js';
|
|
3
|
+
import { SingleBarOptions, ProgressBar, MultiBarOptions, MultiProgressBar } from './progress-bar.js';
|
|
4
|
+
export { ProgressBarOptions, ProgressBarPayload, ProgressBarStyle, getBarChar } from './progress-bar.js';
|
|
5
|
+
import { SpinnerOptions, Spinner, MultiSpinner } from './spinner.js';
|
|
6
|
+
export { SpinnerIcons, SpinnerStartOptions, SpinnerStyle } from './spinner.js';
|
|
7
|
+
import { g as ServerConstructorOptions, C as ConstructorOptions, R as Reporter, a as DefaultLogTypes, b as LoggerFunction } from './packem_shared/types-D3ycu8-x.js';
|
|
8
|
+
export { D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, S as StreamAwareReporter } from './packem_shared/types-D3ycu8-x.js';
|
|
6
9
|
import './packem_shared/index.d-oxZvg_y7.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
interface ProgressBarOptions {
|
|
10
|
-
barCompleteChar?: string;
|
|
11
|
-
barGlue?: string;
|
|
12
|
-
barIncompleteChar?: string;
|
|
13
|
-
barsize?: number;
|
|
14
|
-
clear?: boolean;
|
|
15
|
-
current?: number;
|
|
16
|
-
etaBuffer?: number;
|
|
17
|
-
format?: string;
|
|
18
|
-
fps?: number;
|
|
19
|
-
hideCursor?: boolean;
|
|
20
|
-
lineWrap?: boolean;
|
|
21
|
-
position?: "left" | "right" | "center";
|
|
22
|
-
stream?: NodeJS.WriteStream;
|
|
23
|
-
style?: ProgressBarStyle;
|
|
24
|
-
total: number;
|
|
25
|
-
width?: number;
|
|
26
|
-
}
|
|
27
|
-
interface SingleBarOptions extends ProgressBarOptions {
|
|
28
|
-
format?: string;
|
|
29
|
-
}
|
|
30
|
-
interface MultiBarOptions {
|
|
31
|
-
barCompleteChar?: string;
|
|
32
|
-
barGlue?: string;
|
|
33
|
-
barIncompleteChar?: string;
|
|
34
|
-
clearOnComplete?: boolean;
|
|
35
|
-
format?: string;
|
|
36
|
-
fps?: number;
|
|
37
|
-
hideCursor?: boolean;
|
|
38
|
-
stream?: NodeJS.WriteStream;
|
|
39
|
-
style?: ProgressBarStyle;
|
|
40
|
-
}
|
|
41
|
-
interface ProgressBarPayload {
|
|
42
|
-
[key: string]: string | number | boolean;
|
|
43
|
-
}
|
|
44
|
-
declare const getBarChar: (char: string | undefined, style: ProgressBarStyle, complete?: boolean) => string;
|
|
45
|
-
declare class ProgressBar {
|
|
46
|
-
private options;
|
|
47
|
-
private current;
|
|
48
|
-
private startTime;
|
|
49
|
-
private interactiveManager?;
|
|
50
|
-
private isActive;
|
|
51
|
-
private payload?;
|
|
52
|
-
constructor(options: ProgressBarOptions, interactiveManager?: InteractiveManager, payload?: ProgressBarPayload);
|
|
53
|
-
update(current: number, payload?: ProgressBarPayload): void;
|
|
54
|
-
increment(step?: number, payload?: ProgressBarPayload): void;
|
|
55
|
-
render(): string;
|
|
56
|
-
start(total?: number, startValue?: number, payload?: ProgressBarPayload): void;
|
|
57
|
-
stop(): void;
|
|
58
|
-
private calculateETA;
|
|
59
|
-
}
|
|
60
|
-
declare class MultiProgressBar {
|
|
61
|
-
private bars;
|
|
62
|
-
private options;
|
|
63
|
-
private interactiveManager?;
|
|
64
|
-
private isActive;
|
|
65
|
-
private nextBarId;
|
|
66
|
-
constructor(options?: MultiBarOptions, interactiveManager?: InteractiveManager);
|
|
67
|
-
create(total: number, startValue?: number, payload?: ProgressBarPayload): ProgressBar;
|
|
68
|
-
remove(bar: ProgressBar): boolean;
|
|
69
|
-
renderAll(): void;
|
|
70
|
-
stop(): void;
|
|
71
|
-
}
|
|
10
|
+
import 'type-fest';
|
|
11
|
+
import '@visulima/colorize';
|
|
72
12
|
|
|
73
13
|
declare class PailServerImpl<T extends string = string, L extends string = string> extends PailBrowserImpl<T, L> {
|
|
74
14
|
#private;
|
|
@@ -79,6 +19,7 @@ declare class PailServerImpl<T extends string = string, L extends string = strin
|
|
|
79
19
|
protected readonly interactive: boolean;
|
|
80
20
|
constructor(options: ServerConstructorOptions<T, L>);
|
|
81
21
|
scope<N extends string = T>(...name: string[]): PailServerType<N, L>;
|
|
22
|
+
child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>> & Partial<Pick<ServerConstructorOptions<N, LC>, "interactive" | "stderr" | "stdout">>): PailServerType<N, LC>;
|
|
82
23
|
getInteractiveManager(): InteractiveManager | undefined;
|
|
83
24
|
wrapStd(): void;
|
|
84
25
|
restoreStd(): void;
|
|
@@ -86,13 +27,17 @@ declare class PailServerImpl<T extends string = string, L extends string = strin
|
|
|
86
27
|
restoreAll(): void;
|
|
87
28
|
createProgressBar(options: SingleBarOptions): ProgressBar;
|
|
88
29
|
createMultiProgressBar(options?: MultiBarOptions): MultiProgressBar;
|
|
30
|
+
createSpinner(options?: SpinnerOptions): Spinner;
|
|
31
|
+
createMultiSpinner(options?: SpinnerOptions): MultiSpinner;
|
|
89
32
|
clear(): void;
|
|
90
33
|
protected extendReporter(reporter: Reporter<L>): Reporter<L>;
|
|
91
34
|
}
|
|
92
|
-
type PailServerType<T extends string = string, L extends string = string> = (new <TC extends string = string, LC extends string = string>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>) & PailServerImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction
|
|
35
|
+
type PailServerType<T extends string = string, L extends string = string> = Console & (new <TC extends string = string, LC extends string = string>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>) & PailServerImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & {
|
|
36
|
+
force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
|
|
37
|
+
};
|
|
93
38
|
|
|
94
|
-
declare const createPail: <T extends string = string, L extends string = string>(options?:
|
|
39
|
+
declare const createPail: <T extends string = string, L extends string = string>(options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;
|
|
95
40
|
declare const pail: PailServerType<string, string>;
|
|
96
41
|
|
|
97
|
-
export { ConstructorOptions, DefaultLogTypes, LoggerFunction, MultiProgressBar, ProgressBar, Reporter,
|
|
98
|
-
export type {
|
|
42
|
+
export { ConstructorOptions, DefaultLogTypes, LoggerFunction, MultiBarOptions, MultiProgressBar, MultiSpinner, ProgressBar, Reporter, SingleBarOptions, Spinner, SpinnerOptions, createPail, pail };
|
|
43
|
+
export type { PailServerType as Pail };
|
package/dist/index.server.js
CHANGED
|
@@ -1,5 +1,535 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
stdout,
|
|
9
|
+
stderr,
|
|
10
|
+
env
|
|
11
|
+
} = __cjs_getProcess;
|
|
12
|
+
import InteractiveManager from './packem_shared/InteractiveManager-CZ85hGNW.js';
|
|
13
|
+
import { I as InteractiveStreamHook, c as clearTerminal } from './packem_shared/interactive-stream-hook-DG4BtN12.js';
|
|
14
|
+
import { a as PailBrowserImpl, m as mergeTypes, b as arrayify } from './packem_shared/pail.browser-CPDOE_d1.js';
|
|
15
|
+
import { ProgressBar, applyStyleToOptions, MultiProgressBar } from './progress-bar.js';
|
|
16
|
+
export { getBarChar } from './progress-bar.js';
|
|
17
|
+
import { i as inspect } from './packem_shared/format-label-Btft2KGP.js';
|
|
18
|
+
import { E as EMPTY_SYMBOL } from './packem_shared/constants-DfDr4MHC.js';
|
|
19
|
+
import { w as writeStream } from './packem_shared/write-stream-BG8fhcs3.js';
|
|
20
|
+
import { Spinner, MultiSpinner } from './spinner.js';
|
|
21
|
+
import { g as getLongestLabel } from './packem_shared/get-longest-label-C9PWeyKq.js';
|
|
22
|
+
import MessageFormatterProcessor from './processor/message-formatter-processor.js';
|
|
23
|
+
import { PrettyReporter } from './packem_shared/PrettyReporter-BFWaYP_J.js';
|
|
24
|
+
|
|
25
|
+
class RawReporter {
|
|
26
|
+
#stdout;
|
|
27
|
+
#stderr;
|
|
28
|
+
#interactiveManager;
|
|
29
|
+
#interactive = false;
|
|
30
|
+
#inspectOptions;
|
|
31
|
+
constructor(inspectOptions = {}) {
|
|
32
|
+
this.#stdout = stdout;
|
|
33
|
+
this.#stderr = stderr;
|
|
34
|
+
this.#inspectOptions = inspectOptions;
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
37
|
+
setStdout(stdout_) {
|
|
38
|
+
this.#stdout = stdout_;
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
41
|
+
setStderr(stderr_) {
|
|
42
|
+
this.#stderr = stderr_;
|
|
43
|
+
}
|
|
44
|
+
setInteractiveManager(manager) {
|
|
45
|
+
this.#interactiveManager = manager;
|
|
46
|
+
}
|
|
47
|
+
setIsInteractive(interactive) {
|
|
48
|
+
this.#interactive = interactive;
|
|
49
|
+
}
|
|
50
|
+
log(meta) {
|
|
51
|
+
const { context, groups, message, type } = meta;
|
|
52
|
+
const items = [];
|
|
53
|
+
if (message !== EMPTY_SYMBOL) {
|
|
54
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
55
|
+
items.push(formattedMessage);
|
|
56
|
+
}
|
|
57
|
+
if (context) {
|
|
58
|
+
items.push(
|
|
59
|
+
...context.map((value) => {
|
|
60
|
+
if (typeof value === "object") {
|
|
61
|
+
return ` ${inspect(value, this.#inspectOptions)}`;
|
|
62
|
+
}
|
|
63
|
+
return ` ${value}`;
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const streamType = ["error", "trace", "warn"].includes(type.level) ? "stderr" : "stdout";
|
|
68
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
69
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
70
|
+
if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
|
|
71
|
+
this.#interactiveManager.update(streamType, (groupSpaces + items.join("")).split("\n"), 0);
|
|
72
|
+
} else {
|
|
73
|
+
writeStream(groupSpaces + items.join(""), stream);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class PailServerImpl extends PailBrowserImpl {
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new Pail server logger instance.
|
|
81
|
+
*
|
|
82
|
+
* Initializes the server-compatible logger with streams, interactive support,
|
|
83
|
+
* and server-specific configuration options.
|
|
84
|
+
* @param options Server-specific configuration options
|
|
85
|
+
*/
|
|
86
|
+
constructor(options) {
|
|
87
|
+
const parentStderr = options.parentStderr;
|
|
88
|
+
const parentStdout = options.parentStdout;
|
|
89
|
+
const { interactive, processors, rawReporter, reporters, stderr: optionsStderr, stdout: optionsStdout } = options;
|
|
90
|
+
const stderr = parentStderr ?? optionsStderr;
|
|
91
|
+
const stdout = parentStdout ?? optionsStdout;
|
|
92
|
+
const parentLongestLabel = options.parentLongestLabel;
|
|
93
|
+
const parentTypes = options.parentTypes;
|
|
94
|
+
const { parentLogLevels, parentMessages, parentStringify } = options;
|
|
95
|
+
const parentOptions = {
|
|
96
|
+
disabled: options.disabled,
|
|
97
|
+
logLevel: options.logLevel,
|
|
98
|
+
logLevels: options.logLevels,
|
|
99
|
+
messages: options.messages,
|
|
100
|
+
processors: [],
|
|
101
|
+
rawReporter: options.rawReporter,
|
|
102
|
+
reporters: [],
|
|
103
|
+
scope: options.scope,
|
|
104
|
+
throttle: options.throttle,
|
|
105
|
+
throttleMin: options.throttleMin
|
|
106
|
+
};
|
|
107
|
+
const hasTypesProperty = "types" in options;
|
|
108
|
+
if (parentTypes && parentLongestLabel && !hasTypesProperty) {
|
|
109
|
+
parentOptions.parentTypes = parentTypes;
|
|
110
|
+
parentOptions.parentLongestLabel = parentLongestLabel;
|
|
111
|
+
} else if (hasTypesProperty && options.types !== void 0) {
|
|
112
|
+
parentOptions.types = options.types;
|
|
113
|
+
}
|
|
114
|
+
if (parentStringify) {
|
|
115
|
+
parentOptions.parentStringify = parentStringify;
|
|
116
|
+
}
|
|
117
|
+
if (parentLogLevels && !options.logLevels) {
|
|
118
|
+
parentOptions.parentLogLevels = parentLogLevels;
|
|
119
|
+
}
|
|
120
|
+
if (parentMessages && !options.messages) {
|
|
121
|
+
parentOptions.parentMessages = parentMessages;
|
|
122
|
+
}
|
|
123
|
+
super(parentOptions);
|
|
124
|
+
this.options = options;
|
|
125
|
+
this.interactive = interactive ?? false;
|
|
126
|
+
this.stdout = stdout;
|
|
127
|
+
this.stderr = stderr;
|
|
128
|
+
if (this.interactive) {
|
|
129
|
+
this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(reporters)) {
|
|
132
|
+
this.registerReporters(reporters);
|
|
133
|
+
}
|
|
134
|
+
this.rawReporter = this.extendReporter(rawReporter ?? new RawReporter());
|
|
135
|
+
if (Array.isArray(processors)) {
|
|
136
|
+
this.registerProcessors(processors);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
stdout;
|
|
140
|
+
stderr;
|
|
141
|
+
interactiveManager;
|
|
142
|
+
interactive;
|
|
143
|
+
// @ts-expect-error - this returns a different type
|
|
144
|
+
scope(...name) {
|
|
145
|
+
if (name.length === 0) {
|
|
146
|
+
throw new Error("No scope name was defined.");
|
|
147
|
+
}
|
|
148
|
+
this.scopeName = name.flat();
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a child logger that inherits settings from the parent.
|
|
153
|
+
*
|
|
154
|
+
* Returns a new logger instance that inherits all configuration from the parent
|
|
155
|
+
* (reporters, processors, types, log levels, throttle settings, etc.) while allowing
|
|
156
|
+
* you to override only what you need. Child loggers are independent instances with
|
|
157
|
+
* their own state (timers, counters, etc.).
|
|
158
|
+
* @template N - The new custom logger type names
|
|
159
|
+
* @template LC - The new log level types
|
|
160
|
+
* @param options Configuration options to override or extend parent settings
|
|
161
|
+
* @returns A new child logger instance
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const parent = createPail({
|
|
165
|
+
* logLevel: "info",
|
|
166
|
+
* types: { http: { label: "HTTP", logLevel: "info" } },
|
|
167
|
+
* reporters: [new PrettyReporter()],
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // Child inherits parent settings but overrides log level
|
|
171
|
+
* const child = parent.child({ logLevel: "debug" });
|
|
172
|
+
* child.info("This will be logged"); // Uses debug level from child
|
|
173
|
+
* child.http("GET /api 200"); // Inherits http type from parent
|
|
174
|
+
*
|
|
175
|
+
* // Child can add new types
|
|
176
|
+
* const childWithNewType = parent.child({
|
|
177
|
+
* types: { db: { label: "DB", logLevel: "info" } },
|
|
178
|
+
* });
|
|
179
|
+
* childWithNewType.db("Query executed"); // New type available
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
// @ts-expect-error - override signature differs due to server-specific options
|
|
183
|
+
child(options) {
|
|
184
|
+
const typesChanged = options?.types !== void 0 && options.types !== null;
|
|
185
|
+
const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
|
|
186
|
+
const childReporters = options?.reporters ?? [];
|
|
187
|
+
const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
|
|
188
|
+
const childProcessors = options?.processors ?? [];
|
|
189
|
+
const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
|
|
190
|
+
const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
|
|
191
|
+
let mergedScope;
|
|
192
|
+
if (options?.scope) {
|
|
193
|
+
const childScope = arrayify(options.scope).filter(Boolean);
|
|
194
|
+
mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
|
|
195
|
+
} else {
|
|
196
|
+
mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
|
|
197
|
+
}
|
|
198
|
+
const mergedMessages = options?.messages ? {
|
|
199
|
+
timerEnd: this.endTimerMessage,
|
|
200
|
+
timerStart: this.startTimerMessage,
|
|
201
|
+
...options.messages
|
|
202
|
+
} : {
|
|
203
|
+
timerEnd: this.endTimerMessage,
|
|
204
|
+
timerStart: this.startTimerMessage
|
|
205
|
+
};
|
|
206
|
+
const childOptions = {
|
|
207
|
+
disabled: options?.disabled ?? this.disabled,
|
|
208
|
+
interactive: options?.interactive ?? this.interactive,
|
|
209
|
+
logLevel: options?.logLevel ?? this.generalLogLevel,
|
|
210
|
+
logLevels: mergedLogLevels,
|
|
211
|
+
messages: mergedMessages,
|
|
212
|
+
processors: allProcessors,
|
|
213
|
+
rawReporter: options?.rawReporter ?? this.rawReporter,
|
|
214
|
+
reporters: allReporters,
|
|
215
|
+
scope: mergedScope,
|
|
216
|
+
stderr: options?.stderr ?? this.stderr,
|
|
217
|
+
stdout: options?.stdout ?? this.stdout,
|
|
218
|
+
throttle: options?.throttle ?? this.throttle,
|
|
219
|
+
throttleMin: options?.throttleMin ?? this.throttleMin
|
|
220
|
+
};
|
|
221
|
+
this.#assignParentValues(childOptions, options, typesChanged, mergedTypes);
|
|
222
|
+
return new PailServerImpl(childOptions);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Assigns parent values to child options for optimization.
|
|
226
|
+
*
|
|
227
|
+
* Reuses parent values when they haven't changed to avoid unnecessary recalculations.
|
|
228
|
+
*/
|
|
229
|
+
/* eslint-disable no-param-reassign */
|
|
230
|
+
#assignParentValues(childOptions, options, typesChanged, mergedTypes) {
|
|
231
|
+
if (typesChanged) {
|
|
232
|
+
childOptions.parentTypes = mergedTypes;
|
|
233
|
+
childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
|
|
234
|
+
} else {
|
|
235
|
+
childOptions.parentTypes = this.types;
|
|
236
|
+
childOptions.parentLongestLabel = this.longestLabel;
|
|
237
|
+
}
|
|
238
|
+
if (!options?.logLevels) {
|
|
239
|
+
childOptions.parentLogLevels = this.logLevels;
|
|
240
|
+
}
|
|
241
|
+
if (!options?.messages) {
|
|
242
|
+
childOptions.parentMessages = {
|
|
243
|
+
timerEnd: this.endTimerMessage,
|
|
244
|
+
timerStart: this.startTimerMessage
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
childOptions.parentStringify = this.stringify;
|
|
248
|
+
if (!options?.stdout) {
|
|
249
|
+
childOptions.parentStdout = this.stdout;
|
|
250
|
+
}
|
|
251
|
+
if (!options?.stderr) {
|
|
252
|
+
childOptions.parentStderr = this.stderr;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/* eslint-enable no-param-reassign */
|
|
256
|
+
/**
|
|
257
|
+
* Gets the interactive manager instance if interactive mode is enabled.
|
|
258
|
+
*
|
|
259
|
+
* Returns the InteractiveManager instance that handles interactive terminal
|
|
260
|
+
* features like progress bars and dynamic updates. Only available when
|
|
261
|
+
* interactive mode is enabled in the constructor options.
|
|
262
|
+
* @returns The interactive manager instance, or undefined if not in interactive mode
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const logger = createPail({ interactive: true });
|
|
266
|
+
* const manager = logger.getInteractiveManager();
|
|
267
|
+
* if (manager) {
|
|
268
|
+
* manager.hook();
|
|
269
|
+
* // Use interactive features
|
|
270
|
+
* manager.unhook();
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
getInteractiveManager() {
|
|
275
|
+
return this.interactiveManager;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Wraps stdout and stderr streams to redirect them through the logger.
|
|
279
|
+
*
|
|
280
|
+
* Intercepts writes to process.stdout and process.stderr, redirecting them
|
|
281
|
+
* through the logger instead of writing directly to the streams. This allows
|
|
282
|
+
* all output to be processed by the logging pipeline.
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const logger = createPail();
|
|
286
|
+
* logger.wrapStd();
|
|
287
|
+
*
|
|
288
|
+
* console.log("This goes through logger");
|
|
289
|
+
* process.stdout.write("This too");
|
|
290
|
+
*
|
|
291
|
+
* logger.restoreStd(); // Restore original streams
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
wrapStd() {
|
|
295
|
+
this.#wrapStream(this.stdout, "log");
|
|
296
|
+
this.#wrapStream(this.stderr, "log");
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Restores the original stdout and stderr streams.
|
|
300
|
+
*
|
|
301
|
+
* Removes the stream wrapping that was applied by wrapStd(),
|
|
302
|
+
* restoring the original stream write methods.
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const logger = createPail();
|
|
306
|
+
* logger.wrapStd();
|
|
307
|
+
* // Streams are wrapped
|
|
308
|
+
* logger.restoreStd();
|
|
309
|
+
* // Streams are restored to original behavior
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
restoreStd() {
|
|
313
|
+
this.#restoreStream(this.stdout);
|
|
314
|
+
this.#restoreStream(this.stderr);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Wraps all output sources (console and streams).
|
|
318
|
+
*
|
|
319
|
+
* Convenience method that calls both wrapConsole() and wrapStd()
|
|
320
|
+
* to redirect all output through the logger.
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const logger = createPail();
|
|
324
|
+
* logger.wrapAll(); // Wraps console and streams
|
|
325
|
+
*
|
|
326
|
+
* // All output now goes through logger
|
|
327
|
+
* console.log("Console output");
|
|
328
|
+
* process.stdout.write("Stream output");
|
|
329
|
+
*
|
|
330
|
+
* logger.restoreAll(); // Restore everything
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
wrapAll() {
|
|
334
|
+
this.wrapConsole();
|
|
335
|
+
this.wrapStd();
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Restores all wrapped output sources.
|
|
339
|
+
*
|
|
340
|
+
* Convenience method that calls both restoreConsole() and restoreStd()
|
|
341
|
+
* to restore all original output behavior.
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const logger = createPail();
|
|
345
|
+
* logger.wrapAll();
|
|
346
|
+
* // All output is wrapped
|
|
347
|
+
* logger.restoreAll();
|
|
348
|
+
* // All output sources are restored
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
restoreAll() {
|
|
352
|
+
this.restoreConsole();
|
|
353
|
+
this.restoreStd();
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Creates a single progress bar.
|
|
357
|
+
* @param options Configuration options for the progress bar
|
|
358
|
+
* @returns A new ProgressBar instance
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const logger = createPail({ interactive: true });
|
|
362
|
+
* const bar = logger.createProgressBar({
|
|
363
|
+
* total: 100,
|
|
364
|
+
* format: 'Downloading [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}'
|
|
365
|
+
* });
|
|
366
|
+
*
|
|
367
|
+
* bar.start();
|
|
368
|
+
* // ... do work and update progress
|
|
369
|
+
* bar.update(50);
|
|
370
|
+
* bar.stop();
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
createProgressBar(options) {
|
|
374
|
+
if (!this.interactiveManager) {
|
|
375
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
|
|
376
|
+
}
|
|
377
|
+
const styledOptions = applyStyleToOptions(options);
|
|
378
|
+
return new ProgressBar(styledOptions, this.interactiveManager);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Creates a multi-bar progress manager for displaying multiple progress bars.
|
|
382
|
+
* @param options Configuration options for the multi-bar manager
|
|
383
|
+
* @returns A new MultiProgressBar instance
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const logger = createPail({ interactive: true });
|
|
387
|
+
* const multiBar = logger.createMultiProgressBar();
|
|
388
|
+
*
|
|
389
|
+
* const bar1 = multiBar.create(100);
|
|
390
|
+
* const bar2 = multiBar.create(200);
|
|
391
|
+
*
|
|
392
|
+
* bar1.start();
|
|
393
|
+
* bar2.start();
|
|
394
|
+
* // ... update bars as needed
|
|
395
|
+
* multiBar.stop();
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
createMultiProgressBar(options = {}) {
|
|
399
|
+
if (!this.interactiveManager) {
|
|
400
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
|
|
401
|
+
}
|
|
402
|
+
const styledOptions = applyStyleToOptions(options);
|
|
403
|
+
return new MultiProgressBar(styledOptions, this.interactiveManager);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Creates a single spinner.
|
|
407
|
+
* @param options Configuration options for the spinner
|
|
408
|
+
* @returns A new Spinner instance
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const logger = createPail({ interactive: true });
|
|
412
|
+
* const spinner = logger.createSpinner({ name: 'dots' });
|
|
413
|
+
* spinner.start('Loading...');
|
|
414
|
+
* // ... do work
|
|
415
|
+
* spinner.succeed('Done');
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
createSpinner(options = {}) {
|
|
419
|
+
if (!this.interactiveManager) {
|
|
420
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
|
|
421
|
+
}
|
|
422
|
+
return new Spinner(options, this.interactiveManager);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Creates a multi-spinner manager for displaying multiple spinners.
|
|
426
|
+
* @param options Configuration options for the multi-spinner manager
|
|
427
|
+
* @returns A new MultiSpinner instance
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const logger = createPail({ interactive: true });
|
|
431
|
+
* const multiSpinner = logger.createMultiSpinner();
|
|
432
|
+
*
|
|
433
|
+
* const spinner1 = multiSpinner.create('Loading 1');
|
|
434
|
+
* const spinner2 = multiSpinner.create('Loading 2');
|
|
435
|
+
*
|
|
436
|
+
* spinner1.start();
|
|
437
|
+
* spinner2.start();
|
|
438
|
+
* // ... update spinners as needed
|
|
439
|
+
* multiSpinner.stop();
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
createMultiSpinner(options = {}) {
|
|
443
|
+
if (!this.interactiveManager) {
|
|
444
|
+
throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
|
|
445
|
+
}
|
|
446
|
+
return new MultiSpinner(options, this.interactiveManager);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Clears the terminal screen.
|
|
450
|
+
*
|
|
451
|
+
* Sends ANSI escape sequences to clear the terminal screen and move
|
|
452
|
+
* the cursor to the top-left position. This overrides the browser
|
|
453
|
+
* implementation to work with terminal streams.
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const logger = createPail();
|
|
457
|
+
* logger.info("Some output");
|
|
458
|
+
* logger.clear(); // Clears the terminal screen
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
clear() {
|
|
462
|
+
this.stdout.write(clearTerminal);
|
|
463
|
+
this.stderr.write(clearTerminal);
|
|
464
|
+
}
|
|
465
|
+
extendReporter(reporter) {
|
|
466
|
+
if (typeof reporter.setStdout === "function") {
|
|
467
|
+
reporter.setStdout(this.stdout);
|
|
468
|
+
}
|
|
469
|
+
if (typeof reporter.setStderr === "function") {
|
|
470
|
+
reporter.setStderr(this.stderr);
|
|
471
|
+
}
|
|
472
|
+
if (typeof reporter.setLoggerTypes === "function") {
|
|
473
|
+
reporter.setLoggerTypes(this.types);
|
|
474
|
+
}
|
|
475
|
+
if (typeof reporter.setStringify === "function") {
|
|
476
|
+
reporter.setStringify(this.stringify);
|
|
477
|
+
}
|
|
478
|
+
if (typeof reporter.setIsInteractive === "function") {
|
|
479
|
+
reporter.setIsInteractive(this.interactive);
|
|
480
|
+
}
|
|
481
|
+
if (this.interactive && typeof reporter.setInteractiveManager === "function") {
|
|
482
|
+
reporter.setInteractiveManager(this.interactiveManager);
|
|
483
|
+
}
|
|
484
|
+
return reporter;
|
|
485
|
+
}
|
|
486
|
+
#wrapStream(stream, type) {
|
|
487
|
+
if (!stream) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (!stream.__write) {
|
|
491
|
+
stream.__write = stream.write;
|
|
492
|
+
}
|
|
493
|
+
stream.write = (data) => {
|
|
494
|
+
this[type](String(data).trim());
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
// eslint-disable-next-line class-methods-use-this
|
|
498
|
+
#restoreStream(stream) {
|
|
499
|
+
if (!stream) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (stream.__write) {
|
|
503
|
+
stream.write = stream.__write;
|
|
504
|
+
delete stream.__write;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const PailServer = PailServerImpl;
|
|
509
|
+
|
|
510
|
+
const getDefaultLogLevel = () => {
|
|
511
|
+
if (env.NODE_ENV === "debug" || env.DEBUG !== void 0) {
|
|
512
|
+
return "debug";
|
|
513
|
+
}
|
|
514
|
+
if (env.NODE_ENV === "test") {
|
|
515
|
+
return "warning";
|
|
516
|
+
}
|
|
517
|
+
return "informational";
|
|
518
|
+
};
|
|
519
|
+
const createPail = (options) => {
|
|
520
|
+
let logLevel = getDefaultLogLevel();
|
|
521
|
+
if (env.PAIL_LOG_LEVEL !== void 0) {
|
|
522
|
+
logLevel = env.PAIL_LOG_LEVEL;
|
|
523
|
+
}
|
|
524
|
+
return new PailServer({
|
|
525
|
+
logLevel,
|
|
526
|
+
processors: [new MessageFormatterProcessor()],
|
|
527
|
+
reporters: [new PrettyReporter()],
|
|
528
|
+
stderr,
|
|
529
|
+
stdout,
|
|
530
|
+
...options
|
|
531
|
+
});
|
|
532
|
+
};
|
|
533
|
+
const pail = createPail();
|
|
534
|
+
|
|
535
|
+
export { MultiProgressBar, MultiSpinner, ProgressBar, Spinner, createPail, pail };
|