@visulima/pail 4.0.0-alpha.2 → 4.0.0-alpha.21

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 (131) hide show
  1. package/CHANGELOG.md +371 -0
  2. package/LICENSE.md +148 -879
  3. package/README.md +323 -0
  4. package/dist/error.d.ts +103 -0
  5. package/dist/error.js +5 -0
  6. package/dist/index.browser.d.ts +557 -45
  7. package/dist/index.browser.js +19 -12
  8. package/dist/index.server.d.ts +724 -63
  9. package/dist/index.server.js +27 -529
  10. package/dist/middleware/elysia.d.ts +73 -0
  11. package/dist/middleware/elysia.js +1 -0
  12. package/dist/middleware/express.d.ts +88 -0
  13. package/dist/middleware/express.js +1 -0
  14. package/dist/middleware/fastify.d.ts +83 -0
  15. package/dist/middleware/fastify.js +1 -0
  16. package/dist/middleware/hono.d.ts +87 -0
  17. package/dist/middleware/hono.js +1 -0
  18. package/dist/middleware/next/handler.d.ts +103 -0
  19. package/dist/middleware/next/handler.js +1 -0
  20. package/dist/middleware/sveltekit.d.ts +125 -0
  21. package/dist/middleware/sveltekit.js +1 -0
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-CF0KKdQS.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-CVwjgboT.js +1 -0
  26. package/dist/packem_shared/JsonReporter-BJFnahby.js +1 -0
  27. package/dist/packem_shared/JsonReporter-CnLM-d0U.js +2 -0
  28. package/dist/packem_shared/PrettyReporter-D75CJT0C.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-D9aBMmxI.js +45 -0
  30. package/dist/packem_shared/abstract-json-reporter.d-Boj5w068.d.ts +61 -0
  31. package/dist/packem_shared/abstract-pretty-reporter-zijeSUgy.js +34 -0
  32. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  33. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  34. package/dist/packem_shared/create-middleware-logger.d-MK7moe4r.d.ts +47 -0
  35. package/dist/packem_shared/createPailError-CbU1Ogfa.js +5 -0
  36. package/dist/packem_shared/headers-D-K_EnkH.js +1 -0
  37. package/dist/packem_shared/index-COQEZODZ.js +1 -0
  38. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  39. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  40. package/dist/packem_shared/types.d-Ck_RSjLg.d.ts +246 -0
  41. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  42. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  43. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  44. package/dist/packem_shared/wide-event.d-DkYD7YVK.d.ts +705 -0
  45. package/dist/packem_shared/write-console-log-based-on-level-DDSKGBKj.js +1 -0
  46. package/dist/packem_shared/write-stream-B6BXco86.js +1 -0
  47. package/dist/processor/caller/caller-processor.d.ts +49 -47
  48. package/dist/processor/caller/caller-processor.js +1 -59
  49. package/dist/processor/environment-processor.d.ts +124 -0
  50. package/dist/processor/environment-processor.js +1 -0
  51. package/dist/processor/message-formatter-processor.d.ts +51 -50
  52. package/dist/processor/message-formatter-processor.js +1 -66
  53. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  54. package/dist/processor/opentelemetry-processor.js +1 -52
  55. package/dist/processor/redact-processor.d.ts +60 -41
  56. package/dist/processor/redact-processor.js +1 -30
  57. package/dist/processor/sampling-processor.d.ts +112 -0
  58. package/dist/processor/sampling-processor.js +1 -0
  59. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  60. package/dist/reporter/file/json-file-reporter.js +2 -136
  61. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  62. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  63. package/dist/reporter/http/http-reporter.d.ts +40 -36
  64. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  65. package/dist/reporter/http/http-reporter.edge-light.js +2 -651
  66. package/dist/reporter/http/http-reporter.js +1 -13
  67. package/dist/reporter/json/index.browser.d.ts +98 -3
  68. package/dist/reporter/json/index.browser.js +1 -2
  69. package/dist/reporter/json/index.d.ts +51 -3
  70. package/dist/reporter/json/index.js +1 -2
  71. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  72. package/dist/reporter/pretty/index.browser.js +1 -1
  73. package/dist/reporter/pretty/index.d.ts +183 -2
  74. package/dist/reporter/pretty/index.js +1 -1
  75. package/dist/reporter/simple/simple-reporter.server.d.ts +133 -18
  76. package/dist/reporter/simple/simple-reporter.server.js +8 -186
  77. package/dist/wide-event.d.ts +5 -0
  78. package/dist/wide-event.js +1 -0
  79. package/package.json +87 -37
  80. package/dist/constants.d.ts +0 -37
  81. package/dist/interactive/index.d.ts +0 -2
  82. package/dist/interactive/index.js +0 -2
  83. package/dist/interactive/interactive-manager.d.ts +0 -108
  84. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  85. package/dist/packem_shared/AbstractJsonReporter-BaZ33PlE.js +0 -204
  86. package/dist/packem_shared/InteractiveManager-CbE7d1kY.js +0 -172
  87. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
  88. package/dist/packem_shared/JsonReporter-BRw4skd5.js +0 -28
  89. package/dist/packem_shared/JsonReporter-VzgyLEYz.js +0 -58
  90. package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
  91. package/dist/packem_shared/PrettyReporter-DySIXBjQ.js +0 -169
  92. package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
  93. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  94. package/dist/packem_shared/format-label-De49vNPd.js +0 -1193
  95. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
  96. package/dist/packem_shared/index-BomQ3E6J.js +0 -650
  97. package/dist/packem_shared/index-EZ_WSQZS.js +0 -1146
  98. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +0 -141
  99. package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
  100. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  101. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  102. package/dist/pail.browser.d.ts +0 -412
  103. package/dist/pail.server.d.ts +0 -233
  104. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  105. package/dist/progress-bar.d.ts +0 -136
  106. package/dist/progress-bar.js +0 -404
  107. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  108. package/dist/reporter/http/utils/compression.d.ts +0 -7
  109. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  110. package/dist/reporter/http/utils/retry.d.ts +0 -27
  111. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  112. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  113. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  114. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  115. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  116. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  117. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  118. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  119. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  120. package/dist/reporter/utils/format-label.d.ts +0 -3
  121. package/dist/spinner.d.ts +0 -220
  122. package/dist/spinner.js +0 -2150
  123. package/dist/types.d.ts +0 -241
  124. package/dist/utils/ansi-escapes.d.ts +0 -4
  125. package/dist/utils/arrayify.d.ts +0 -2
  126. package/dist/utils/get-longest-badge.d.ts +0 -4
  127. package/dist/utils/get-longest-label.d.ts +0 -4
  128. package/dist/utils/merge-types.d.ts +0 -4
  129. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  130. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  131. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,52 +1 @@
