@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
@@ -0,0 +1 @@
1
+ const o=new Set(["alert","critical","emergency","error"]),n=r=>{const e=console;return o.has(r)?e.__error??console.error:r==="warning"?e.__warn??console.warn:r==="trace"?e.__trace??console.trace:e.__log??console.log};export{n as t};
@@ -0,0 +1 @@
1
+ const a=new Set(["alert","critical","emergency","error","trace","warning"]),e=t=>a.has(t),c=(t,r)=>(r.__write??r.write.bind(r)).call(r,t);export{c as a,e as r};
@@ -1,54 +1,57 @@
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
- * 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
- */
6
+ * Global namespace extension for caller file metadata.
7
+ *
8
+ * Extends the VisulimaPail.CustomMeta interface to include file information
9
+ * that will be added by the CallerProcessor.
10
+ */
8
11
  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
- }
12
+ namespace VisulimaPail {
13
+ interface CustomMeta<L> {
14
+ /** File information where the log was called from */
15
+ file: {
16
+ /** Column number in the source file */
17
+ column: number | undefined;
18
+ /** Line number in the source file */
19
+ line: number | undefined;
20
+ /** Name/path of the source file */
21
+ name: string | undefined;
22
+ } | undefined;
21
23
  }
24
+ }
22
25
  }
23
26
  /**
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
- */
27
+ * Caller Processor.
28
+ *
29
+ * A processor that adds file location information to log metadata.
30
+ * Uses stack trace analysis to determine the file, line, and column
31
+ * where the log call originated from.
32
+ * @template L - The log level type
33
+ * @example
34
+ * ```typescript
35
+ * import { createPail } from "@visulima/pail";
36
+ * import CallerProcessor from "@visulima/pail/processor/caller";
37
+ *
38
+ * const logger = createPail({
39
+ * processors: [new CallerProcessor()]
40
+ * });
41
+ *
42
+ * logger.info("This log will include file location info");
43
+ * // Result includes: file: { name: "...", line: 123, column: 45 }
44
+ * ```
45
+ */
43
46
  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>;
47
+ /**
48
+ * Processes log metadata to add caller file information.
49
+ *
50
+ * Analyzes the call stack to determine the file location where the log
51
+ * was called from and adds this information to the metadata.
52
+ * @param meta The log metadata to process
53
+ * @returns The processed metadata with file location information added
54
+ */
55
+ process(meta: Meta<L>): Meta<L>;
53
56
  }
54
- export default CallerProcessor;
57
+ 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
+ const u=()=>{const i=Error.prepareStackTrace;try{let l=[];Error.prepareStackTrace=(n,e)=>{const m=e.slice(1);return l=m,m};const r=l.reduce((n,e)=>(e.isNative()||e.getFileName()?.includes("pail/dist")||n.push({columnNumber:e.getColumnNumber(),fileName:e.getFileName()??void 0,lineNumber:e.getLineNumber()}),n),[]).at(0);return r?{columnNumber:r.columnNumber??void 0,fileName:r.fileName,lineNumber:r.lineNumber??void 0}:{fileName:"anonymous",lineNumber:void 0}}finally{Error.prepareStackTrace=i}};class a{process(l){const{columnNumber:r,fileName:n,lineNumber:e}=u();return l.file={column:r,line:e,name:n},l}}export{a as default};
@@ -1,124 +1,125 @@
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
- * Detected environment information.
4
- *
5
- * Contains runtime environment details that are automatically detected
6
- * from environment variables and process information.
7
- */
6
+ * Detected environment information.
7
+ *
8
+ * Contains runtime environment details that are automatically detected
9
+ * from environment variables and process information.
10
+ */
8
11
  interface EnvironmentInfo {
9
- /** Git commit hash or short SHA */
10
- commit?: string;
11
- /** Runtime environment (e.g., "production", "development", "test") */
12
- environment?: string;
13
- /** Hostname of the machine */
14
- hostname?: string;
15
- /** Process ID */
16
- pid?: number;
17
- /** Cloud region (e.g., "us-east-1") */
18
- region?: string;
19
- /** Application/service name */
20
- service?: string;
21
- /** Application version */
22
- version?: string;
12
+ /** Git commit hash or short SHA */
13
+ commit?: string;
14
+ /** Runtime environment (e.g., "production", "development", "test") */
15
+ environment?: string;
16
+ /** Hostname of the machine */
17
+ hostname?: string;
18
+ /** Process ID */
19
+ pid?: number;
20
+ /** Cloud region (e.g., "us-east-1") */
21
+ region?: string;
22
+ /** Application/service name */
23
+ service?: string;
24
+ /** Application version */
25
+ version?: string;
23
26
  }
