@visulima/pail 4.0.0-alpha.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +23 -38
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,70 +1,74 @@
1
- import type { Meta, Processor } from "../types.d.ts";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-bWnqHJKL.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ import 'type-fest';
2
5
  /**
3
- * Configuration options for the OpenTelemetry processor.
4
- */
5
- export interface OpenTelemetryProcessorOptions {
6
- /**
7
- * Field name for the span ID. Defaults to 'span_id'
8
- */
9
- spanIdFieldName?: string;
10
- /**
11
- * If specified, all trace fields will be nested under this key
12
- */
13
- traceFieldName?: string;
14
- /**
15
- * Field name for the trace flags. Defaults to 'trace_flags'
16
- */
17
- traceFlagsFieldName?: string;
18
- /**
19
- * Field name for the trace ID. Defaults to 'trace_id'
20
- */
21
- traceIdFieldName?: string;
6
+ * Configuration options for the OpenTelemetry processor.
7
+ */
8
+ interface OpenTelemetryProcessorOptions {
9
+ /**
10
+ * Field name for the span ID. Defaults to 'span_id'
11
+ */
12
+ spanIdFieldName?: string;
13
+ /**
14
+ * If specified, all trace fields will be nested under this key
15
+ */
16
+ traceFieldName?: string;
17
+ /**
18
+ * Field name for the trace flags. Defaults to 'trace_flags'
19
+ */
20
+ traceFlagsFieldName?: string;
21
+ /**
22
+ * Field name for the trace ID. Defaults to 'trace_id'
23
+ */
24
+ traceIdFieldName?: string;
22
25
  }
23
26
  /**
24
- * OpenTelemetry Processor.
25
- *
26
- * A processor that adds OpenTelemetry trace context to log metadata.
27
- * Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span
28
- * and adds them to the log context for distributed tracing correlation.
29
- * @template L - The log level type
30
- * @example
31
- * ```typescript
32
- * import { createPail } from "@visulima/pail";
33
- * import { OpenTelemetryProcessor } from "@visulima/pail/processor/opentelemetry";
34
- *
35
- * const logger = createPail({
36
- * processors: [new OpenTelemetryProcessor()]
37
- * });
38
- *
39
- * logger.info("Processing request");
40
- * // Context includes: { trace_id: "...", span_id: "...", trace_flags: "01" }
41
- * ```
42
- * @example
43
- * ```typescript
44
- * // With custom field names
45
- * const logger = createPail({
46
- * processors: [new OpenTelemetryProcessor({
47
- * traceFieldName: "trace",
48
- * traceIdFieldName: "traceId",
49
- * spanIdFieldName: "spanId"
50
- * })]
51
- * });
52
- * ```
53
- */
54
- export declare class OpenTelemetryProcessor<L extends string = string> implements Processor<L> {
55
- #private;
56
- /**
57
- * Creates a new OpenTelemetryProcessor instance.
58
- * @param options Configuration options for field names and nesting
59
- */
60
- constructor(options?: OpenTelemetryProcessorOptions);
61
- /**
62
- * Processes log metadata to add OpenTelemetry trace context.
63
- *
64
- * Extracts trace information from the active OpenTelemetry span and adds it
65
- * to the log context. If no valid span is found, the metadata is returned unchanged.
66
- * @param meta The log metadata to process
67
- * @returns The processed metadata with trace context added
68
- */
69
- process(meta: Meta<L>): Meta<L>;
27
+ * OpenTelemetry Processor.
28
+ *
29
+ * A processor that adds OpenTelemetry trace context to log metadata.
30
+ * Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span
31
+ * and adds them to the log context for distributed tracing correlation.
32
+ * @template L - The log level type
33
+ * @example
34
+ * ```typescript
35
+ * import { createPail } from "@visulima/pail";
36
+ * import { OpenTelemetryProcessor } from "@visulima/pail/processor/opentelemetry";
37
+ *
38
+ * const logger = createPail({
39
+ * processors: [new OpenTelemetryProcessor()]
40
+ * });
41
+ *
42
+ * logger.info("Processing request");
43
+ * // Context includes: { trace_id: "...", span_id: "...", trace_flags: "01" }
44
+ * ```
45
+ * @example
46
+ * ```typescript
47
+ * // With custom field names
48
+ * const logger = createPail({
49
+ * processors: [new OpenTelemetryProcessor({
50
+ * traceFieldName: "trace",
51
+ * traceIdFieldName: "traceId",
52
+ * spanIdFieldName: "spanId"
53
+ * })]
54
+ * });
55
+ * ```
56
+ */
57
+ declare class OpenTelemetryProcessor<L extends string = string> implements Processor<L> {
58
+ #private;
59
+ /**
60
+ * Creates a new OpenTelemetryProcessor instance.
61
+ * @param options Configuration options for field names and nesting
62
+ */
63
+ constructor(options?: OpenTelemetryProcessorOptions);
64
+ /**
65
+ * Processes log metadata to add OpenTelemetry trace context.
66
+ *
67
+ * Extracts trace information from the active OpenTelemetry span and adds it
68
+ * to the log context. If no valid span is found, the metadata is returned unchanged.
69
+ * @param meta The log metadata to process
70
+ * @returns The processed metadata with trace context added
71
+ */
72
+ process(meta: Meta<L>): Meta<L>;
70
73
  }
74
+ export { OpenTelemetryProcessor, OpenTelemetryProcessorOptions };
@@ -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,102 @@
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-bWnqHJKL.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ import 'type-fest';
3
5
  /**
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
- */
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
+ */
20
+ type Censor = (value: unknown, path: string | undefined) => unknown;
21
+ type StringAnonymize = {
22
+ key: string;
23
+ pattern: RegExp | string;
24
+ replacement?: Censor | string;
25
+ };
26
+ type Anonymize = {
27
+ /**
28
+ * When `true`, the rule is also applied to nested string values (NLP / regex based),
29
+ * not just to matching object keys.
30
+ */
31
+ deep?: boolean;
32
+ /** The key (or wildcard pattern, or NLP type) to match. Case-insensitive. */
33
+ key: string;
34
+ /** Optional regular expression matched against nested string values. */
35
+ pattern?: RegExp | string;
36
+ /**
37
+ * When `true`, the matching key is deleted from the output object instead of being
38
+ * replaced with `replacement`. Ignored for array elements and string-anonymizer matches.
39
+ */
40
+ remove?: boolean;
41
+ /**
42
+ * The value (or {@link Censor} function) to put in place of a match. Defaults to
43
+ * the `&lt;KEY&gt;` placeholder when omitted.
44
+ */
45
+ replacement?: unknown;
46
+ };
47
+ type Rules = (Anonymize | StringAnonymize | number | string)[];
48
+ type RedactOptions = {
49
+ exclude?: (number | string)[];
50
+ logger?: {
51
+ debug: (message?: unknown, ...optionalParameters: unknown[]) => void;
52
+ };
53
+ };
54
+ /**
55
+ * Credential / secret rules: API keys, AWS keys, bearer/JWT/Slack tokens, crypto wallets,
56
+ * basic-auth strings, and the broad key-name rules (`auth`, `password`, `secret`, ...).
57
+ *
58
+ * These are the safest default rules — they target high-entropy or unambiguous shapes — and are
59
+ * what most logger-scrubbing use cases need.
60
+ */
61
+ /**
62
+ * Redact Processor.
63
+ *
64
+ * A processor that redacts sensitive information from log messages and metadata.
65
+ * Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
66
+ * passwords, API keys, credit card numbers, and other PII.
67
+ * @template L - The log level type
68
+ * @example
69
+ * ```typescript
70
+ * import { createPail } from "@visulima/pail";
71
+ * import RedactProcessor from "@visulima/pail/processor/redact";
72
+ *
73
+ * const logger = createPail({
74
+ * processors: [new RedactProcessor()]
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
+ */
26
84
  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>;
85
+ #private;
86
+ /**
87
+ * Creates a new RedactProcessor instance.
88
+ * @param rules Custom redaction rules (uses standardRules if not provided)
89
+ * @param options Additional redaction options
90
+ */
91
+ constructor(rules?: Rules, options?: RedactOptions);
92
+ /**
93
+ * Processes log metadata to redact sensitive information.
94
+ *
95
+ * Applies redaction rules to the message, context, and error properties
96
+ * in the log metadata to prevent sensitive data from being logged.
97
+ * @param meta The log metadata to process
98
+ * @returns The processed metadata with sensitive data redacted
99
+ */
100
+ process(meta: Meta<L>): Meta<L>;
43
101
  }
44
- export default RedactProcessor;
102
+ 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};
@@ -1,111 +1,113 @@
1
- import type { Meta, Processor } from "../types.d.ts";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-bWnqHJKL.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ import 'type-fest';
2
5
  /**
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
- */
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
+ */
18
21
  type HeadSamplingConfig = Partial<Record<string, number>>;
