@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +152 -894
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +1 -1
  6. package/dist/index.server.d.ts +722 -61
  7. package/dist/index.server.js +5 -4
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/express.d.ts +73 -71
  10. package/dist/middleware/fastify.d.ts +69 -67
  11. package/dist/middleware/hono.d.ts +74 -72
  12. package/dist/middleware/next/handler.d.ts +101 -34
  13. package/dist/middleware/sveltekit.d.ts +100 -98
  14. package/dist/object-tree.d.ts +67 -70
  15. package/dist/packem_shared/{PrettyReporter-BtTr13Ha.js → PrettyReporter-CIbrmjUV.js} +1 -1
  16. package/dist/packem_shared/{PrettyReporter-BCvyNzXO.js → PrettyReporter-CNJEO9g7.js} +11 -8
  17. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  18. package/dist/packem_shared/{abstract-pretty-reporter-CXAKYCb8.js → abstract-pretty-reporter-CkqCt5hg.js} +4 -2
  19. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  20. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  21. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  22. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  23. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  24. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  25. package/dist/processor/caller/caller-processor.d.ts +49 -47
  26. package/dist/processor/environment-processor.d.ts +113 -113
  27. package/dist/processor/environment-processor.js +3 -10
  28. package/dist/processor/message-formatter-processor.d.ts +51 -49
  29. package/dist/processor/message-formatter-processor.js +2 -2
  30. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  31. package/dist/processor/redact-processor.d.ts +60 -41
  32. package/dist/processor/sampling-processor.d.ts +102 -101
  33. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  34. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  35. package/dist/reporter/http/http-reporter.d.ts +40 -36
  36. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  37. package/dist/reporter/json/index.browser.d.ts +99 -3
  38. package/dist/reporter/json/index.d.ts +51 -3
  39. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  40. package/dist/reporter/pretty/index.browser.js +1 -1
  41. package/dist/reporter/pretty/index.d.ts +219 -2
  42. package/dist/reporter/pretty/index.js +1 -1
  43. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  44. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  45. package/dist/wide-event.d.ts +5 -300
  46. package/package.json +6 -7
  47. package/dist/constants.d.ts +0 -37
  48. package/dist/middleware/next/middleware.d.ts +0 -59
  49. package/dist/middleware/next/storage.d.ts +0 -14
  50. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  51. package/dist/middleware/shared/headers.d.ts +0 -14
  52. package/dist/middleware/shared/routes.d.ts +0 -30
  53. package/dist/middleware/shared/storage.d.ts +0 -29
  54. package/dist/pail.browser.d.ts +0 -412
  55. package/dist/pail.server.d.ts +0 -158
  56. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  57. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  58. package/dist/reporter/http/utils/compression.d.ts +0 -7
  59. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  60. package/dist/reporter/http/utils/retry.d.ts +0 -27
  61. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  62. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  63. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  64. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  65. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  66. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  67. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  68. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  69. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  70. package/dist/reporter/utils/format-label.d.ts +0 -3
  71. package/dist/types.d.ts +0 -241
  72. package/dist/utils/arrayify.d.ts +0 -2
  73. package/dist/utils/get-longest-badge.d.ts +0 -4
  74. package/dist/utils/get-longest-label.d.ts +0 -4
  75. package/dist/utils/merge-types.d.ts +0 -4
  76. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  77. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  78. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,44 +1,63 @@