24
27
  /**
25
- * Environment processor configuration options.
26
- */
28
+ * Environment processor configuration options.
29
+ */
27
30
  interface EnvironmentProcessorOptions {
28
- /**
29
- * Whether to include the hostname. Defaults to false.
30
- */
31
- includeHostname?: boolean;
32
- /**
33
- * Whether to include the process ID. Defaults to false.
34
- */
35
- includePid?: boolean;
36
- /**
37
- * Static environment info to use instead of or in addition to auto-detection.
38
- * Values provided here take precedence over auto-detected values.
39
- */
40
- overrides?: Partial<EnvironmentInfo>;
31
+ /**
32
+ * Whether to include the hostname. Defaults to false.
33
+ */
34
+ includeHostname?: boolean;
35
+ /**
36
+ * Whether to include the process ID. Defaults to false.
37
+ */
38
+ includePid?: boolean;
39
+ /**
40
+ * Static environment info to use instead of or in addition to auto-detection.
41
+ * Values provided here take precedence over auto-detected values.
42
+ */
43
+ overrides?: Partial<EnvironmentInfo>;
41
44
  }
42
45
  /**
43
- * Detects the runtime environment from environment variables.
44
- *
45
- * Checks common environment variable patterns used by various hosting
46
- * platforms (Vercel, AWS, GCP, Heroku, Railway, Fly.io, Render, etc.)
47
- * to automatically determine service name, version, environment, region,
48
- * and commit hash.
49
- * @returns Detected environment information
50
- */
46
+ * Detects the runtime environment from environment variables.
47
+ *
48
+ * Checks common environment variable patterns used by various hosting
49
+ * platforms (Vercel, AWS, GCP, Heroku, Railway, Fly.io, Render, etc.)
50
+ * to automatically determine service name, version, environment, region,
51
+ * and commit hash.
52
+ * @returns Detected environment information
53
+ */
51
54
  declare const detectEnvironment: () => EnvironmentInfo;
