@visulima/pail 4.0.2 → 4.1.1
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 +23 -0
- package/LICENSE.md +346 -0
- package/README.md +17 -0
- package/dist/error.d.ts +69 -69
- package/dist/index.browser.d.ts +446 -445
- package/dist/index.browser.js +17 -17
- package/dist/index.server.d.ts +582 -582
- package/dist/index.server.js +27 -27
- package/dist/middleware/elysia.d.ts +44 -42
- package/dist/middleware/elysia.js +1 -1
- package/dist/middleware/express.d.ts +58 -59
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +55 -56
- package/dist/middleware/fastify.js +1 -1
- package/dist/middleware/hono.d.ts +56 -57
- package/dist/middleware/hono.js +1 -1
- package/dist/middleware/next/handler.d.ts +67 -68
- package/dist/middleware/next/handler.js +1 -1
- package/dist/middleware/sveltekit.d.ts +72 -73
- package/dist/middleware/sveltekit.js +1 -1
- package/dist/object-tree.d.ts +44 -44
- package/dist/packem_shared/AbstractJsonReporter-BpWRnN0L.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-DxZwImm5.js +1 -0
- package/dist/packem_shared/JsonReporter-9IcELa1m.js +2 -0
- package/dist/packem_shared/JsonReporter-Dd3kuj8X.js +1 -0
- package/dist/packem_shared/{PrettyReporter-DsHfKOU7.js → PrettyReporter-BUWNEg3_.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-CcDdPQSt.js → PrettyReporter-DbgD89ck.js} +56 -30
- package/dist/packem_shared/abstract-json-reporter.d-B6NoO-hG.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-DrLBJ6ds.js → abstract-pretty-reporter-CyfTvmKf.js} +41 -39
- package/dist/packem_shared/create-middleware-logger.d-BRkkBMlk.d.ts +47 -0
- package/dist/packem_shared/headers-DI58djdG.js +1 -0
- package/dist/packem_shared/index-CbkPnylC.js +1 -0
- package/dist/packem_shared/serializeError-52C4oiKx-CrnRcq9R.js +1 -0
- package/dist/packem_shared/storage-DVcJumyk.js +1 -0
- package/dist/packem_shared/types.d-4ge_rME4.d.ts +246 -0
- package/dist/packem_shared/{types.d-Cz9S7jZh.d.ts → types.d-BW8kAXUv.d.ts} +95 -95
- package/dist/packem_shared/types.d-DGHeA2iJ.d.ts +194 -0
- package/dist/packem_shared/useLogger-7p55yvvc.js +1 -0
- package/dist/packem_shared/wide-event.d-BMLastMR.d.ts +716 -0
- package/dist/packem_shared/write-stream-ytl_vhg_.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +32 -33
- package/dist/processor/environment-processor.d.ts +83 -84
- package/dist/processor/message-formatter-processor.d.ts +40 -45
- package/dist/processor/message-formatter-processor.js +1 -1
- package/dist/processor/opentelemetry-processor.d.ts +51 -52
- package/dist/processor/redact-processor.d.ts +57 -65
- package/dist/processor/sampling-processor.d.ts +90 -91
- package/dist/reporter/file/json-file-reporter.d.ts +77 -78
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +125 -121
- package/dist/reporter/http/abstract-http-reporter.js +2 -2
- package/dist/reporter/http/http-reporter.d.ts +33 -34
- package/dist/reporter/http/http-reporter.edge-light.d.ts +235 -230
- package/dist/reporter/http/http-reporter.edge-light.js +2 -2
- package/dist/reporter/json/index.browser.d.ts +62 -61
- package/dist/reporter/json/index.browser.js +1 -1
- package/dist/reporter/json/index.d.ts +36 -37
- package/dist/reporter/json/index.js +1 -1
- package/dist/reporter/pretty/index.browser.d.ts +57 -56
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +133 -133
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +91 -90
- package/dist/reporter/simple/simple-reporter.server.js +7 -7
- package/dist/wide-event.d.ts +2 -3
- package/dist/wide-event.js +1 -1
- package/package.json +58 -37
- package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +0 -1
- package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +0 -1
- package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +0 -2
- package/dist/packem_shared/JsonReporter-bmem9lcg.js +0 -1
- package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +0 -62
- package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +0 -25
- package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +0 -47
- package/dist/packem_shared/headers-DH0H2s8W.js +0 -1
- package/dist/packem_shared/index-Q1764hvO.js +0 -1
- package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +0 -1
- package/dist/packem_shared/storage-DaXAlpiO.js +0 -1
- package/dist/packem_shared/types.d-bWnqHJKL.d.ts +0 -211
- package/dist/packem_shared/types.d-xxE3FOD3.d.ts +0 -229
- package/dist/packem_shared/useLogger-DB34CuU5.js +0 -1
- package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +0 -717
- package/dist/packem_shared/write-stream-C7jxLxIT.js +0 -1
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { M as Meta, P as Processor } from "../packem_shared/types.d-
|
|
1
|
+
import { M as Meta, P as Processor } from "../packem_shared/types.d-4ge_rME4.js";
|
|
2
2
|
import '@visulima/colorize';
|
|
3
3
|
import '@visulima/interactive-manager';
|
|
4
|
-
import 'type-fest';
|
|
5
4
|
/**
|
|
6
|
-
* A censor function receives the original value being redacted plus the dot-path
|
|
7
|
-
* identifier of where it was found, and returns the value to store in its place.
|
|
8
|
-
*
|
|
9
|
-
* Use it for partial masking — e.g. keep the last four digits of a card number, or
|
|
10
|
-
* mask the local part of an email — instead of a static replacement string.
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const keepLast4: Censor = (value) =>
|
|
14
|
-
* typeof value === "string" ? "****" + value.slice(-4) : value;
|
|
15
|
-
* ```
|
|
16
|
-
* @param value The original value matched by the rule.
|
|
17
|
-
* @param path The dot-path of the matched key (e.g. `user.card`), or `undefined`
|
|
18
|
-
* for matches that have no key path (string-anonymizer / array-index matches).
|
|
19
|
-
*/
|
|
5
|
+
* A censor function receives the original value being redacted plus the dot-path
|
|
6
|
+
* identifier of where it was found, and returns the value to store in its place.
|
|
7
|
+
*
|
|
8
|
+
* Use it for partial masking — e.g. keep the last four digits of a card number, or
|
|
9
|
+
* mask the local part of an email — instead of a static replacement string.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const keepLast4: Censor = (value) =>
|
|
13
|
+
* typeof value === "string" ? "****" + value.slice(-4) : value;
|
|
14
|
+
* ```
|
|
15
|
+
* @param value The original value matched by the rule.
|
|
16
|
+
* @param path The dot-path of the matched key (e.g. `user.card`), or `undefined`
|
|
17
|
+
* for matches that have no key path (string-anonymizer / array-index matches).
|
|
18
|
+
*/
|
|
20
19
|
type Censor = (value: unknown, path: string | undefined) => unknown;
|
|
21
20
|
type StringAnonymize = {
|
|
22
21
|
key: string;
|
|
@@ -25,23 +24,23 @@ type StringAnonymize = {
|
|
|
25
24
|
};
|
|
26
25
|
type Anonymize = {
|
|
27
26
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
* When `true`, the rule is also applied to nested string values (NLP / regex based),
|
|
28
|
+
* not just to matching object keys.
|
|
29
|
+
*/
|
|
31
30
|
deep?: boolean;
|
|
32
31
|
/** The key (or wildcard pattern, or NLP type) to match. Case-insensitive. */
|
|
33
32
|
key: string;
|
|
34
33
|
/** Optional regular expression matched against nested string values. */
|
|
35
34
|
pattern?: RegExp | string;
|
|
36
35
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
* When `true`, the matching key is deleted from the output object instead of being
|
|
37
|
+
* replaced with `replacement`. Ignored for array elements and string-anonymizer matches.
|
|
38
|
+
*/
|
|
40
39
|
remove?: boolean;
|
|
41
40
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
* The value (or {@link Censor} function) to put in place of a match. Defaults to
|
|
42
|
+
* the `<KEY>` placeholder when omitted.
|
|
43
|
+
*/
|
|
45
44
|
replacement?: unknown;
|
|
46
45
|
};
|
|
47
46
|
type Rules = (Anonymize | StringAnonymize | number | string)[];
|
|
@@ -52,51 +51,44 @@ type RedactOptions = {
|
|
|
52
51
|
};
|
|
53
52
|
};
|
|
54
53
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
* logger.info("User login", {
|
|
78
|
-
* username: "john",
|
|
79
|
-
* password: "secret123", // Will be redacted
|
|
80
|
-
* apiKey: "sk-123456" // Will be redacted
|
|
81
|
-
* });
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
54
|
+
* Redact Processor.
|
|
55
|
+
*
|
|
56
|
+
* A processor that redacts sensitive information from log messages and metadata.
|
|
57
|
+
* Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
|
|
58
|
+
* passwords, API keys, credit card numbers, and other PII.
|
|
59
|
+
* @template L - The log level type
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { createPail } from "@visulima/pail";
|
|
63
|
+
* import RedactProcessor from "@visulima/pail/processor/redact";
|
|
64
|
+
*
|
|
65
|
+
* const logger = createPail({
|
|
66
|
+
* processors: [new RedactProcessor()]
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* logger.info("User login", {
|
|
70
|
+
* username: "john",
|
|
71
|
+
* password: "secret123", // Will be redacted
|
|
72
|
+
* apiKey: "sk-123456" // Will be redacted
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
84
76
|
declare class RedactProcessor<L extends string = string> implements Processor<L> {
|
|
85
77
|
#private;
|
|
86
78
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
* Creates a new RedactProcessor instance.
|
|
80
|
+
* @param rules Custom redaction rules (uses standardRules if not provided)
|
|
81
|
+
* @param options Additional redaction options
|
|
82
|
+
*/
|
|
91
83
|
constructor(rules?: Rules, options?: RedactOptions);
|
|
92
84
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
* Processes log metadata to redact sensitive information.
|
|
86
|
+
*
|
|
87
|
+
* Applies redaction rules to the message, context, and error properties
|
|
88
|
+
* in the log metadata to prevent sensitive data from being logged.
|
|
89
|
+
* @param meta The log metadata to process
|
|
90
|
+
* @returns The processed metadata with sensitive data redacted
|
|
91
|
+
*/
|
|
100
92
|
process(meta: Meta<L>): Meta<L>;
|
|
101
93
|
}
|
|
102
94
|
export { RedactProcessor as default };
|
|
@@ -1,113 +1,112 @@
|
|
|
1
|
-
import { M as Meta, P as Processor } from "../packem_shared/types.d-
|
|
1
|
+
import { M as Meta, P as Processor } from "../packem_shared/types.d-4ge_rME4.js";
|
|
2
2
|
import '@visulima/colorize';
|
|
3
3
|
import '@visulima/interactive-manager';
|
|
4
|
-
import 'type-fest';
|
|
5
4
|
/**
|
|
6
|
-
* Head sampling configuration.
|
|
7
|
-
*
|
|
8
|
-
* Controls random sampling rates per log level. Each key is a log level name
|
|
9
|
-
* and the value is the percentage (0-100) of logs at that level to keep.
|
|
10
|
-
* Levels not listed default to 100 (keep all).
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const headSampling: HeadSamplingConfig = {
|
|
14
|
-
* debug: 0, // Drop all debug logs
|
|
15
|
-
* informational: 10, // Keep 10% of info logs
|
|
16
|
-
* warning: 50, // Keep 50% of warning logs
|
|
17
|
-
* error: 100, // Keep all error logs
|
|
18
|
-
* };
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
5
|
+
* Head sampling configuration.
|
|
6
|
+
*
|
|
7
|
+
* Controls random sampling rates per log level. Each key is a log level name
|
|
8
|
+
* and the value is the percentage (0-100) of logs at that level to keep.
|
|
9
|
+
* Levels not listed default to 100 (keep all).
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const headSampling: HeadSamplingConfig = {
|
|
13
|
+
* debug: 0, // Drop all debug logs
|
|
14
|
+
* informational: 10, // Keep 10% of info logs
|
|
15
|
+
* warning: 50, // Keep 50% of warning logs
|
|
16
|
+
* error: 100, // Keep all error logs
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
21
20
|
type HeadSamplingConfig = Partial<Record<string, number>>;
|
|
22
21
|
/**
|
|
23
|
-
* Tail sampling condition function.
|
|
24
|
-
*
|
|
25
|
-
* A function that receives the log metadata and returns true if the log
|
|
26
|
-
* should be force-kept regardless of head sampling. This allows keeping
|
|
27
|
-
* important logs based on their content (e.g., errors, slow operations).
|
|
28
|
-
* @template L - The log level type
|
|
29
|
-
*/
|
|
22
|
+
* Tail sampling condition function.
|
|
23
|
+
*
|
|
24
|
+
* A function that receives the log metadata and returns true if the log
|
|
25
|
+
* should be force-kept regardless of head sampling. This allows keeping
|
|
26
|
+
* important logs based on their content (e.g., errors, slow operations).
|
|
27
|
+
* @template L - The log level type
|
|
28
|
+
*/
|
|
30
29
|
type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
|
|
31
30
|
/**
|
|
32
|
-
* Sampling processor configuration options.
|
|
33
|
-
*/
|
|
31
|
+
* Sampling processor configuration options.
|
|
32
|
+
*/
|
|
34
33
|
interface SamplingProcessorOptions<L extends string = string> {
|
|
35
34
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
* Head sampling rates per log level.
|
|
36
|
+
*
|
|
37
|
+
* A map of log level to sampling percentage (0-100).
|
|
38
|
+
* Levels not specified default to 100 (keep all).
|
|
39
|
+
* Set to 0 to drop all logs at that level.
|
|
40
|
+
*/
|
|
42
41
|
head?: HeadSamplingConfig;
|
|
43
42
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
* Tail sampling conditions.
|
|
44
|
+
*
|
|
45
|
+
* An array of condition functions that can force-keep a log entry
|
|
46
|
+
* even if it was dropped by head sampling. If any condition returns true,
|
|
47
|
+
* the log is kept.
|
|
48
|
+
*/
|
|
50
49
|
tail?: TailSamplingCondition<L>[];
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
|
-
* Sampling Processor.
|
|
54
|
-
*
|
|
55
|
-
* Inspired by evlog's production sampling strategy, this processor implements
|
|
56
|
-
* both head sampling (random per-level) and tail sampling (force-keep based
|
|
57
|
-
* on conditions) to control log volume in production environments.
|
|
58
|
-
*
|
|
59
|
-
* **Head sampling** randomly drops a percentage of logs per level. This is
|
|
60
|
-
* evaluated first and provides broad volume control.
|
|
61
|
-
*
|
|
62
|
-
* **Tail sampling** can override head sampling to force-keep important logs
|
|
63
|
-
* based on their content. For example, you might drop 90% of info logs but
|
|
64
|
-
* force-keep any that contain error information or relate to slow operations.
|
|
65
|
-
*
|
|
66
|
-
* When a log is dropped by sampling, the processor sets a `dropped: true`
|
|
67
|
-
* boolean flag on the meta object. Reporters should check for this flag and
|
|
68
|
-
* skip entries where `dropped` is `true`.
|
|
69
|
-
* @template L - The log level type
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* import { createPail } from "@visulima/pail";
|
|
73
|
-
* import SamplingProcessor from "@visulima/pail/processor/sampling";
|
|
74
|
-
*
|
|
75
|
-
* const logger = createPail({
|
|
76
|
-
* processors: [
|
|
77
|
-
* new SamplingProcessor({
|
|
78
|
-
* head: {
|
|
79
|
-
* debug: 0, // Drop all debug logs
|
|
80
|
-
* informational: 10, // Keep 10% of info logs
|
|
81
|
-
* warning: 50, // Keep 50% of warnings
|
|
82
|
-
* error: 100, // Keep all errors
|
|
83
|
-
* },
|
|
84
|
-
* tail: [
|
|
85
|
-
* // Force-keep logs with errors regardless of head sampling
|
|
86
|
-
* (meta) => meta.error !== undefined,
|
|
87
|
-
* // Force-keep logs from critical scopes
|
|
88
|
-
* (meta) => meta.scope?.includes("payment") ?? false,
|
|
89
|
-
* ],
|
|
90
|
-
* }),
|
|
91
|
-
* ],
|
|
92
|
-
* });
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
52
|
+
* Sampling Processor.
|
|
53
|
+
*
|
|
54
|
+
* Inspired by evlog's production sampling strategy, this processor implements
|
|
55
|
+
* both head sampling (random per-level) and tail sampling (force-keep based
|
|
56
|
+
* on conditions) to control log volume in production environments.
|
|
57
|
+
*
|
|
58
|
+
* **Head sampling** randomly drops a percentage of logs per level. This is
|
|
59
|
+
* evaluated first and provides broad volume control.
|
|
60
|
+
*
|
|
61
|
+
* **Tail sampling** can override head sampling to force-keep important logs
|
|
62
|
+
* based on their content. For example, you might drop 90% of info logs but
|
|
63
|
+
* force-keep any that contain error information or relate to slow operations.
|
|
64
|
+
*
|
|
65
|
+
* When a log is dropped by sampling, the processor sets a `dropped: true`
|
|
66
|
+
* boolean flag on the meta object. Reporters should check for this flag and
|
|
67
|
+
* skip entries where `dropped` is `true`.
|
|
68
|
+
* @template L - The log level type
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { createPail } from "@visulima/pail";
|
|
72
|
+
* import SamplingProcessor from "@visulima/pail/processor/sampling";
|
|
73
|
+
*
|
|
74
|
+
* const logger = createPail({
|
|
75
|
+
* processors: [
|
|
76
|
+
* new SamplingProcessor({
|
|
77
|
+
* head: {
|
|
78
|
+
* debug: 0, // Drop all debug logs
|
|
79
|
+
* informational: 10, // Keep 10% of info logs
|
|
80
|
+
* warning: 50, // Keep 50% of warnings
|
|
81
|
+
* error: 100, // Keep all errors
|
|
82
|
+
* },
|
|
83
|
+
* tail: [
|
|
84
|
+
* // Force-keep logs with errors regardless of head sampling
|
|
85
|
+
* (meta) => meta.error !== undefined,
|
|
86
|
+
* // Force-keep logs from critical scopes
|
|
87
|
+
* (meta) => meta.scope?.includes("payment") ?? false,
|
|
88
|
+
* ],
|
|
89
|
+
* }),
|
|
90
|
+
* ],
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
95
94
|
declare class SamplingProcessor<L extends string = string> implements Processor<L> {
|
|
96
95
|
#private;
|
|
97
96
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
* Creates a new SamplingProcessor instance.
|
|
98
|
+
* @param options Sampling configuration options
|
|
99
|
+
*/
|
|
101
100
|
constructor(options?: SamplingProcessorOptions<L>);
|
|
102
101
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
* Processes log metadata to apply sampling rules.
|
|
103
|
+
*
|
|
104
|
+
* First evaluates head sampling (random per-level), then checks tail
|
|
105
|
+
* sampling conditions. If a log is dropped, the meta is marked with
|
|
106
|
+
* `dropped: true` so reporters can skip it.
|
|
107
|
+
* @param meta The log metadata to process
|
|
108
|
+
* @returns The processed metadata, potentially marked as dropped
|
|
109
|
+
*/
|
|
111
110
|
process(meta: Meta<L>): Meta<L>;
|
|
112
111
|
}
|
|
113
112
|
export { type HeadSamplingConfig, type SamplingProcessorOptions, type TailSamplingCondition, SamplingProcessor as default };
|
|
@@ -1,59 +1,58 @@
|
|
|
1
1
|
import { Options } from 'rotating-file-stream';
|
|
2
|
-
import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-
|
|
2
|
+
import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-B6NoO-hG.js";
|
|
3
3
|
import "../../packem_shared/index.d-T71KjNAr.js";
|
|
4
|
-
import
|
|
5
|
-
import "../../packem_shared/types.d-bWnqHJKL.js";
|
|
4
|
+
import "../../packem_shared/types.d-4ge_rME4.js";
|
|
6
5
|
import '@visulima/colorize';
|
|
7
6
|
import '@visulima/interactive-manager';
|
|
8
7
|
/**
|
|
9
|
-
* Rotating File Stream.
|
|
10
|
-
*
|
|
11
|
-
* A wrapper for the `rotating-file-stream` module that provides optional immediate
|
|
12
|
-
* writing to disk by creating and closing a new stream on each write operation.
|
|
13
|
-
* This is useful for ensuring log messages are written immediately rather than buffered.
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Buffered writing (default)
|
|
17
|
-
* const bufferedStream = new RotatingFileStream("/var/log/app.log", false, {
|
|
18
|
-
* interval: "1d",
|
|
19
|
-
* size: "10M"
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // Immediate writing
|
|
23
|
-
* const immediateStream = new RotatingFileStream("/var/log/app.log", true, {
|
|
24
|
-
* interval: "1d"
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
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
|
+
*/
|
|
28
27
|
declare class RotatingFileStream {
|
|
29
28
|
#private;
|
|
30
29
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
*/
|
|
37
36
|
constructor(filePath: string, writeImmediately?: boolean, options?: Options);
|
|
38
37
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
*/
|
|
45
44
|
write(message: string): void;
|
|
46
45
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
*/
|
|
52
51
|
end(): void;
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
55
|
-
* Options for configuring the JsonFileReporter.
|
|
56
|
-
*/
|
|
54
|
+
* Options for configuring the JsonFileReporter.
|
|
55
|
+
*/
|
|
57
56
|
type FileReporterOptions = AbstractJsonReporterOptions & Options & {
|
|
58
57
|
/** Path to the log file */
|
|
59
58
|
filePath: string;
|
|
@@ -61,53 +60,53 @@ type FileReporterOptions = AbstractJsonReporterOptions & Options & {
|
|
|
61
60
|
writeImmediately?: boolean;
|
|
62
61
|
};
|
|
63
62
|
/**
|
|
64
|
-
* JSON File Reporter.
|
|
65
|
-
*
|
|
66
|
-
* A reporter that writes structured JSON log entries to rotating files on disk.
|
|
67
|
-
* Supports automatic file rotation based on size, time intervals, and compression.
|
|
68
|
-
* @template L - The log level type
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* const reporter = new JsonFileReporter({
|
|
72
|
-
* filePath: "/var/log/app.log",
|
|
73
|
-
* interval: "1d", // Rotate daily
|
|
74
|
-
* size: "10M", // Rotate when file reaches 10MB
|
|
75
|
-
* compress: "gzip"
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* logger.registerReporters([reporter]);
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
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
|
+
*/
|
|
81
80
|
declare class JsonFileReporter<L extends string = string> extends AbstractJsonReporter<L> {
|
|
82
81
|
/** The rotating file stream instance */
|
|
83
82
|
protected stream: RotatingFileStream;
|
|
84
83
|
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
* Creates a new JsonFileReporter instance.
|
|
85
|
+
* @param options Configuration options for file rotation and JSON formatting
|
|
86
|
+
*/
|
|
88
87
|
constructor(options: FileReporterOptions);
|
|
89
88
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
* Closes the underlying rotating file stream.
|
|
90
|
+
*
|
|
91
|
+
* Ends the buffered stream so any queued writes are flushed to disk before the
|
|
92
|
+
* process exits. Without this the tail of the log can be lost on a short-lived
|
|
93
|
+
* process. After calling `close()` no further writes should be made (unless
|
|
94
|
+
* `writeImmediately` was enabled, in which case each write owns its own stream).
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* process.on("beforeExit", () => reporter.close());
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
101
100
|
close(): void;
|
|
102
101
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
* Alias for {@link close} to match common transport `dispose` conventions.
|
|
103
|
+
*/
|
|
105
104
|
dispose(): void;
|
|
106
105
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
* Writes a JSON message to the rotating file stream.
|
|
107
|
+
* @param message The JSON-formatted log message to write
|
|
108
|
+
* @protected
|
|
109
|
+
*/
|
|
111
110
|
protected override _log(message: string): void;
|
|
112
111
|
}
|
|
113
112
|
export { FileReporterOptions, JsonFileReporter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{AbstractJsonReporter as a}from"../../packem_shared/AbstractJsonReporter-
|
|
1
|
+
import{AbstractJsonReporter as a}from"../../packem_shared/AbstractJsonReporter-DxZwImm5.js";class h{#t=!0;#s;#e;#i;constructor(t,e,s){this.#s=t,this.#e=e,this.#i=s??((i,o)=>{console.error(`Stream error: ${o}. Writes will be dropped.`,i)}),this.#s.on("error",i=>{this.#t=!1,this.#i(i,this.#e)}),this.#s.on("drain",()=>{this.#t=!0}),this.#s.on("finish",()=>{this.#t=!0})}write(t){this.writeStream(t)}end(...t){this.#s.end(...t)}get isReady(){return this.#t}writeStream(t){if(!this.#t){console.warn(`Stream busy: ${this.#e}. Write will be dropped: "${t}"`);return}this.#t=!1,this.#t=this.#s.write(t,()=>{})}}class n{#t;#s;#e;#i;#r;#h;constructor(t,e=!1,s={}){this.#t=t,this.#s=e,this.#i=s;try{this.#r=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.#s||(this.#e=this.#r(this.#t,s),this.#h=new h(this.#e,this.#t))}write(t){if(this.#s){const e=this.#r(this.#t,this.#i),s=new h(e,this.#t);s.write(t),s.end();return}this.#h.write(t)}end(){this.#e!==void 0&&this.#e.end()}}class c extends a{stream;constructor(t){super();const{filePath:e,writeImmediately:s=!1,...i}=t;this.stream=new n(e,s,{compress:"gzip",interval:"1d",size:"10M",...i})}close(){this.stream.end()}dispose(){this.close()}_log(t){this.stream.write(`${t}
|
|
2
2
|
`)}}export{c as JsonFileReporter};
|