1
- import type { RedactOptions, Rules } from "@visulima/redact";
2
- import type { Meta, Processor } from "../types.d.ts";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-BeLumqgD.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ type StringAnonymize = {
5
+ key: string;
6
+ pattern: RegExp | string;
7
+ replacement?: string;
8
+ };
9
+ type Anonymize = {
10
+ deep?: boolean;
11
+ key: string;
12
+ pattern?: RegExp | string;
13
+ replacement?: unknown;
14
+ };
15
+ type Rules = (Anonymize | StringAnonymize | number | string)[];
16
+ type RedactOptions = {
17
+ exclude?: (number | string)[];
18
+ logger?: {
19
+ debug: (message?: unknown, ...optionalParameters: unknown[]) => void;
20
+ };
21
+ };
3
22
  /**
4
- * Redact Processor.
5
- *
6
- * A processor that redacts sensitive information from log messages and metadata.
7
- * Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
8
- * passwords, API keys, credit card numbers, and other PII.
9
- * @template L - The log level type
10
- * @example
11
- * ```typescript
12
- * import { createPail } from "@visulima/pail";
13
- * import RedactProcessor from "@visulima/pail/processor/redact";
14
- *
15
- * const logger = createPail({
16
- * processors: [new RedactProcessor()]
17
- * });
18
- *
19
- * logger.info("User login", {
20
- * username: "john",
21
- * password: "secret123", // Will be redacted
22
- * apiKey: "sk-123456" // Will be redacted
23
- * });
24
- * ```
25
- */
23
+ * Redact Processor.
24
+ *
25
+ * A processor that redacts sensitive information from log messages and metadata.
26
+ * Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
27
+ * passwords, API keys, credit card numbers, and other PII.
28
+ * @template L - The log level type
29
+ * @example
30
+ * ```typescript
31
+ * import { createPail } from "@visulima/pail";
32
+ * import RedactProcessor from "@visulima/pail/processor/redact";
33
+ *
34
+ * const logger = createPail({
35
+ * processors: [new RedactProcessor()]
36
+ * });
37
+ *
38
+ * logger.info("User login", {
39
+ * username: "john",
40
+ * password: "secret123", // Will be redacted
41
+ * apiKey: "sk-123456" // Will be redacted
42
+ * });
43
+ * ```
44
+ */
26
45
  declare class RedactProcessor<L extends string = string> implements Processor<L> {
27
- #private;
28
- /**
29
- * Creates a new RedactProcessor instance.
30
- * @param rules Custom redaction rules (uses standardRules if not provided)
31
- * @param options Additional redaction options
32
- */
33
- constructor(rules?: Rules, options?: RedactOptions);
34
- /**
35
- * Processes log metadata to redact sensitive information.
36
- *
37
- * Applies redaction rules to the message, context, and error properties
38
- * in the log metadata to prevent sensitive data from being logged.
39
- * @param meta The log metadata to process
40
- * @returns The processed metadata with sensitive data redacted
41
- */
42
- process(meta: Meta<L>): Meta<L>;
46
+ #private;
47
+ /**
48
+ * Creates a new RedactProcessor instance.
49
+ * @param rules Custom redaction rules (uses standardRules if not provided)
50
+ * @param options Additional redaction options
51
+ */
52
+ constructor(rules?: Rules, options?: RedactOptions);
53
+ /**
54
+ * Processes log metadata to redact sensitive information.
55
+ *
56
+ * Applies redaction rules to the message, context, and error properties
57
+ * in the log metadata to prevent sensitive data from being logged.
58
+ * @param meta The log metadata to process
59
+ * @returns The processed metadata with sensitive data redacted
60
+ */
61
+ process(meta: Meta<L>): Meta<L>;
43
62
  }
44
- export default RedactProcessor;
63
+ export { RedactProcessor as default };
@@ -1,111 +1,112 @@
1
- import type { Meta, Processor } from "../types.d.ts";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-BeLumqgD.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
2
4
  /**
3
- * Head sampling configuration.
4
- *
5
- * Controls random sampling rates per log level. Each key is a log level name
6
- * and the value is the percentage (0-100) of logs at that level to keep.
7
- * Levels not listed default to 100 (keep all).
8
- * @example
9
- * ```typescript
10
- * const headSampling: HeadSamplingConfig = {
11
- * debug: 0, // Drop all debug logs
12
- * informational: 10, // Keep 10% of info logs
13
- * warning: 50, // Keep 50% of warning logs
14
- * error: 100, // Keep all error logs
15
- * };
16
- * ```
17
- */
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
+ */
18
20
  type HeadSamplingConfig = Partial<Record<string, number>>;
19
21
  /**
20
- * Tail sampling condition function.
21
- *
22
- * A function that receives the log metadata and returns true if the log
23
- * should be force-kept regardless of head sampling. This allows keeping
24
- * important logs based on their content (e.g., errors, slow operations).
25
- * @template L - The log level type
26
- */
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
+ */
27
29
  type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
28
30
  /**
29
- * Sampling processor configuration options.
30
- */
31
+ * Sampling processor configuration options.
32
+ */
31
33
  interface SamplingProcessorOptions<L extends string = string> {
32
- /**
33
- * Head sampling rates per log level.
34
- *
35
- * A map of log level to sampling percentage (0-100).
36
- * Levels not specified default to 100 (keep all).
37
- * Set to 0 to drop all logs at that level.
38
- */
39
- head?: HeadSamplingConfig;
40
- /**
41
- * Tail sampling conditions.
42
- *
43
- * An array of condition functions that can force-keep a log entry
44
- * even if it was dropped by head sampling. If any condition returns true,
45
- * the log is kept.
46
- */
47
- tail?: TailSamplingCondition<L>[];
34
+ /**
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
+ */
41
+ head?: HeadSamplingConfig;
42
+ /**
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
+ */
49
+ tail?: TailSamplingCondition<L>[];
48
50
  }
