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

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 +355 -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-D_Pb6kpB.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-PVC4ONf2.js +1 -0
  26. package/dist/packem_shared/JsonReporter-BEEmb0W4.js +2 -0
  27. package/dist/packem_shared/JsonReporter-CE-lw7R0.js +1 -0
  28. package/dist/packem_shared/PrettyReporter-CDv9n1Fy.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CuFxJm_o.js +44 -0
  30. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  31. package/dist/packem_shared/abstract-pretty-reporter-BpyhtAoN.js +33 -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-CR3o6VDh.d.ts +47 -0
  35. package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
  36. package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
  37. package/dist/packem_shared/index-Dwp5v97D.js +1 -0
  38. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
  39. package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
  40. package/dist/packem_shared/types.d-BeLumqgD.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-qyZrjy4D.js +1 -0
  44. package/dist/packem_shared/wide-event.d-gb2-ks5w.d.ts +705 -0
  45. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
  46. package/dist/packem_shared/write-stream-Dd4_PTcm.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 +150 -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
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var t=(e,r)=>a(e,"name",{value:r,configurable:!0});var i=Object.defineProperty,n=t((e,r)=>i(e,"name",{value:r,configurable:!0}),"r");const l=n((e,r)=>(r.__write??r.write.bind(r)).call(r,e),"writeStream");export{l as i};
@@ -1,54 +1,56 @@
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
- * Global namespace extension for caller file metadata.
4
- *
5
- * Extends the VisulimaPail.CustomMeta interface to include file information
6
- * that will be added by the CallerProcessor.
7
- */
5
+ * Global namespace extension for caller file metadata.
6
+ *
7
+ * Extends the VisulimaPail.CustomMeta interface to include file information
8
+ * that will be added by the CallerProcessor.
9
+ */
8
10
  declare global {
9
- namespace VisulimaPail {
10
- interface CustomMeta<L> {
11
- /** File information where the log was called from */
12
- file: {
13
- /** Column number in the source file */
14
- column: number | undefined;
15
- /** Line number in the source file */
16
- line: number | undefined;
17
- /** Name/path of the source file */
18
- name: string | undefined;
19
- } | undefined;
20
- }
11
+ namespace VisulimaPail {
12
+ interface CustomMeta<L> {
13
+ /** File information where the log was called from */
14
+ file: {
15
+ /** Column number in the source file */
16
+ column: number | undefined;
17
+ /** Line number in the source file */
18
+ line: number | undefined;
19
+ /** Name/path of the source file */
20
+ name: string | undefined;
21
+ } | undefined;
21
22
  }
23
+ }
22
24
  }
23
25
  /**
24
- * Caller Processor.
25
- *
26
- * A processor that adds file location information to log metadata.
27
- * Uses stack trace analysis to determine the file, line, and column
28
- * where the log call originated from.
29
- * @template L - The log level type
30
- * @example
31
- * ```typescript
32
- * import { createPail } from "@visulima/pail";
33
- * import CallerProcessor from "@visulima/pail/processor/caller";
34
- *
35
- * const logger = createPail({
36
- * processors: [new CallerProcessor()]
37
- * });
38
- *
39
- * logger.info("This log will include file location info");
40
- * // Result includes: file: { name: "...", line: 123, column: 45 }
41
- * ```
42
- */
26
+ * Caller Processor.
27
+ *
28
+ * A processor that adds file location information to log metadata.
29
+ * Uses stack trace analysis to determine the file, line, and column
30
+ * where the log call originated from.
31
+ * @template L - The log level type
32
+ * @example
33
+ * ```typescript
34
+ * import { createPail } from "@visulima/pail";
35
+ * import CallerProcessor from "@visulima/pail/processor/caller";
36
+ *
37
+ * const logger = createPail({
38
+ * processors: [new CallerProcessor()]
39
+ * });
40
+ *
41
+ * logger.info("This log will include file location info");
42
+ * // Result includes: file: { name: "...", line: 123, column: 45 }
43
+ * ```
44
+ */
43
45
  declare class CallerProcessor<L extends string = string> implements Processor<L> {
44
- /**
45
- * Processes log metadata to add caller file information.
46
- *
47
- * Analyzes the call stack to determine the file location where the log
48
- * was called from and adds this information to the metadata.
49
- * @param meta The log metadata to process
50
- * @returns The processed metadata with file location information added
51
- */
52
- process(meta: Meta<L>): Meta<L>;
46
+ /**
47
+ * Processes log metadata to add caller file information.
48
+ *
49
+ * Analyzes the call stack to determine the file location where the log
50
+ * was called from and adds this information to the metadata.
51
+ * @param meta The log metadata to process
52
+ * @returns The processed metadata with file location information added
53
+ */
54
+ process(meta: Meta<L>): Meta<L>;
53
55
  }
54
- export default CallerProcessor;
56
+ export { CallerProcessor as default };
@@ -1,59 +1 @@
1
- const getCallerFilename = () => {
2
- const errorStack = Error.prepareStackTrace;
3
- try {
4
- let result = [];
5
- Error.prepareStackTrace = (_error, stack) => {
6
- const callSitesWithoutCurrent = stack.slice(1);
7
- result = callSitesWithoutCurrent;
8
- return callSitesWithoutCurrent;
9
- };
10
- const callers = result.reduce((accumulator, x) => {
11
- if (x.isNative() || x.getFileName()?.includes("pail/dist")) {
12
- return accumulator;
13
- }
14
- accumulator.push({
15
- columnNumber: x.getColumnNumber(),
16
- fileName: x.getFileName() ?? void 0,
17
- lineNumber: x.getLineNumber()
18
- });
19
- return accumulator;
20
- }, []);
21
- const firstExternalFilePath = callers[0];
22
- if (firstExternalFilePath) {
23
- return {
24
- columnNumber: firstExternalFilePath.columnNumber ?? void 0,
25
- fileName: firstExternalFilePath.fileName,
26
- lineNumber: firstExternalFilePath.lineNumber ?? void 0
27
- };
28
- }
29
- return {
30
- fileName: "anonymous",
31
- lineNumber: void 0
32
- };
33
- } finally {
34
- Error.prepareStackTrace = errorStack;
35
- }
36
- };
37
-
38
- class CallerProcessor {
39
- /**
40
- * Processes log metadata to add caller file information.
41
- *
42
- * Analyzes the call stack to determine the file location where the log
43
- * was called from and adds this information to the metadata.
44
- * @param meta The log metadata to process
45
- * @returns The processed metadata with file location information added
46
- */
47
- // eslint-disable-next-line class-methods-use-this
48
- process(meta) {
49
- const { columnNumber, fileName, lineNumber } = getCallerFilename();
50
- meta.file = {
51
- column: columnNumber,
52
- line: lineNumber,
53
- name: fileName
54
- };
55
- return meta;
56
- }
57
- }
58
-
59
- export { CallerProcessor as default };
1
+ var u=Object.defineProperty;var n=(a,e)=>u(a,"name",{value:e,configurable:!0});var m=Object.defineProperty,o=n((a,e)=>m(a,"name",{value:e,configurable:!0}),"u");const c=o(()=>{const a=Error.prepareStackTrace;try{let e=[];Error.prepareStackTrace=(i,r)=>{const t=r.slice(1);return e=t,t};const l=e.reduce((i,r)=>(r.isNative()||r.getFileName()?.includes("pail/dist")||i.push({columnNumber:r.getColumnNumber(),fileName:r.getFileName()??void 0,lineNumber:r.getLineNumber()}),i),[]).at(0);return l?{columnNumber:l.columnNumber??void 0,fileName:l.fileName,lineNumber:l.lineNumber??void 0}:{fileName:"anonymous",lineNumber:void 0}}finally{Error.prepareStackTrace=a}},"getCallerFilename");var s=Object.defineProperty,N=n((a,e)=>s(a,"name",{value:e,configurable:!0}),"r");class f{static{n(this,"a")}static{N(this,"CallerProcessor")}process(e){const{columnNumber:l,fileName:i,lineNumber:r}=c();return e.file={column:l,line:r,name:i},e}}export{f as default};
@@ -0,0 +1,124 @@
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
+ /**
5
+ * Detected environment information.
6
+ *
7
+ * Contains runtime environment details that are automatically detected
8
+ * from environment variables and process information.
9
+ */
10
+ interface EnvironmentInfo {
11
+ /** Git commit hash or short SHA */
12
+ commit?: string;
13
+ /** Runtime environment (e.g., "production", "development", "test") */
14
+ environment?: string;
15
+ /** Hostname of the machine */
16
+ hostname?: string;
17
+ /** Process ID */
18
+ pid?: number;
19
+ /** Cloud region (e.g., "us-east-1") */
20
+ region?: string;
21
+ /** Application/service name */
22
+ service?: string;
23
+ /** Application version */
24
+ version?: string;
25
+ }
26
+ /**
27
+ * Environment processor configuration options.
28
+ */
29
+ interface EnvironmentProcessorOptions {
30
+ /**
31
+ * Whether to include the hostname. Defaults to false.
32
+ */
33
+ includeHostname?: boolean;
34
+ /**
35
+ * Whether to include the process ID. Defaults to false.
36
+ */
37
+ includePid?: boolean;
38
+ /**
39
+ * Static environment info to use instead of or in addition to auto-detection.
40
+ * Values provided here take precedence over auto-detected values.
41
+ */
42
+ overrides?: Partial<EnvironmentInfo>;
43
+ }
44
+ /**
45
+ * Detects the runtime environment from environment variables.
46
+ *
47
+ * Checks common environment variable patterns used by various hosting
48
+ * platforms (Vercel, AWS, GCP, Heroku, Railway, Fly.io, Render, etc.)
49
+ * to automatically determine service name, version, environment, region,
50
+ * and commit hash.
51
+ * @returns Detected environment information
52
+ */
53
+ declare const detectEnvironment: () => EnvironmentInfo;
54
+ /**
55
+ * Environment Enrichment Processor.
56
+ *
57
+ * Inspired by evlog's automatic environment detection, this processor
58
+ * enriches log metadata with runtime environment information. It auto-detects
59
+ * details like service name, version, environment, region, and commit hash
60
+ * from common environment variables used by popular hosting platforms.
61
+ *
62
+ * The detected info is added to the log's context, making it easier to
63
+ * correlate logs across services and deployments in production.
64
+ * @template L - The log level type
65
+ * @example
66
+ * ```typescript
67
+ * import { createPail } from "@visulima/pail";
68
+ * import EnvironmentProcessor from "@visulima/pail/processor/environment";
69
+ *
70
+ * const logger = createPail({
71
+ * processors: [
72
+ * new EnvironmentProcessor({
73
+ * overrides: { service: "my-api" },
74
+ * includePid: true,
75
+ * }),
76
+ * ],
77
+ * });
78
+ *
79
+ * logger.info("Server started");
80
+ * // Log metadata will include: { __env: { service: "my-api", environment: "production", ... } }
81
+ * ```
82
+ * @example
83
+ * ```typescript
84
+ * // With static configuration only (no auto-detection)
85
+ * new EnvironmentProcessor({
86
+ * overrides: {
87
+ * service: "payment-service",
88
+ * version: "2.1.0",
89
+ * environment: "staging",
90
+ * },
91
+ * });
92
+ * ```
93
+ */
94
+ declare class EnvironmentProcessor<L extends string = string> implements Processor<L> {
95
+ #private;
96
+ /**
97
+ * Creates a new EnvironmentProcessor instance.
98
+ *
99
+ * Auto-detects environment information on construction and merges
100
+ * with any provided overrides. Undefined values in overrides are
101
+ * filtered out so they don't overwrite detected values.
102
+ * @param options Processor configuration options
103
+ */
104
+ constructor(options?: EnvironmentProcessorOptions);
105
+ /**
106
+ * Processes log metadata to add environment information.
107
+ *
108
+ * Adds a `__env` property to the meta containing detected and
109
+ * configured environment details. Each call receives a shallow
110
+ * clone of the environment info to prevent cross-record mutation.
111
+ * @param meta The log metadata to process
112
+ * @returns The processed metadata with environment info added
113
+ */
114
+ process(meta: Meta<L>): Meta<L>;
115
+ /**
116
+ * Returns the detected environment information.
117
+ *
118
+ * Useful for inspecting what environment details were auto-detected.
119
+ * Returns a shallow clone to prevent external mutation.
120
+ * @returns The environment information object
121
+ */
122
+ getEnvironmentInfo(): Readonly<EnvironmentInfo>;
123
+ }
124
+ export { type EnvironmentInfo, type EnvironmentProcessorOptions, EnvironmentProcessor as default, detectEnvironment };
@@ -0,0 +1 @@
1
+ var R=Object.defineProperty;var s=(e,E)=>R(e,"name",{value:E,configurable:!0});var c=Object.defineProperty,I=s((e,E)=>c(e,"name",{value:E,configurable:!0}),"s");const N=I(()=>{if(!process.env)return{};const{env:e}=process,E={commit:e.COMMIT_SHA||e.GIT_COMMIT||e.VERCEL_GIT_COMMIT_SHA?.slice(0,7)||e.RAILWAY_GIT_COMMIT_SHA?.slice(0,7)||e.RENDER_GIT_COMMIT?.slice(0,7)||e.HEROKU_SLUG_COMMIT?.slice(0,7)||e.CF_PAGES_COMMIT_SHA?.slice(0,7)||void 0,environment:e.NODE_ENV||e.ENVIRONMENT||e.APP_ENV||void 0,hostname:e.HOSTNAME||e.HOST||void 0,pid:process.pid,region:e.AWS_REGION||e.VERCEL_REGION||e.FLY_REGION||e.RENDER_REGION||e.CF_REGION||e.GOOGLE_CLOUD_REGION||e.FUNCTION_REGION||void 0,service:e.SERVICE_NAME||e.APP_NAME||e.K_SERVICE||e.GAE_SERVICE||e.FUNCTION_TARGET||e.VERCEL_PROJECT_PRODUCTION_URL||e.FLY_APP_NAME||e.RAILWAY_SERVICE_NAME||e.RENDER_SERVICE_NAME||e.HEROKU_APP_NAME||void 0,version:e.APP_VERSION||e.npm_package_version||e.K_REVISION||e.GAE_VERSION||e.RAILWAY_GIT_COMMIT_SHA?.slice(0,7)||e.RENDER_GIT_COMMIT?.slice(0,7)||void 0};return Object.fromEntries(Object.entries(E).filter(([,t])=>t!==void 0))},"detectEnvironment");class d{static{s(this,"O")}static{I(this,"EnvironmentProcessor")}#e;constructor(E={}){const t=N(),_={};if(E.overrides){const n=Object.entries(E.overrides);for(let o=0;o<n.length;o+=1){const[O,r]=n[o];r!==void 0&&(_[O]=r)}}const i={...t,..._};!E.includePid&&_.pid===void 0&&delete i.pid,!E.includeHostname&&_.hostname===void 0&&delete i.hostname,this.#e=i}process(E){return{...E,envStorage:{...this.#e}}}getEnvironmentInfo(){return{...this.#e}}}export{d as default,N as detectEnvironment};
@@ -1,53 +1,54 @@
1
- import type { FormatterFunction } from "@visulima/fmt";
2
- import type { stringify } from "safe-stable-stringify";
3
- import type { Meta, StringifyAwareProcessor } from "../types.d.ts";
1
+ import { M as Meta, b as StringifyAwareProcessor } from "../packem_shared/types.d-BeLumqgD.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ type FormatterFunction = (argument: any) => string;
4
5
  /**
5
- * Message Formatter Processor.
6
- *
7
- * A processor that formats log messages using the {@link https://www.visulima.com/docs/package/fmt|@visulima/fmt} library.
8
- * Supports custom formatters, string interpolation, and complex object formatting.
9
- * Processes both the main message and contextual data.
10
- * @template L - The log level type
11
- * @example
12
- * ```typescript
13
- * import { createPail } from "@visulima/pail";
14
- * import MessageFormatterProcessor from "@visulima/pail/processor/message-formatter";
15
- *
16
- * const logger = createPail({
17
- * processors: [new MessageFormatterProcessor({
18
- * formatters: {
19
- * user: (value) => `[USER:${value.id}]`
20
- * }
21
- * })]
22
- * });
23
- *
24
- * logger.info("User {user} logged in", { user: { id: 123 } });
25
- * // Output: "User [USER:123] logged in"
26
- * ```
27
- */
6
+ * Message Formatter Processor.
7
+ *
8
+ * A processor that formats log messages using the {@link https://visulima.com/packages/fmt/|@visulima/fmt} library.
9
+ * Supports custom formatters, string interpolation, and complex object formatting.
10
+ * Processes both the main message and contextual data.
11
+ * @template L - The log level type
12
+ * @example
13
+ * ```typescript
14
+ * import { createPail } from "@visulima/pail";
15
+ * import MessageFormatterProcessor from "@visulima/pail/processor/message-formatter";
16
+ *
17
+ * const logger = createPail({
18
+ * processors: [new MessageFormatterProcessor({
19
+ * formatters: {
20
+ * user: (value) => `[USER:${value.id}]`
21
+ * }
22
+ * })]
23
+ * });
24
+ *
25
+ * logger.info("User {user} logged in", { user: { id: 123 } });
26
+ * // Output: "User [USER:123] logged in"
27
+ * ```
28
+ */
28
29
  declare class MessageFormatterProcessor<L extends string = string> implements StringifyAwareProcessor<L> {
29
- #private;
30
- /**
31
- * Creates a new MessageFormatterProcessor instance.
32
- * @param options Configuration options
33
- * @param options.formatters Custom formatters for message interpolation
34
- */
35
- constructor(options?: {
36
- formatters?: Record<string, FormatterFunction>;
37
- });
38
- /**
39
- * Sets the stringify function for object serialization.
40
- * @param function_ The stringify function to use for serializing objects
41
- */
42
- setStringify(function_: typeof stringify): void;
43
- /**
44
- * Processes log metadata to format messages.
45
- *
46
- * Applies string interpolation and custom formatters to the message
47
- * and contextual data in the log metadata.
48
- * @param meta The log metadata to process
49
- * @returns The processed metadata with formatted messages
50
- */
51
- process(meta: Meta<L>): Meta<L>;
30
+ #private;
31
+ /**
32
+ * Creates a new MessageFormatterProcessor instance.
33
+ * @param options Configuration options
34
+ * @param options.formatters Custom formatters for message interpolation
35
+ */
36
+ constructor(options?: {
37
+ formatters?: Record<string, FormatterFunction>;
38
+ });
39
+ /**
40
+ * Sets the stringify function for object serialization.
41
+ * @param function_ The stringify function to use for serializing objects
42
+ */
43
+ setStringify(function_: typeof JSON.stringify): void;
44
+ /**
45
+ * Processes log metadata to format messages.
46
+ *
47
+ * Applies string interpolation and custom formatters to the message
48
+ * and contextual data in the log metadata.
49
+ * @param meta The log metadata to process
50
+ * @returns The processed metadata with formatted messages
51
+ */
52
+ process(meta: Meta<L>): Meta<L>;
52
53
  }
53
- export default MessageFormatterProcessor;
54
+ export { MessageFormatterProcessor as default };
@@ -1,66 +1 @@
1
- import { b as build } from '../packem_shared/index-BomQ3E6J.js';
2
-
3
- class MessageFormatterProcessor {
4
- /** Custom stringify function for object serialization */
5
- #stringify;
6
- /** Custom formatters for message interpolation */
7
- #formatters;
8
- /**
9
- * Creates a new MessageFormatterProcessor instance.
10
- * @param options Configuration options
11
- * @param options.formatters Custom formatters for message interpolation
12
- */
13
- constructor(options = {}) {
14
- this.#formatters = options.formatters;
15
- }
16
- /**
17
- * Sets the stringify function for object serialization.
18
- * @param function_ The stringify function to use for serializing objects
19
- */
20
- setStringify(function_) {
21
- this.#stringify = function_;
22
- }
23
- /**
24
- * Processes log metadata to format messages.
25
- *
26
- * Applies string interpolation and custom formatters to the message
27
- * and contextual data in the log metadata.
28
- * @param meta The log metadata to process
29
- * @returns The processed metadata with formatted messages
30
- */
31
- process(meta) {
32
- const formatter = build({
33
- formatters: this.#formatters});
34
- if (meta.message !== void 0) {
35
- meta.message = this.#format(formatter, meta.message, meta.context ?? []);
36
- }
37
- return meta;
38
- }
39
- /**
40
- * Recursively formats data using the formatter.
41
- *
42
- * Applies string interpolation and formatting to strings, arrays, and objects.
43
- * @param formatter The formatter function to use
44
- * @param data The data to format (string, array, or object)
45
- * @param arguments_ Additional arguments for formatting
46
- * @returns The formatted data
47
- * @private
48
- */
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- #format(formatter, data, arguments_ = []) {
51
- if (typeof data === "string") {
52
- return formatter(data, arguments_);
53
- }
54
- if (typeof data === "object" && data !== null) {
55
- for (const index in data) {
56
- const value = data[index];
57
- if (typeof value === "string" || Array.isArray(value) || typeof value === "object") {
58
- data[index] = this.#format(formatter, value, arguments_);
59
- }
60
- }
61
- }
62
- return data;
63
- }
64
- }
65
-
66
- export { MessageFormatterProcessor as default };
1
+ var A=Object.defineProperty;var m=(e,t)=>A(e,"name",{value:t,configurable:!0});var S=Object.defineProperty,D=m((e,t)=>S(e,"name",{value:t,configurable:!0}),"x"),C=Object.defineProperty,$=D((e,t)=>C(e,"name",{value:t,configurable:!0}),"h"),N=Object.defineProperty,g=$((e,t)=>N(e,"name",{value:t,configurable:!0}),"g$1");const p=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["darkblue","#00008b"],["darkcyan","#008b8b"],["darkgoldenrod","#b8860b"],["darkgray","#a9a9a9"],["darkgreen","#006400"],["darkgrey","#a9a9a9"],["darkkhaki","#bdb76b"],["darkmagenta","#8b008b"],["darkolivegreen","#556b2f"],["darkorange","#ff8c00"],["darkorchid","#9932cc"],["darkred","#8b0000"],["darksalmon","#e9967a"],["darkseagreen","#8fbc8f"],["darkslateblue","#483d8b"],["darkslategray","#2f4f4f"],["darkslategrey","#2f4f4f"],["darkturquoise","#00ced1"],["darkviolet","#9400d3"],["deeppink","#ff1493"],["deepskyblue","#00bfff"],["dimgray","#696969"],["dimgrey","#696969"],["dodgerblue","#1e90ff"],["firebrick","#b22222"],["floralwhite","#fffaf0"],["forestgreen","#228b22"],["fuchsia","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["honeydew","#f0fff0"],["hotpink","#ff69b4"],["indianred","#cd5c5c"],["indigo","#4b0082"],["ivory","#fffff0"],["khaki","#f0e68c"],["lavender","#e6e6fa"],["lavenderblush","#fff0f5"],["lawngreen","#7cfc00"],["lemonchiffon","#fffacd"],["lightblue","#add8e6"],["lightcoral","#f08080"],["lightcyan","#e0ffff"],["lightgoldenrodyellow","#fafad2"],["lightgray","#d3d3d3"],["lightgreen","#90ee90"],["lightgrey","#d3d3d3"],["lightpink","#ffb6c1"],["lightsalmon","#ffa07a"],["lightseagreen","#20b2aa"],["lightskyblue","#87cefa"],["lightslategray","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["maroon","#800000"],["mediumaquamarine","#66cdaa"],["mediumblue","#0000cd"],["mediumorchid","#ba55d3"],["mediumpurple","#9370db"],["mediumseagreen","#3cb371"],["mediumslateblue","#7b68ee"],["mediumspringgreen","#00fa9a"],["mediumturquoise","#48d1cc"],["mediumvioletred","#c71585"],["midnightblue","#191970"],["mintcream","#f5fffa"],["mistyrose","#ffe4e1"],["moccasin","#ffe4b5"],["navajowhite","#ffdead"],["navy","#000080"],["oldlace","#fdf5e6"],["olive","#808000"],["olivedrab","#6b8e23"],["orange","#ffa500"],["orangered","#ff4500"],["orchid","#da70d6"],["palegoldenrod","#eee8aa"],["palegreen","#98fb98"],["paleturquoise","#afeeee"],["palevioletred","#db7093"],["papayawhip","#ffefd5"],["peachpuff","#ffdab9"],["peru","#cd853f"],["pink","#ffc0cb"],["plum","#dda0dd"],["powderblue","#b0e0e6"],["purple","#800080"],["rebeccapurple","#663399"],["red","#ff0000"],["rosybrown","#bc8f8f"],["royalblue","#4169e1"],["saddlebrown","#8b4513"],["salmon","#fa8072"],["sandybrown","#f4a460"],["seagreen","#2e8b57"],["seashell","#fff5ee"],["sienna","#a0522d"],["silver","#c0c0c0"],["skyblue","#87ceeb"],["slateblue","#6a5acd"],["slategray","#708090"],["slategrey","#708090"],["snow","#fffafa"],["springgreen","#00ff7f"],["steelblue","#4682b4"],["tan","#d2b48c"],["teal","#008080"],["thistle","#d8bfd8"],["tomato","#ff6347"],["turquoise","#40e0d0"],["violet","#ee82ee"],["wheat","#f5deb3"],["white","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]),M=/^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i,P=/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i,j=/^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,F=/^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,k=g(()=>({__proto__:null,backgroundColor:null,color:null,fontStyle:null,fontWeight:null,textDecorationColor:null,textDecorationLine:[]}),"getDefaultCss"),w=/\s+/,h=g(e=>{p.has(e)&&(e=p.get(e));const t=M.exec(e);if(t)return[Number.parseInt(t[1],16),Number.parseInt(t[2],16),Number.parseInt(t[3],16)];const r=P.exec(e);if(r)return[Number.parseInt(`${r[1]}${r[1]}`,16),Number.parseInt(`${r[2]}${r[2]}`,16),Number.parseInt(`${r[3]}${r[3]}`,16)];const i=j.exec(e);if(i)return[Math.round(Math.max(0,Math.min(255,Number(i[1])))),Math.round(Math.max(0,Math.min(255,Number(i[2])))),Math.round(Math.max(0,Math.min(255,Number(i[3]))))];const l=F.exec(e);if(l){let a=Number(l[1])%360;a<0&&(a+=360);const f=Math.max(0,Math.min(100,Number(l[2])))/100,n=Math.max(0,Math.min(100,Number(l[3])))/100,c=(1-Math.abs(2*n-1))*f,u=c*(1-Math.abs(a/60%2-1)),o=n-c/2;let d,s,b;return a<60?{0:d,1:s,2:b}=[c,u,0]:a<120?{0:d,1:s,2:b}=[u,c,0]:a<180?{0:d,1:s,2:b}=[0,c,u]:a<240?{0:d,1:s,2:b}=[0,u,c]:a<300?{0:d,1:s,2:b}=[u,0,c]:{0:d,1:s,2:b}=[c,0,u],[Math.round((d+o)*255),Math.round((s+o)*255),Math.round((b+o)*255)]}return null},"parseCssColor"),y=g((e,t)=>e?.[0]===t?.[0]&&e?.[1]===t?.[1]&&e?.[2]===t?.[2],"colorEquals"),L=g(e=>{if(typeof e!="string")return k();const t=k(),r=[];let i=!1,l=null,a=0,f="";for(const n of e){if(n==="(")a+=1;else if(a>0)n===")"&&(a-=1);else if(i){if(n===";"){const c=f.trim();c!==""&&r.push([l,c]),l=null,f="",i=!1;continue}}else if(n===":"){l=f.trim(),f="",i=!0;continue}f+=n}if(i&&a===0){const n=f.trim();n!==""&&r.push([l,n]),l=null,f=""}for(const{0:n,1:c}of r)switch(n){case"background-color":{c!=null&&(t.backgroundColor=c);break}case"color":{c!=null&&(t.color=c);break}case"font-style":{["italic","oblique","oblique 14deg"].includes(c)&&(t.fontStyle="italic");break}case"font-weight":{c==="bold"&&(t.fontWeight=c);break}case"text-decoration":{t.textDecorationColor=null,t.textDecorationLine=[];const u=c.split(w);for(const o of u){const d=h(o);d!=null?t.textDecorationColor=d:["line-through","overline","underline"].includes(o)&&t.textDecorationLine.push(o)}break}case"text-decoration-color":{const u=h(c);u!=null&&(t.textDecorationColor=u);break}case"text-decoration-line":{t.textDecorationLine=[];const u=c.split(w);for(const o of u)["line-through","overline","underline"].includes(o)&&t.textDecorationLine.push(o);break}}return t},"parseCss"),q=g((e,t)=>{t=t??k();let r="";if(!y(e.backgroundColor,t.backgroundColor))if(e.backgroundColor==null)r+="\x1B[49m";else switch(e.backgroundColor){case"black":{r+="\x1B[40m";break}case"blue":{r+="\x1B[44m";break}case"cyan":{r+="\x1B[46m";break}case"green":{r+="\x1B[42m";break}case"magenta":{r+="\x1B[45m";break}case"red":{r+="\x1B[41m";break}case"white":{r+="\x1B[47m";break}case"yellow":{r+="\x1B[43m";break}default:if(Array.isArray(e.backgroundColor)){const{0:i,1:l,2:a}=e.backgroundColor;r+=`\x1B[48;2;${String(i)};${String(l)};${String(a)}m`}else{const i=h(e.backgroundColor);if(i===null)r+="\x1B[49m";else{const{0:l,1:a,2:f}=i;r+=`\x1B[48;2;${String(l)};${String(a)};${String(f)}m`}}}if(!y(e.color,t.color))if(e.color==null)r+="\x1B[39m";else switch(e.color){case"black":{r+="\x1B[30m";break}case"blue":{r+="\x1B[34m";break}case"cyan":{r+="\x1B[36m";break}case"green":{r+="\x1B[32m";break}case"magenta":{r+="\x1B[35m";break}case"red":{r+="\x1B[31m";break}case"white":{r+="\x1B[37m";break}case"yellow":{r+="\x1B[33m";break}default:if(Array.isArray(e.color)){const{0:i,1:l,2:a}=e.color;r+=`\x1B[38;2;${String(i)};${String(l)};${String(a)}m`}else{const i=h(e.color);if(i===null)r+="\x1B[39m";else{const{0:l,1:a,2:f}=i;r+=`\x1B[38;2;${String(l)};${String(a)};${String(f)}m`}}}if(e.fontWeight!==t.fontWeight&&(r+=e.fontWeight==="bold"?"\x1B[1m":"\x1B[22m"),e.fontStyle!==t.fontStyle&&(r+=e.fontStyle==="italic"?"\x1B[3m":"\x1B[23m"),!y(e.textDecorationColor,t.textDecorationColor))if(e.textDecorationColor==null)r+="\x1B[59m";else{const{0:i,1:l,2:a}=e.textDecorationColor;r+=`\x1B[58;2;${String(i)};${String(l)};${String(a)}m`}return e.textDecorationLine.includes("line-through")!==t.textDecorationLine.includes("line-through")&&(r+=e.textDecorationLine.includes("line-through")?"\x1B[9m":"\x1B[29m"),e.textDecorationLine.includes("overline")!==t.textDecorationLine.includes("overline")&&(r+=e.textDecorationLine.includes("overline")?"\x1B[53m":"\x1B[55m"),e.textDecorationLine.includes("underline")!==t.textDecorationLine.includes("underline")&&(r+=e.textDecorationLine.includes("underline")?"\x1B[4m":"\x1B[24m"),r},"cssToAnsi");var O=Object.defineProperty,x=$((e,t)=>O(e,"name",{value:t,configurable:!0}),"u");const E=x(e=>{try{return JSON.stringify(e)}catch{return'"[Circular]"'}},"tryStringify"),v="%".codePointAt(0),I="s".codePointAt(0),W="d".codePointAt(0),T="f".codePointAt(0),_="i".codePointAt(0),J="O".codePointAt(0),z="o".codePointAt(0),G="j".codePointAt(0),H="c".codePointAt(0),K=x((e,t=[],r={})=>{if(typeof e!="string"&&typeof e!="object"||e===null)throw new TypeError(`fmt must be a string or object, got ${e===null?"null":typeof e}`);const i=r.stringify??E,l=1;if(typeof e=="object"){const o=t.length+l;if(o===1)return"{}";const d=Array.from({length:o});d[0]=i(e);for(let s=1;s<o;s+=1)d[s]=i(t[s-l]);return d.join(" ")}if(t.length===0)return e;let a="",f=1-l,n=-1,c=!1,u;for(let o=0;o<e.length;){if(e.codePointAt(o)===v&&o+1<e.length){n=n>-1?n:0;const d=e.codePointAt(o+1);if(d===void 0){f+=1;break}switch(d){case H:{if(globalThis.window===void 0){const s=L(t[f]);n<o&&(a+=e.slice(n,o));const b=q(s,u);a+=b,b!==""&&(c=!0,u=s)}n=o+2,o+=1;break}case W:case T:{if(f>=t.length||t[f]==null)break;n<o&&(a+=e.slice(n,o));const s=t[f];a+=(typeof s=="symbol"?Number.NaN:Number(s)).toString(),n=o+2,o+=1;break}case _:{if(f>=t.length||t[f]==null)break;n<o&&(a+=e.slice(n,o));const s=t[f];a+=Math.floor(typeof s=="symbol"?Number.NaN:Number(s)).toString(),n=o+2,o+=1;break}case G:case J:case z:{if(f>=t.length||t[f]===void 0)break;n<o&&(a+=e.slice(n,o));const s=t[f],b=typeof s;if(b==="string"){a+=`'${s}'`,n=o+2,o+=1;break}if(b==="function"){a+=s.name?`[Function: ${s.name}]`:"[Function: <anonymous>]",n=o+2,o+=1;break}a+=i(s),n=o+2,o+=1;break}case v:{n<o&&(a+=e.slice(n,o)),a+="%",n=o+2,o+=1,f-=1;break}case I:{if(f>=t.length)break;n<o&&(a+=e.slice(n,o)),a+=typeof t[f]=="object"?i(t[f]):String(t[f]),n=o+2,o+=1;break}default:typeof r.formatters?.[d]=="function"&&(n<o&&(a+=e.slice(n,o)),a+=r.formatters[d](t[f]),n=o+2,o+=1)}f+=1}o+=1}return n===-1?e:(n<e.length&&(a+=e.slice(n)),c&&(a+="\x1B[0m"),a)},"format"),Q=x((e={})=>{const t={};return typeof e.formatters=="object"&&Object.entries(e.formatters).forEach(([r,i])=>{if(r.length===0)throw new Error(`Formatter %${r} has no characters`);if(r.length>1)throw new Error(`Formatter %${r} has more than one character`);if(typeof i!="function")throw new TypeError(`Formatter for %${r} is not a function`);const l=r.codePointAt(0);if(l===void 0)throw new Error(`${r}.codePointAt(0) failed to return a value, please report this issue`);t[l]=i}),(r,i=[],l={})=>K(r,i,{...l,formatters:t})},"build");var R=Object.defineProperty,B=m((e,t)=>R(e,"name",{value:t,configurable:!0}),"s");class V{static{m(this,"p")}static{B(this,"MessageFormatterProcessor")}#e;#r;#t;constructor(t={}){this.#r=t.formatters}setStringify(t){this.#e=t}process(t){this.#t===void 0&&(this.#t=Q({formatters:this.#r,stringify:B(i=>this.#e?this.#e(i):JSON.stringify(i),"stringify")}));const r=this.#t;return t.message!==void 0&&(t.message=this.#o(r,t.message,t.context??[])),t}#o(t,r,i=[]){if(typeof r=="string")return t(r,i);if(typeof r=="object"&&r!==null){const l=r,a=Object.keys(l);for(let f=0;f<a.length;f+=1){const n=a[f],c=l[n];(typeof c=="string"||Array.isArray(c)||typeof c=="object")&&(l[n]=this.#o(t,c,i))}}return r}}export{V as default};
@@ -1,70 +1,73 @@
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
- * 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;
5
+ * Configuration options for the OpenTelemetry processor.
6
+ */
7
+ interface OpenTelemetryProcessorOptions {
8
+ /**
9
+ * Field name for the span ID. Defaults to 'span_id'
10
+ */
11
+ spanIdFieldName?: string;
12
+ /**
13
+ * If specified, all trace fields will be nested under this key
14
+ */
15
+ traceFieldName?: string;
16
+ /**
17
+ * Field name for the trace flags. Defaults to 'trace_flags'
18
+ */
19
+ traceFlagsFieldName?: string;
20
+ /**
21
+ * Field name for the trace ID. Defaults to 'trace_id'
22
+ */
23
+ traceIdFieldName?: string;
22
24
  }
23
25
  /**
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>;
26
+ * OpenTelemetry Processor.
27
+ *
28
+ * A processor that adds OpenTelemetry trace context to log metadata.
29
+ * Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span
30
+ * and adds them to the log context for distributed tracing correlation.
31
+ * @template L - The log level type
32
+ * @example
33
+ * ```typescript
34
+ * import { createPail } from "@visulima/pail";
35
+ * import { OpenTelemetryProcessor } from "@visulima/pail/processor/opentelemetry";
36
+ *
37
+ * const logger = createPail({
38
+ * processors: [new OpenTelemetryProcessor()]
39
+ * });
40
+ *
41
+ * logger.info("Processing request");
42
+ * // Context includes: { trace_id: "...", span_id: "...", trace_flags: "01" }
43
+ * ```
44
+ * @example
45
+ * ```typescript
46
+ * // With custom field names
47
+ * const logger = createPail({
48
+ * processors: [new OpenTelemetryProcessor({
49
+ * traceFieldName: "trace",
50
+ * traceIdFieldName: "traceId",
51
+ * spanIdFieldName: "spanId"
52
+ * })]
53
+ * });
54
+ * ```
55
+ */
56
+ declare class OpenTelemetryProcessor<L extends string = string> implements Processor<L> {
57
+ #private;
58
+ /**
59
+ * Creates a new OpenTelemetryProcessor instance.
60
+ * @param options Configuration options for field names and nesting
61
+ */
62
+ constructor(options?: OpenTelemetryProcessorOptions);
63
+ /**
64
+ * Processes log metadata to add OpenTelemetry trace context.
65
+ *
66
+ * Extracts trace information from the active OpenTelemetry span and adds it
67
+ * to the log context. If no valid span is found, the metadata is returned unchanged.
68
+ * @param meta The log metadata to process
69
+ * @returns The processed metadata with trace context added
70
+ */
71
+ process(meta: Meta<L>): Meta<L>;
70
72
  }
73
+ export { OpenTelemetryProcessor, OpenTelemetryProcessorOptions };