52
55
  /**
53
- * Environment Enrichment Processor.
54
- *
55
- * Inspired by evlog's automatic environment detection, this processor
56
- * enriches log metadata with runtime environment information. It auto-detects
57
- * details like service name, version, environment, region, and commit hash
58
- * from common environment variables used by popular hosting platforms.
59
- *
60
- * The detected info is added to the log's context, making it easier to
61
- * correlate logs across services and deployments in production.
62
- * @template L - The log level type
63
- * @example
64
- * ```typescript
65
- * import { createPail } from "@visulima/pail";
66
- * import EnvironmentProcessor from "@visulima/pail/processor/environment";
67
- *
68
- * const logger = createPail({
69
- * processors: [
70
- * new EnvironmentProcessor({
71
- * overrides: { service: "my-api" },
72
- * includePid: true,
73
- * }),
74
- * ],
75
- * });
76
- *
77
- * logger.info("Server started");
78
- * // Log metadata will include: { __env: { service: "my-api", environment: "production", ... } }
79
- * ```
80
- * @example
81
- * ```typescript
82
- * // With static configuration only (no auto-detection)
83
- * new EnvironmentProcessor({
84
- * overrides: {
85
- * service: "payment-service",
86
- * version: "2.1.0",
87
- * environment: "staging",
88
- * },
89
- * });
90
- * ```
91
- */
56
+ * Environment Enrichment Processor.
57
+ *
58
+ * Inspired by evlog's automatic environment detection, this processor
59
+ * enriches log metadata with runtime environment information. It auto-detects
60
+ * details like service name, version, environment, region, and commit hash
61
+ * from common environment variables used by popular hosting platforms.
62
+ *
63
+ * The detected info is added to the log's context, making it easier to
64
+ * correlate logs across services and deployments in production.
65
+ * @template L - The log level type
66
+ * @example
67
+ * ```typescript
68
+ * import { createPail } from "@visulima/pail";
69
+ * import EnvironmentProcessor from "@visulima/pail/processor/environment";
70
+ *
71
+ * const logger = createPail({
72
+ * processors: [
73
+ * new EnvironmentProcessor({
74
+ * overrides: { service: "my-api" },
75
+ * includePid: true,
76
+ * }),
77
+ * ],
78
+ * });
79
+ *
80
+ * logger.info("Server started");
81
+ * // Log metadata will include: { __env: { service: "my-api", environment: "production", ... } }
82
+ * ```
83
+ * @example
84
+ * ```typescript
85
+ * // With static configuration only (no auto-detection)
86
+ * new EnvironmentProcessor({
87
+ * overrides: {
88
+ * service: "payment-service",
89
+ * version: "2.1.0",
90
+ * environment: "staging",
91
+ * },
92
+ * });
93
+ * ```
94
+ */
92
95
  declare class EnvironmentProcessor<L extends string = string> implements Processor<L> {
93
- #private;
94
- /**
95
- * Creates a new EnvironmentProcessor instance.
96
- *
97
- * Auto-detects environment information on construction and merges
98
- * with any provided overrides. Undefined values in overrides are
99
- * filtered out so they don't overwrite detected values.
100
- * @param options Processor configuration options
101
- */
102
- constructor(options?: EnvironmentProcessorOptions);
103
- /**
104
- * Processes log metadata to add environment information.
105
- *
106
- * Adds a `__env` property to the meta containing detected and
107
- * configured environment details. Each call receives a shallow
108
- * clone of the environment info to prevent cross-record mutation.
109
- * @param meta The log metadata to process
110
- * @returns The processed metadata with environment info added
111
- */
112
- process(meta: Meta<L>): Meta<L>;
113
- /**
114
- * Returns the detected environment information.
115
- *
116
- * Useful for inspecting what environment details were auto-detected.
117
- * Returns a shallow clone to prevent external mutation.
118
- * @returns The environment information object
119
- */
120
- getEnvironmentInfo(): Readonly<EnvironmentInfo>;
96
+ #private;
97
+ /**
98
+ * Creates a new EnvironmentProcessor instance.
99
+ *
100
+ * Auto-detects environment information on construction and merges
101
+ * with any provided overrides. Undefined values in overrides are
102
+ * filtered out so they don't overwrite detected values.
103
+ * @param options Processor configuration options
104
+ */
105
+ constructor(options?: EnvironmentProcessorOptions);
106
+ /**
107
+ * Processes log metadata to add environment information.
108
+ *
109
+ * Adds a `__env` property to the meta containing detected and
110
+ * configured environment details. Each call receives a shallow
111
+ * clone of the environment info to prevent cross-record mutation.
112
+ * @param meta The log metadata to process
113
+ * @returns The processed metadata with environment info added
114
+ */
115
+ process(meta: Meta<L>): Meta<L>;
116
+ /**
117
+ * Returns the detected environment information.
118
+ *
119
+ * Useful for inspecting what environment details were auto-detected.
120
+ * Returns a shallow clone to prevent external mutation.
121
+ * @returns The environment information object
122
+ */
123
+ getEnvironmentInfo(): Readonly<EnvironmentInfo>;
121
124
  }