19
22
  /**
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
- */
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
+ */
27
30
  type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
28
31
  /**
29
- * Sampling processor configuration options.
30
- */
32
+ * Sampling processor configuration options.
33
+ */
31
34
  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>[];
35
+ /**
36
+ * Head sampling rates per log level.
37
+ *
38
+ * A map of log level to sampling percentage (0-100).
39
+ * Levels not specified default to 100 (keep all).
40
+ * Set to 0 to drop all logs at that level.
41
+ */
42
+ head?: HeadSamplingConfig;
43
+ /**
44
+ * Tail sampling conditions.
45
+ *
46
+ * An array of condition functions that can force-keep a log entry
47
+ * even if it was dropped by head sampling. If any condition returns true,
48
+ * the log is kept.
49
+ */
50
+ tail?: TailSamplingCondition<L>[];
48
51
  }
49
52
  /**
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
- */
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
+ */
92
95
  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>;
96
+ #private;
97
+ /**
98
+ * Creates a new SamplingProcessor instance.
99
+ * @param options Sampling configuration options
100
+ */
101
+ constructor(options?: SamplingProcessorOptions<L>);
102
+ /**
103
+ * Processes log metadata to apply sampling rules.
104
+ *
105
+ * First evaluates head sampling (random per-level), then checks tail
106
+ * sampling conditions. If a log is dropped, the meta is marked with
107
+ * `dropped: true` so reporters can skip it.
108
+ * @param meta The log metadata to process
109
+ * @returns The processed metadata, potentially marked as dropped
110
+ */
111
+ process(meta: Meta<L>): Meta<L>;
109
112
  }