1
- import { trace, context, isSpanContextValid } from '@opentelemetry/api';
2
-
3
- class OpenTelemetryProcessor {
4
- /** Field name for trace ID */
5
- #traceIdField;
6
- /** Field name for span ID */
7
- #spanIdField;
8
- /** Field name for trace flags */
9
- #traceFlagsField;
10
- /** Optional field name to nest all trace fields under */
11
- #traceFieldName;
12
- /**
13
- * Creates a new OpenTelemetryProcessor instance.
14
- * @param options Configuration options for field names and nesting
15
- */
16
- constructor(options = {}) {
17
- this.#traceIdField = options.traceIdFieldName || "trace_id";
18
- this.#spanIdField = options.spanIdFieldName || "span_id";
19
- this.#traceFlagsField = options.traceFlagsFieldName || "trace_flags";
20
- this.#traceFieldName = options.traceFieldName;
21
- }
22
- /**
23
- * Processes log metadata to add OpenTelemetry trace context.
24
- *
25
- * Extracts trace information from the active OpenTelemetry span and adds it
26
- * to the log context. If no valid span is found, the metadata is returned unchanged.
27
- * @param meta The log metadata to process
28
- * @returns The processed metadata with trace context added
29
- */
30
- process(meta) {
31
- const span = trace.getSpan(context.active());
32
- if (!span) {
33
- return meta;
34
- }
35
- const spanContext = span.spanContext();
36
- if (!isSpanContextValid(spanContext)) {
37
- return meta;
38
- }
39
- const fields = {
40
- [this.#spanIdField]: spanContext.spanId,
41
- [this.#traceFlagsField]: `0${spanContext.traceFlags.toString(16)}`,
42
- [this.#traceIdField]: spanContext.traceId
43
- };
44
- const traceData = this.#traceFieldName ? {
45
- [this.#traceFieldName]: fields
46
- } : fields;
47
- meta.context = [...meta.context || [], traceData];
48
- return meta;
49
- }
50
- }
51
-
52
- export { OpenTelemetryProcessor };
1
+ import{trace as i,context as c,isSpanContextValid as n}from"@opentelemetry/api";class l{#s;#e;#r;#t;constructor(t={}){this.#s=t.traceIdFieldName??"trace_id",this.#e=t.spanIdFieldName??"span_id",this.#r=t.traceFlagsFieldName??"trace_flags",this.#t=t.traceFieldName}process(t){const e=i.getSpan(c.active());if(!e)return t;const s=e.spanContext();if(!n(s))return t;const r={[this.#e]:s.spanId,[this.#r]:`0${s.traceFlags.toString(16)}`,[this.#s]:s.traceId},a=this.#t?{[this.#t]:r}:r;return t.context=[...t.context??[],a],t}}export{l as OpenTelemetryProcessor};
@@ -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-Ck_RSjLg.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://www.visulima.com/docs/package/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,30 +1 @@
1
- import { redact, standardRules } from '@visulima/redact';
2
-
3
- class RedactProcessor {
4
- /** The redact function configured with custom rules and options */
5
- #redact;
6
- /**
7
- * Creates a new RedactProcessor instance.
8
- * @param rules Custom redaction rules (uses standardRules if not provided)
9
- * @param options Additional redaction options
10
- */
11
- constructor(rules, options) {
12
- this.#redact = (input) => redact(input, rules || standardRules, options);
13
- }
14
- /**
15
- * Processes log metadata to redact sensitive information.
16
- *
17
- * Applies redaction rules to the message, context, and error properties
18
- * in the log metadata to prevent sensitive data from being logged.
19
- * @param meta The log metadata to process
20
- * @returns The processed metadata with sensitive data redacted
21
- */
22
- process(meta) {
23
- meta.message = this.#redact(meta.message);
24
- meta.context = this.#redact(meta.context);
25
- meta.error = this.#redact(meta.error);
26
- return meta;
27
- }
28
- }
29
-
30
- export { RedactProcessor as default };
1
+ import{redact as e,standardRules as a}from"@visulima/redact";class n{#t;constructor(t,s){const r=t??a;this.#t=o=>e(o,r,s)}process(t){return t.message=this.#t(t.message),t.context=this.#t(t.context),t.error=this.#t(t.error),t}}export{n as default};
@@ -0,0 +1,112 @@
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-Ck_RSjLg.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ /**
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
+ */
20
+ type HeadSamplingConfig = Partial<Record<string, number>>;
21
+ /**
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
+ */
29
+ type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
30
+ /**
31
+ * Sampling processor configuration options.
32
+ */
33
+ interface SamplingProcessorOptions<L extends string = string> {
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>[];
50
+ }
51
+ /**
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
+ */
94
+ declare class SamplingProcessor<L extends string = string> implements Processor<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>;
111
+ }
112
+ export { type HeadSamplingConfig, type SamplingProcessorOptions, type TailSamplingCondition, SamplingProcessor as default };
@@ -0,0 +1 @@
1
+ class e{#r;#t;constructor(t={}){this.#r=t.head??{},this.#t=t.tail??[]}process(t){const r=t.type.level;return this.#s(r)&&!this.#e(t)?{...t,dropped:!0}:t}#s(t){const r=this.#r[t];return r===void 0?!1:r<=0?!0:r>=100?!1:Math.random()*100>=r}#e(t){for(let r=0;r<this.#t.length;r+=1)if(this.#t[r](t))return!0;return!1}}export{e 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-Boj5w068.js";
3
+ import 'safe-stable-stringify';
4
+ import "../../packem_shared/types.d-Ck_RSjLg.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 };
@@ -1,136 +1,2 @@
1
- import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-BaZ33PlE.js';
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
+ import{AbstractJsonReporter as a}from"../../packem_shared/AbstractJsonReporter-CF0KKdQS.js";class r{#t=!0;#s;#e;constructor(t,e){this.#s=t,this.#e=e,this.#s.on("error",s=>{throw s}),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;#r;#i;#h;constructor(t,e=!1,s={}){this.#t=t,this.#s=e,this.#r=s;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.#s||(this.#e=this.#i(this.#t,s),this.#h=new r(this.#e,this.#t))}write(t){if(this.#s){const e=this.#i(this.#t,this.#r),s=new r(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,...h}=t;this.stream=new n(e,s,{compress:"gzip",interval:"1d",size:"10M",...h})}_log(t){this.stream.write(`${t}
2
+ `)}}export{c as JsonFileReporter};