@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.13
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 +33 -0
- package/LICENSE.md +131 -900
- package/dist/error.d.ts +95 -96
- package/dist/error.js +5 -76
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +19 -1499
- package/dist/index.server.d.ts +722 -61
- package/dist/index.server.js +31 -2803
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +1 -70
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -29
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +1 -46
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/hono.js +1 -33
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/next/handler.js +1 -53
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/middleware/sveltekit.js +1 -43
- package/dist/object-tree.d.ts +67 -70
- package/dist/object-tree.js +2 -89
- package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
- package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
- package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
- package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
- package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
- package/dist/packem_shared/abstract-json-reporter.d-Bz3lZEDi.d.ts +61 -0
- package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.js +33 -0
- package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
- package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
- package/dist/packem_shared/create-middleware-logger.d-DeNLii5l.d.ts +47 -0
- package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
- package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
- package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
- package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
- package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
- package/dist/packem_shared/types.d-ByY2ZuYG.d.ts +246 -0
- package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
- package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
- package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
- package/dist/packem_shared/wide-event.d-Ke44zirU.d.ts +704 -0
- package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
- package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/caller/caller-processor.js +1 -59
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/environment-processor.js +1 -89
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +1 -715
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/opentelemetry-processor.js +1 -52
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/redact-processor.js +1 -31
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/processor/sampling-processor.js +1 -59
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +2 -136
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +2 -432
- package/dist/reporter/http/http-reporter.d.ts +40 -36
- package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
- package/dist/reporter/http/http-reporter.edge-light.js +2 -728
- package/dist/reporter/http/http-reporter.js +1 -13
- package/dist/reporter/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +1 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +1 -2
- package/dist/reporter/pretty/index.browser.d.ts +106 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +186 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
- package/dist/reporter/simple/simple-reporter.server.js +8 -182
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +1 -284
- package/package.json +29 -30
- package/dist/constants.d.ts +0 -37
- package/dist/middleware/next/middleware.d.ts +0 -59
- package/dist/middleware/next/storage.d.ts +0 -14
- package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
- package/dist/middleware/shared/headers.d.ts +0 -14
- package/dist/middleware/shared/routes.d.ts +0 -30
- package/dist/middleware/shared/storage.d.ts +0 -29
- package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
- package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
- package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
- package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +0 -2720
- package/dist/packem_shared/PrettyReporter-BtTr13Ha.js +0 -213
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +0 -2635
- package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
- package/dist/packem_shared/constants-omsTHUWB.js +0 -119
- package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
- package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
- package/dist/packem_shared/index-Bx3-C0j9.js +0 -658
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
- package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
- package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
- package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
- package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -158
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
- package/dist/reporter/http/utils/compression.d.ts +0 -7
- package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
- package/dist/reporter/http/utils/retry.d.ts +0 -27
- package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
- package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
- package/dist/reporter/json/json-reporter.server.d.ts +0 -50
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
- package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
- package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
- package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
- package/dist/reporter/utils/format-label.d.ts +0 -3
- package/dist/types.d.ts +0 -241
- package/dist/utils/arrayify.d.ts +0 -2
- package/dist/utils/get-longest-badge.d.ts +0 -4
- package/dist/utils/get-longest-label.d.ts +0 -4
- package/dist/utils/merge-types.d.ts +0 -4
- package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
- package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
- package/dist/utils/write-stream.d.ts +0 -2
|
@@ -1,46 +1,95 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Options } from 'rotating-file-stream';
|
|
2
|
+
import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-Bz3lZEDi.js";
|
|
3
|
+
import 'safe-stable-stringify';
|
|
4
|
+
import "../../packem_shared/types.d-ByY2ZuYG.js";
|
|
5
|
+
import '@visulima/colorize';
|
|
6
|
+
import '@visulima/interactive-manager';
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
* Rotating File Stream.
|
|
9
|
+
*
|
|
10
|
+
* A wrapper for the `rotating-file-stream` module that provides optional immediate
|
|
11
|
+
* writing to disk by creating and closing a new stream on each write operation.
|
|
12
|
+
* This is useful for ensuring log messages are written immediately rather than buffered.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Buffered writing (default)
|
|
16
|
+
* const bufferedStream = new RotatingFileStream("/var/log/app.log", false, {
|
|
17
|
+
* interval: "1d",
|
|
18
|
+
* size: "10M"
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Immediate writing
|
|
22
|
+
* const immediateStream = new RotatingFileStream("/var/log/app.log", true, {
|
|
23
|
+
* interval: "1d"
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare class RotatingFileStream {
|
|
28
|
+
#private;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new RotatingFileStream instance.
|
|
31
|
+
* @param filePath Path to the log file
|
|
32
|
+
* @param writeImmediately Whether to write immediately or buffer writes
|
|
33
|
+
* @param options Options for the rotating file stream
|
|
34
|
+
* @throws {Error} If the 'rotating-file-stream' package is not installed
|
|
35
|
+
*/
|
|
36
|
+
constructor(filePath: string, writeImmediately?: boolean, options?: Options);
|
|
37
|
+
/**
|
|
38
|
+
* Writes a message to the rotating file stream.
|
|
39
|
+
*
|
|
40
|
+
* If writeImmediately was set to true in the constructor, a new stream
|
|
41
|
+
* is created for each write operation. Otherwise, uses the buffered stream.
|
|
42
|
+
* @param message The message to write to the file
|
|
43
|
+
*/
|
|
44
|
+
write(message: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Ends the rotating file stream.
|
|
47
|
+
*
|
|
48
|
+
* Closes the underlying stream. When `writeImmediately` is not `true`,
|
|
49
|
+
* calling `write` after calling this method will throw an error.
|
|
50
|
+
*/
|
|
51
|
+
end(): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for configuring the JsonFileReporter.
|
|
55
|
+
*/
|
|
56
|
+
type FileReporterOptions = AbstractJsonReporterOptions & Options & {
|
|
57
|
+
/** Path to the log file */
|
|
58
|
+
filePath: string;
|
|
59
|
+
/** Whether to write immediately to disk instead of buffering */
|
|
60
|
+
writeImmediately?: boolean;
|
|
13
61
|
};
|
|
14
62
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
* JSON File Reporter.
|
|
64
|
+
*
|
|
65
|
+
* A reporter that writes structured JSON log entries to rotating files on disk.
|
|
66
|
+
* Supports automatic file rotation based on size, time intervals, and compression.
|
|
67
|
+
* @template L - The log level type
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const reporter = new JsonFileReporter({
|
|
71
|
+
* filePath: "/var/log/app.log",
|
|
72
|
+
* interval: "1d", // Rotate daily
|
|
73
|
+
* size: "10M", // Rotate when file reaches 10MB
|
|
74
|
+
* compress: "gzip"
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* logger.registerReporters([reporter]);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare class JsonFileReporter<L extends string = string> extends AbstractJsonReporter<L> {
|
|
81
|
+
/** The rotating file stream instance */
|
|
82
|
+
protected stream: RotatingFileStream;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new JsonFileReporter instance.
|
|
85
|
+
* @param options Configuration options for file rotation and JSON formatting
|
|
86
|
+
*/
|
|
87
|
+
constructor(options: FileReporterOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Writes a JSON message to the rotating file stream.
|
|
90
|
+
* @param message The JSON-formatted log message to write
|
|
91
|
+
* @protected
|
|
92
|
+
*/
|
|
93
|
+
protected override _log(message: string): void;
|
|
46
94
|
}
|
|
95
|
+
export { FileReporterOptions, JsonFileReporter };
|
|
@@ -1,136 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class SafeStreamHandler {
|
|
4
|
-
#ready = true;
|
|
5
|
-
#stream;
|
|
6
|
-
#name;
|
|
7
|
-
constructor(stream, name) {
|
|
8
|
-
this.#stream = stream;
|
|
9
|
-
this.#name = name;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Writes `message` to the instance's internal stream.
|
|
13
|
-
* @param message Message to write
|
|
14
|
-
*/
|
|
15
|
-
write(message) {
|
|
16
|
-
this.writeStream(message);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Calls `end` on this instance's internal stream
|
|
20
|
-
*/
|
|
21
|
-
end(...arguments_) {
|
|
22
|
-
this.#stream.end(...arguments_);
|
|
23
|
-
}
|
|
24
|
-
get isReady() {
|
|
25
|
-
return this.#ready;
|
|
26
|
-
}
|
|
27
|
-
writeStream(message) {
|
|
28
|
-
if (!this.#ready) {
|
|
29
|
-
console.warn(`Stream busy: ${this.#name}. Write will be dropped: "${message}"`);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
this.#ready = false;
|
|
33
|
-
this.#stream.on("error", (error) => {
|
|
34
|
-
throw error;
|
|
35
|
-
});
|
|
36
|
-
this.#stream.on("drain", () => {
|
|
37
|
-
this.#ready = true;
|
|
38
|
-
});
|
|
39
|
-
this.#stream.on("finish", () => {
|
|
40
|
-
this.#ready = true;
|
|
41
|
-
});
|
|
42
|
-
this.#ready = this.#stream.write(message, () => {
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class RotatingFileStream {
|
|
48
|
-
#filePath;
|
|
49
|
-
#immediate;
|
|
50
|
-
#stream;
|
|
51
|
-
#options;
|
|
52
|
-
#createRfsStream;
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new RotatingFileStream instance.
|
|
55
|
-
* @param filePath Path to the log file
|
|
56
|
-
* @param writeImmediately Whether to write immediately or buffer writes
|
|
57
|
-
* @param options Options for the rotating file stream
|
|
58
|
-
* @throws {Error} If the 'rotating-file-stream' package is not installed
|
|
59
|
-
*/
|
|
60
|
-
constructor(filePath, writeImmediately = false, options = {}) {
|
|
61
|
-
this.#filePath = filePath;
|
|
62
|
-
this.#immediate = writeImmediately;
|
|
63
|
-
this.#options = options;
|
|
64
|
-
if (!this.#immediate) {
|
|
65
|
-
try {
|
|
66
|
-
this.#createRfsStream = require("rotating-file-stream").createStream;
|
|
67
|
-
} catch {
|
|
68
|
-
throw new Error("The 'rotating-file-stream' package is missing. Make sure to install the 'rotating-file-stream' package.");
|
|
69
|
-
}
|
|
70
|
-
this.#stream = this.#createRfsStream(this.#filePath, options);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Writes a message to the rotating file stream.
|
|
75
|
-
*
|
|
76
|
-
* If writeImmediately was set to true in the constructor, a new stream
|
|
77
|
-
* is created for each write operation. Otherwise, uses the buffered stream.
|
|
78
|
-
* @param message The message to write to the file
|
|
79
|
-
*/
|
|
80
|
-
write(message) {
|
|
81
|
-
let fileStream = this.#stream;
|
|
82
|
-
if (this.#immediate) {
|
|
83
|
-
fileStream = this.#createRfsStream(this.#filePath, this.#options);
|
|
84
|
-
}
|
|
85
|
-
const stream = new SafeStreamHandler(fileStream, this.#filePath);
|
|
86
|
-
stream.write(message);
|
|
87
|
-
if (this.#immediate) {
|
|
88
|
-
stream.end();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Ends the rotating file stream.
|
|
93
|
-
*
|
|
94
|
-
* Closes the underlying stream. When `writeImmediately` is not `true`,
|
|
95
|
-
* calling `write` after calling this method will throw an error.
|
|
96
|
-
*/
|
|
97
|
-
end() {
|
|
98
|
-
if (this.#stream !== void 0) {
|
|
99
|
-
this.#stream.end();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
class JsonFileReporter extends AbstractJsonReporter {
|
|
105
|
-
/** The rotating file stream instance */
|
|
106
|
-
stream;
|
|
107
|
-
/**
|
|
108
|
-
* Creates a new JsonFileReporter instance.
|
|
109
|
-
* @param options Configuration options for file rotation and JSON formatting
|
|
110
|
-
*/
|
|
111
|
-
constructor(options) {
|
|
112
|
-
super();
|
|
113
|
-
const { filePath, writeImmediately = false, ...rfsOptions } = options;
|
|
114
|
-
this.stream = new RotatingFileStream(filePath, writeImmediately, {
|
|
115
|
-
compress: "gzip",
|
|
116
|
-
// compress rotated files
|
|
117
|
-
interval: "1d",
|
|
118
|
-
// rotate daily
|
|
119
|
-
size: "10M",
|
|
120
|
-
// rotate every 10 MegaBytes written,
|
|
121
|
-
...rfsOptions
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Writes a JSON message to the rotating file stream.
|
|
126
|
-
* @param message The JSON-formatted log message to write
|
|
127
|
-
* @protected
|
|
128
|
-
*/
|
|
129
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
130
|
-
_log(message) {
|
|
131
|
-
this.stream.write(`${message}
|
|
132
|
-
`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export { JsonFileReporter };
|
|
1
|
+
var h=Object.defineProperty;var s=(e,t)=>h(e,"name",{value:t,configurable:!0});import{AbstractJsonReporter as n}from"../../packem_shared/AbstractJsonReporter-BawNFYxI.js";var o=Object.defineProperty,c=s((e,t)=>o(e,"name",{value:t,configurable:!0}),"e");class l{static{s(this,"n")}static{c(this,"SafeStreamHandler")}#t=!0;#e;#r;constructor(t,r){this.#e=t,this.#r=r}write(t){this.writeStream(t)}end(...t){this.#e.end(...t)}get isReady(){return this.#t}writeStream(t){if(!this.#t){console.warn(`Stream busy: ${this.#r}. Write will be dropped: "${t}"`);return}this.#t=!1,this.#e.on("error",r=>{throw r}),this.#e.on("drain",()=>{this.#t=!0}),this.#e.on("finish",()=>{this.#t=!0}),this.#t=this.#e.write(t,()=>{})}}var u=Object.defineProperty,m=s((e,t)=>u(e,"name",{value:t,configurable:!0}),"r$1");class d{static{s(this,"o")}static{m(this,"RotatingFileStream")}#t;#e;#r;#s;#i;constructor(t,r=!1,i={}){if(this.#t=t,this.#e=r,this.#s=i,!this.#e){try{this.#i=require("rotating-file-stream").createStream}catch{throw new Error("The 'rotating-file-stream' package is missing. Make sure to install the 'rotating-file-stream' package.")}this.#r=this.#i(this.#t,i)}}write(t){let r=this.#r;this.#e&&(r=this.#i(this.#t,this.#s));const i=new l(r,this.#t);i.write(t),this.#e&&i.end()}end(){this.#r!==void 0&&this.#r.end()}}var f=Object.defineProperty,p=s((e,t)=>f(e,"name",{value:t,configurable:!0}),"r");class v extends n{static{s(this,"JsonFileReporter")}static{p(this,"JsonFileReporter")}stream;constructor(t){super();const{filePath:r,writeImmediately:i=!1,...a}=t;this.stream=new d(r,i,{compress:"gzip",interval:"1d",size:"10M",...a})}_log(t){this.stream.write(`${t}
|
|
2
|
+
`)}}export{v as JsonFileReporter};
|