110
- export default SamplingProcessor;
111
- export type { HeadSamplingConfig, SamplingProcessorOptions, TailSamplingCondition };
113
+ export { type HeadSamplingConfig, type SamplingProcessorOptions, type TailSamplingCondition, SamplingProcessor as default };
@@ -1,59 +1 @@
1
- class SamplingProcessor {
2
- #headRates;
3
- #tailConditions;
4
- /**
5
- * Creates a new SamplingProcessor instance.
6
- * @param options Sampling configuration options
7
- */
8
- constructor(options = {}) {
9
- this.#headRates = options.head ?? {};
10
- this.#tailConditions = options.tail ?? [];
11
- }
12
- /**
13
- * Processes log metadata to apply sampling rules.
14
- *
15
- * First evaluates head sampling (random per-level), then checks tail
16
- * sampling conditions. If a log is dropped, the meta is marked with
17
- * `__dropped: true` so reporters can skip it.
18
- * @param meta The log metadata to process
19
- * @returns The processed metadata, potentially marked as dropped
20
- */
21
- process(meta) {
22
- const level = meta.type.level;
23
- if (this.#shouldDrop(level) && !this.#shouldForceKeep(meta)) {
24
- return { ...meta, dropped: true };
25
- }
26
- return meta;
27
- }
28
- /**
29
- * Evaluates head sampling for the given log level.
30
- * @returns true if the log should be dropped
31
- */
32
- #shouldDrop(level) {
33
- const rate = this.#headRates[level];
34
- if (rate === void 0) {
35
- return false;
36
- }
37
- if (rate <= 0) {
38
- return true;
39
- }
40
- if (rate >= 100) {
41
- return false;
42
- }
43
- return Math.random() * 100 >= rate;
44
- }
45
- /**
46
- * Evaluates tail sampling conditions.
47
- * @returns true if any condition forces keeping the log
48
- */
49
- #shouldForceKeep(meta) {
50
- for (const condition of this.#tailConditions) {
51
- if (condition(meta)) {
52
- return true;
53
- }
54
- }
55
- return false;
56
- }
57
- }
58
-
59
- export { SamplingProcessor as default };
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};