122
- export { detectEnvironment };
123
- export default EnvironmentProcessor;
124
- export type { EnvironmentInfo, EnvironmentProcessorOptions };
125
+ export { type EnvironmentInfo, type EnvironmentProcessorOptions, EnvironmentProcessor as default, detectEnvironment };
@@ -1,78 +1 @@
1
- const detectEnvironment = () => {
2
- if (!process.env) {
3
- return {};
4
- }
5
- const { env } = process;
6
- const info = {
7
- // Commit hash
8
- commit: env.COMMIT_SHA || env.GIT_COMMIT || env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7) || env.RAILWAY_GIT_COMMIT_SHA?.slice(0, 7) || env.RENDER_GIT_COMMIT?.slice(0, 7) || env.HEROKU_SLUG_COMMIT?.slice(0, 7) || env.CF_PAGES_COMMIT_SHA?.slice(0, 7) || void 0,
9
- // Environment / Node env
10
- environment: env.NODE_ENV || env.ENVIRONMENT || env.APP_ENV || void 0,
11
- // Hostname
12
- hostname: env.HOSTNAME || env.HOST || void 0,
13
- // PID
14
- pid: process.pid,
15
- // Region (including GCP Cloud Functions FUNCTION_REGION and GOOGLE_CLOUD_REGION)
16
- region: env.AWS_REGION || env.VERCEL_REGION || env.FLY_REGION || env.RENDER_REGION || env.CF_REGION || env.GOOGLE_CLOUD_REGION || env.FUNCTION_REGION || void 0,
17
- // Service name - check common platform variables (including GCP Cloud Run / App Engine)
18
- service: env.SERVICE_NAME || env.APP_NAME || env.K_SERVICE || env.GAE_SERVICE || env.FUNCTION_TARGET || env.VERCEL_PROJECT_PRODUCTION_URL || env.FLY_APP_NAME || env.RAILWAY_SERVICE_NAME || env.RENDER_SERVICE_NAME || env.HEROKU_APP_NAME || void 0,
19
- // Version (including GCP Cloud Run K_REVISION and App Engine GAE_VERSION)
20
- version: env.APP_VERSION || env.npm_package_version || env.K_REVISION || env.GAE_VERSION || env.RAILWAY_GIT_COMMIT_SHA?.slice(0, 7) || env.RENDER_GIT_COMMIT?.slice(0, 7) || void 0
21
- };
22
- return Object.fromEntries(Object.entries(info).filter(([, v]) => v !== void 0));
23
- };
24
- class EnvironmentProcessor {
25
- #envInfo;
26
- /**
27
- * Creates a new EnvironmentProcessor instance.
28
- *
29
- * Auto-detects environment information on construction and merges
30
- * with any provided overrides. Undefined values in overrides are
31
- * filtered out so they don't overwrite detected values.
32
- * @param options Processor configuration options
33
- */
34
- constructor(options = {}) {
35
- const detected = detectEnvironment();
36
- const cleanOverrides = {};
37
- if (options.overrides) {
38
- for (const [key, value] of Object.entries(options.overrides)) {
39
- if (value !== void 0) {
40
- cleanOverrides[key] = value;
41
- }
42
- }
43
- }
44
- const merged = { ...detected, ...cleanOverrides };
45
- if (!options.includePid && cleanOverrides.pid === void 0) {
46
- delete merged.pid;
47
- }
48
- if (!options.includeHostname && cleanOverrides.hostname === void 0) {
49
- delete merged.hostname;
50
- }
51
- this.#envInfo = merged;
52
- }
53
- /**
54
- * Processes log metadata to add environment information.
55
- *
56
- * Adds a `__env` property to the meta containing detected and
57
- * configured environment details. Each call receives a shallow
58
- * clone of the environment info to prevent cross-record mutation.
59
- * @param meta The log metadata to process
60
- * @returns The processed metadata with environment info added
61
- */
62
- process(meta) {
63
- const enriched = { ...meta, envStorage: { ...this.#envInfo } };
64
- return enriched;
65
- }
66
- /**
67
- * Returns the detected environment information.
68
- *
69
- * Useful for inspecting what environment details were auto-detected.
70
- * Returns a shallow clone to prevent external mutation.
71
- * @returns The environment information object
72
- */
73
- getEnvironmentInfo() {
74
- return { ...this.#envInfo };
75
- }
76
- }
77
-
78
- export { EnvironmentProcessor as default, detectEnvironment };
1
+ const O=()=>{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(([,i])=>i!==void 0))};class R{#e;constructor(E={}){const i=O(),_={};if(E.overrides){const t=Object.entries(E.overrides);for(let o=0;o<t.length;o+=1){const[n,I]=t[o];I!==void 0&&(_[n]=I)}}const s={...i,..._};!E.includePid&&_.pid===void 0&&delete s.pid,!E.includeHostname&&_.hostname===void 0&&delete s.hostname,this.#e=s}process(E){return{...E,envStorage:{...this.#e}}}getEnvironmentInfo(){return{...this.#e}}}export{R as default,O as detectEnvironment};
@@ -1,52 +1,62 @@
1
- import type { FormatterFunction } from "@visulima/fmt";
2
- import type { Meta, StringifyAwareProcessor } from "../types.d.ts";
1
+ import { M as Meta, b as StringifyAwareProcessor } from "../packem_shared/types.d-bWnqHJKL.js";
2
+ import '@visulima/colorize';
3
+ import '@visulima/interactive-manager';
4
+ import 'type-fest';
3
5
  /**
4
- * Message Formatter Processor.
5
- *
6
- * A processor that formats log messages using the {@link https://www.visulima.com/docs/package/fmt|@visulima/fmt} library.
7
- * Supports custom formatters, string interpolation, and complex object formatting.
8
- * Processes both the main message and contextual data.
9
- * @template L - The log level type
10
- * @example
11
- * ```typescript
12
- * import { createPail } from "@visulima/pail";
13
- * import MessageFormatterProcessor from "@visulima/pail/processor/message-formatter";
14
- *
15
- * const logger = createPail({
16
- * processors: [new MessageFormatterProcessor({
17
- * formatters: {
18
- * user: (value) => `[USER:${value.id}]`
19
- * }
20
- * })]
21
- * });
22
- *
23
- * logger.info("User {user} logged in", { user: { id: 123 } });
24
- * // Output: "User [USER:123] logged in"
25
- * ```
26
- */
6
+ * A custom specifier formatter: receives the matched argument and returns its string form.
7
+ */
8
+ type FormatterFunction = (argument: any) => string;
9
+ /**
10
+ * Internal map of custom formatters keyed by the specifier character's codepoint, as produced by
11
+ * {@link build}.
12
+ */
13
+ /**
14
+ * Message Formatter Processor.
15
+ *
16
+ * A processor that formats log messages using the {@link https://visulima.com/packages/fmt/|@visulima/fmt} library.
17
+ * Supports custom formatters, string interpolation, and complex object formatting.
18
+ * Processes both the main message and contextual data.
19
+ * @template L - The log level type
20
+ * @example
21
+ * ```typescript
22
+ * import { createPail } from "@visulima/pail";
23
+ * import MessageFormatterProcessor from "@visulima/pail/processor/message-formatter";
24
+ *
25
+ * const logger = createPail({
26
+ * processors: [new MessageFormatterProcessor({
27
+ * formatters: {
28
+ * user: (value) => `[USER:${value.id}]`
29
+ * }
30
+ * })]
31
+ * });
32
+ *
33
+ * logger.info("User {user} logged in", { user: { id: 123 } });
34
+ * // Output: "User [USER:123] logged in"
35
+ * ```
36
+ */
27
37
  declare class MessageFormatterProcessor<L extends string = string> implements StringifyAwareProcessor<L> {
28
- #private;
29
- /**
30
- * Creates a new MessageFormatterProcessor instance.
31
- * @param options Configuration options
32
- * @param options.formatters Custom formatters for message interpolation
33
- */
34
- constructor(options?: {
35
- formatters?: Record<string, FormatterFunction>;
36
- });
37
- /**
38
- * Sets the stringify function for object serialization.
39
- * @param function_ The stringify function to use for serializing objects
40
- */
41
- setStringify(function_: typeof JSON.stringify): void;
42
- /**
43
- * Processes log metadata to format messages.
44
- *
45
- * Applies string interpolation and custom formatters to the message
46
- * and contextual data in the log metadata.
47
- * @param meta The log metadata to process
48
- * @returns The processed metadata with formatted messages
49
- */
50
- process(meta: Meta<L>): Meta<L>;
38
+ #private;
39
+ /**
40
+ * Creates a new MessageFormatterProcessor instance.
41
+ * @param options Configuration options
42
+ * @param options.formatters Custom formatters for message interpolation
43
+ */
44
+ constructor(options?: {
45
+ formatters?: Record<string, FormatterFunction>;
46
+ });
47
+ /**
48
+ * Sets the stringify function for object serialization.
49
+ * @param function_ The stringify function to use for serializing objects
50
+ */
51
+ setStringify(function_: typeof JSON.stringify): void;
52
+ /**
53
+ * Processes log metadata to format messages.
54
+ *
55
+ * Applies string interpolation and custom formatters to the message
56
+ * and contextual data in the log metadata.
57
+ * @param meta The log metadata to process
58
+ * @returns The processed metadata with formatted messages
59
+ */
60
+ process(meta: Meta<L>): Meta<L>;
51
61
  }
52
- export default MessageFormatterProcessor;
62
+ export { MessageFormatterProcessor as default };