49
51
  /**
50
- * Sampling Processor.
51
- *
52
- * Inspired by evlog's production sampling strategy, this processor implements
53
- * both head sampling (random per-level) and tail sampling (force-keep based
54
- * on conditions) to control log volume in production environments.
55
- *
56
- * **Head sampling** randomly drops a percentage of logs per level. This is
57
- * evaluated first and provides broad volume control.
58
- *
59
- * **Tail sampling** can override head sampling to force-keep important logs
60
- * based on their content. For example, you might drop 90% of info logs but
61
- * force-keep any that contain error information or relate to slow operations.
62
- *
63
- * When a log is dropped by sampling, the processor sets a `__dropped: true`
64
- * boolean flag on the meta object. Reporters should check for this flag and
65
- * skip entries where `__dropped` is `true`.
66
- * @template L - The log level type
67
- * @example
68
- * ```typescript
69
- * import { createPail } from "@visulima/pail";
70
- * import SamplingProcessor from "@visulima/pail/processor/sampling";
71
- *
72
- * const logger = createPail({
73
- * processors: [
74
- * new SamplingProcessor({
75
- * head: {
76
- * debug: 0, // Drop all debug logs
77
- * informational: 10, // Keep 10% of info logs
78
- * warning: 50, // Keep 50% of warnings
79
- * error: 100, // Keep all errors
80
- * },
81
- * tail: [
82
- * // Force-keep logs with errors regardless of head sampling
83
- * (meta) => meta.error !== undefined,
84
- * // Force-keep logs from critical scopes
85
- * (meta) => meta.scope?.includes("payment") ?? false,
86
- * ],
87
- * }),
88
- * ],
89
- * });
90
- * ```
91
- */
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
+ */
92
94
  declare class SamplingProcessor<L extends string = string> implements Processor<L> {
93
- #private;
94
- /**
95
- * Creates a new SamplingProcessor instance.
96
- * @param options Sampling configuration options
97
- */
98
- constructor(options?: SamplingProcessorOptions<L>);
99
- /**
100
- * Processes log metadata to apply sampling rules.
101
- *
102
- * First evaluates head sampling (random per-level), then checks tail
103
- * sampling conditions. If a log is dropped, the meta is marked with
104
- * `__dropped: true` so reporters can skip it.
105
- * @param meta The log metadata to process
106
- * @returns The processed metadata, potentially marked as dropped
107
- */
108
- process(meta: Meta<L>): Meta<L>;
95
+ #private;
96
+ /**
97
+ * Creates a new SamplingProcessor instance.
98
+ * @param options Sampling configuration options
99
+ */
100
+ constructor(options?: SamplingProcessorOptions<L>);
101
+ /**
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
+ */
110
+ process(meta: Meta<L>): Meta<L>;
109
111
  }
110
- export default SamplingProcessor;
111
- export type { HeadSamplingConfig, SamplingProcessorOptions, TailSamplingCondition };
112
+ export { type HeadSamplingConfig, type SamplingProcessorOptions, type TailSamplingCondition, SamplingProcessor as default };
@@ -1,46 +1,95 @@
1
- import type { Options as RfsOptions } from "rotating-file-stream";
2
- import type { AbstractJsonReporterOptions } from "../json/abstract-json-reporter.d.ts";
3
- import { AbstractJsonReporter } from "../json/abstract-json-reporter.d.ts";
4
- import RotatingFileStream from "./utils/rotating-file-stream.d.ts";
1
+ import { Options } from 'rotating-file-stream';
2
+ import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-BAgznjyU.js";
3
+ import 'safe-stable-stringify';
4
+ import "../../packem_shared/types.d-BeLumqgD.js";
5
+ import '@visulima/colorize';
6
+ import '@visulima/interactive-manager';
5
7
  /**
6
- * Options for configuring the JsonFileReporter.
7
- */
8
- export type FileReporterOptions = AbstractJsonReporterOptions & RfsOptions & {
9
- /** Path to the log file */
10
- filePath: string;
11
- /** Whether to write immediately to disk instead of buffering */
12
- writeImmediately?: boolean;
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
- * JSON File Reporter.
16
- *
17
- * A reporter that writes structured JSON log entries to rotating files on disk.
18
- * Supports automatic file rotation based on size, time intervals, and compression.
19
- * @template L - The log level type
20
- * @example
21
- * ```typescript
22
- * const reporter = new JsonFileReporter({
23
- * filePath: "/var/log/app.log",
24
- * interval: "1d", // Rotate daily
25
- * size: "10M", // Rotate when file reaches 10MB
26
- * compress: "gzip"
27
- * });
28
- *
29
- * logger.registerReporters([reporter]);
30
- * ```
31
- */
32
- export declare class JsonFileReporter<L extends string = string> extends AbstractJsonReporter<L> {
33
- /** The rotating file stream instance */
34
- protected stream: RotatingFileStream;
35
- /**
36
- * Creates a new JsonFileReporter instance.
37
- * @param options Configuration options for file rotation and JSON formatting
38
- */
39
- constructor(options: FileReporterOptions);
40
- /**
41
- * Writes a JSON message to the rotating file stream.
42
- * @param message The JSON-formatted log message to write
43
- * @protected
44
- */
45
- protected _log(message: string): void;
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 };