@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
@@ -1,189 +1,11 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
1
+ var F=Object.defineProperty;var x=(o,e)=>F(o,"name",{value:e,configurable:!0});import{createRequire as V}from"node:module";import A from"@visulima/colorize";import{A as G,u as W,i as H,O as K,b as Q,s as Z,o as d,c as J,a as N,p as R,d as U,B as X,G as S}from"../../packem_shared/abstract-pretty-reporter-BpyhtAoN.js";const le=V(import.meta.url),Y=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{stdout:z,stderr:D}=Y;var ee=Object.defineProperty,B=x((o,e)=>ee(o,"name",{value:e,configurable:!0}),"b");const{bgGrey:te,bold:I,cyan:se,green:re,greenBright:ie,grey:a,red:T,underline:k,white:ae}=A,oe=/[\\/]pail[\\/]dist/,_=B(o=>!oe.test(o),"pailFileFilter");class ue extends G{static{x(this,"SimpleReporter")}static{B(this,"SimpleReporter")}#t;#s;#r;#a=!1;#i;#e;constructor(e={}){const{error:n,inspect:p,...i}=e;super({uppercase:{label:!0,...i.uppercase},...i}),this.#i={...W,indent:void 0,...p},this.#e={...n,color:{fileLine:re,hint:se,marker:T,message:T,method:ie,title:T}},this.#t=z,this.#s=D}setStdout(e){this.#t=e}setStderr(e){this.#s=e}setInteractiveManager(e){this.#r=e}setIsInteractive(e){this.#a=e}log(e){const n=this.formatMessage(e),p=e.type.level,i=["error","trace","warn"].includes(p)?"stderr":"stdout",h=i==="stderr"?this.#s:this.#t;this.#a&&this.#r!==void 0&&h.isTTY?this.#r.update(i,n.split(`
2
+ `),0):H(`${n}
3
+ `,h)}formatMessage(e){const{columns:n}=K();let p=n;typeof this.styles.messageLength=="number"&&(p=this.styles.messageLength);const{badge:i,context:h,date:c,error:j,file:u,groups:g,label:m,message:f,prefix:y,repeated:M,scope:$,suffix:b,traceError:v,type:L}=e,{color:w}=this.loggerTypes[L.name],E=w?A[w]:ae,l=g.map(()=>" ").join(""),t=[];if(g.length>0&&t.push(`${l+a(`[${g.at(-1)??""}]`)} `),c&&t.push(`${a(this.styles.dateFormatter(typeof c=="string"?new Date(c):c))} `),i)t.push(I(E(i)));else{const s=Q(this.loggerTypes);s.length>0&&t.push(a(" ".repeat(s.length)))}const O=Z(this.loggerTypes),C=d(O);if(m){const s=d(m),r=Math.max(0,C-s);t.push(`${I(E(J(m,this.styles)))} `," ".repeat(r))}else t.push(" ".repeat(C+1));M&&t.push(`${te.white(`[${String(M)}x]`)} `),Array.isArray($)&&$.length>0&&t.push(`${a(`[${$.join(" > ")}]`)} `),y&&t.push(`${a(`[${this.styles.underline.prefix?k(y):y}]`)} `);const P=d(t.join(""));if(f!==N){const s=typeof f=="string"?f:R(f,this.#i);t.push(l+U(s,{trim:!1,width:p-3,wrapMode:X.STRICT_WIDTH}))}if(h){let s=!1;t.push(...h.map(r=>{if(r instanceof Error)return s=!0,`
2
4
 
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
5
+ ${S(r,{...this.#e,filterStacktrace:_,prefix:l})}`;if(typeof r=="object")return` ${R(r,this.#i)}`;const q=(s?`
4
6
 
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
7
+ `:" ")+String(r);return s=!1,q}))}if(j&&t.push(S(j,{...this.#e,filterStacktrace:_,prefix:l})),v&&t.push(`
6
8
 
7
- const {
8
- stdout,
9
- stderr
10
- } = __cjs_getProcess;
11
- import colorize, { red, greenBright, cyan, green, grey, bold, white, bgGrey, underline } from '@visulima/colorize';
12
- import { d as defaultInspectorConfig, f as formatLabel, i as inspect, r as renderError } from '../../packem_shared/format-label-De49vNPd.js';
13
- import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from '../../packem_shared/index-EZ_WSQZS.js';
14
- import { E as EMPTY_SYMBOL } from '../../packem_shared/constants-omsTHUWB.js';
15
- import { A as AbstractPrettyReporter, g as getLongestBadge } from '../../packem_shared/abstract-pretty-reporter-Di_sdm2r.js';
16
- import { g as getLongestLabel } from '../../packem_shared/get-longest-label-C9PWeyKq.js';
17
- import { w as writeStream } from '../../packem_shared/write-stream-BG8fhcs3.js';
18
-
19
- const pailFileFilter = (line) => !/[\\/]pail[\\/]dist/.test(line);
20
- class SimpleReporter extends AbstractPrettyReporter {
21
- #stdout;
22
- #stderr;
23
- #interactiveManager;
24
- #interactive = false;
25
- #inspectOptions;
26
- #errorOptions;
27
- constructor(options = {}) {
28
- const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
29
- super({
30
- uppercase: {
31
- label: true,
32
- ...rest.uppercase
33
- },
34
- ...rest
35
- });
36
- this.#inspectOptions = { ...defaultInspectorConfig, indent: void 0, ...inspectOptions };
37
- this.#errorOptions = {
38
- ...errorOptions,
39
- color: {
40
- fileLine: green,
41
- hint: cyan,
42
- marker: red,
43
- message: red,
44
- method: greenBright,
45
- title: red
46
- }
47
- };
48
- this.#stdout = stdout;
49
- this.#stderr = stderr;
50
- }
51
- setStdout(stdout_) {
52
- this.#stdout = stdout_;
53
- }
54
- setStderr(stderr_) {
55
- this.#stderr = stderr_;
56
- }
57
- setInteractiveManager(manager) {
58
- this.#interactiveManager = manager;
59
- }
60
- setIsInteractive(interactive) {
61
- this.#interactive = interactive;
62
- }
63
- log(meta) {
64
- const message = this.formatMessage(meta);
65
- const logLevel = meta.type.level;
66
- const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
67
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
68
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
69
- this.#interactiveManager.update(streamType, message.split("\n"), 0);
70
- } else {
71
- writeStream(`${message}
72
- `, stream);
73
- }
74
- }
75
- // eslint-disable-next-line sonarjs/cognitive-complexity
76
- formatMessage(data) {
77
- const { columns } = terminalSize();
78
- let size = columns;
79
- if (typeof this.styles.messageLength === "number") {
80
- size = this.styles.messageLength;
81
- }
82
- const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
83
- const { color } = this.loggerTypes[type.name];
84
- const colorized = color ? colorize[color] : white;
85
- const groupSpaces = groups.map(() => " ").join("");
86
- const items = [];
87
- if (groups.length > 0) {
88
- items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
89
- }
90
- if (date) {
91
- items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
92
- }
93
- if (badge) {
94
- items.push(bold(colorized(badge)));
95
- } else {
96
- const longestBadge = getLongestBadge(this.loggerTypes);
97
- if (longestBadge.length > 0) {
98
- items.push(grey(" ".repeat(longestBadge.length)));
99
- }
100
- }
101
- const longestLabel = getLongestLabel(this.loggerTypes);
102
- const longestWidth = getStringWidth(longestLabel);
103
- if (label) {
104
- const labelWidth = getStringWidth(label);
105
- const pad = Math.max(0, longestWidth - labelWidth);
106
- items.push(`${bold(colorized(formatLabel(label, this.styles)))} `, " ".repeat(pad));
107
- } else {
108
- items.push(" ".repeat(longestWidth + 1));
109
- }
110
- if (repeated) {
111
- items.push(`${bgGrey.white(`[${repeated}x]`)} `);
112
- }
113
- if (Array.isArray(scope) && scope.length > 0) {
114
- items.push(`${grey(`[${scope.join(" > ")}]`)} `);
115
- }
116
- if (prefix) {
117
- items.push(`${grey(`[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `);
118
- }
119
- const titleSize = getStringWidth(items.join(""));
120
- if (message !== EMPTY_SYMBOL) {
121
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
122
- items.push(
123
- groupSpaces + wordWrap(formattedMessage, {
124
- trim: false,
125
- width: size - 3,
126
- wrapMode: WrapMode.STRICT_WIDTH
127
- })
128
- );
129
- }
130
- if (context) {
131
- let hasError = false;
132
- items.push(
133
- ...context.map((value) => {
134
- if (value instanceof Error) {
135
- hasError = true;
136
- return `
137
-
138
- ${renderError(value, {
139
- ...this.#errorOptions,
140
- filterStacktrace: pailFileFilter,
141
- prefix: groupSpaces
142
- })}`;
143
- }
144
- if (typeof value === "object") {
145
- return ` ${inspect(value, this.#inspectOptions)}`;
146
- }
147
- const newValue = (hasError ? "\n\n" : " ") + value;
148
- hasError = false;
149
- return newValue;
150
- })
151
- );
152
- }
153
- if (error) {
154
- items.push(
155
- renderError(error, {
156
- ...this.#errorOptions,
157
- filterStacktrace: pailFileFilter,
158
- prefix: groupSpaces
159
- })
160
- );
161
- }
162
- if (traceError) {
163
- items.push(
164
- `
165
-
166
- ${renderError(traceError, {
167
- ...this.#errorOptions,
168
- filterStacktrace: pailFileFilter,
169
- hideErrorCauseCodeView: true,
170
- hideErrorCodeView: true,
171
- hideErrorErrorsCodeView: true,
172
- hideMessage: true,
173
- prefix: groupSpaces
174
- })}`
175
- );
176
- }
177
- if (suffix) {
178
- items.push(` ${groupSpaces}${grey(this.styles.underline.suffix ? underline(suffix) : suffix)}`);
179
- }
180
- if (file) {
181
- const fileMessage = file.name + (file.line ? `:${file.line}` : "");
182
- const callerPad = Math.max(0, titleSize - getStringWidth("Caller: "));
183
- items.push("\n", grey("Caller: "), " ".repeat(callerPad), fileMessage, "\n");
184
- }
185
- return items.join("");
186
- }
187
- }
188
-
189
- export { SimpleReporter };
9
+ ${S(v,{...this.#e,filterStacktrace:_,hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0,hideMessage:!0,prefix:l})}`),b&&t.push(` ${l}${a(this.styles.underline.suffix?k(b):b)}`),u){const s=(u.name??"")+(u.line?`:${String(u.line)}`:""),r=Math.max(0,P-d("Caller: "));t.push(`
10
+ `,a("Caller: ")," ".repeat(r),s,`
11
+ `)}return t.join("")}}export{ue as SimpleReporter};
@@ -0,0 +1,5 @@
1
+ export { R as RequestLogEntry, S as SerializedError, W as WideEvent, a as WideEventFinishOptions, b as WideEventLevel, c as WideEventOptions, d as createWideEvent } from "./packem_shared/wide-event.d-gb2-ks5w.js";
2
+ import "./packem_shared/types.d-BeLumqgD.js";
3
+ import 'safe-stable-stringify';
4
+ import '@visulima/colorize';
5
+ import '@visulima/interactive-manager';
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var u=(s,t)=>l(s,"name",{value:t,configurable:!0});var g=Object.defineProperty,n=u((s,t)=>g(s,"name",{value:t,configurable:!0}),"o");const d={debug:0,error:3,info:1,warn:2},v={debug:"debug",error:"error",info:"info",warn:"warn"},c=n((s,t)=>{const e={...s},a=Object.keys(t);for(let i=0;i<a.length;i+=1){const r=a[i],o=t[r],h=e[r];o!==null&&typeof o=="object"&&!Array.isArray(o)&&h!==null&&typeof h=="object"&&!Array.isArray(h)?e[r]=c(h,o):e[r]=o}return e},"deepMerge"),E=n(s=>s<1e3?`${String(s)}ms`:`${(s/1e3).toFixed(2)}s`,"formatDuration"),m=n(s=>{const t={message:s.message,name:s.name};s.stack&&(t.stack=s.stack);const e=s;return e.status!==void 0?t.status=e.status:e.statusCode!==void 0&&(t.status=e.statusCode),e.data!==void 0&&(t.data=e.data),s.cause instanceof Error&&(t.cause=m(s.cause)),t},"serializeError");class p{static{u(this,"WideEvent")}static{n(this,"WideEvent")}name;autoEmit;data;emitted;attachedError;level;pail;requestLogs;service;startTime;status;timestamp;_type;constructor(t){this.name=t.name,this.pail=t.pail,this.data={},this.startTime=performance.now(),this.timestamp=new Date().toISOString(),this.emitted=!1,this.autoEmit=t.autoEmit??!0,this._type=t.type??"info",this.level="info",this.requestLogs=[],this.service=t.service}debug(t,e){return this.addLogEntry("debug",t,e)}emit(t){if(this.emitted)return;this.emitted=!0;const e=Math.round(performance.now()-this.startTime),a=this.attachedError?"error":this.level,i=t??v[a],r={duration:E(e),duration_ms:e,event:this.name,timestamp:this.timestamp,...this.data};this.service&&(r.service=this.service),this.status!==void 0&&(r.status=this.status),this.attachedError&&(r.error=m(this.attachedError)),this.requestLogs.length>0&&(r.requestLogs=this.requestLogs);const o=this.pail[i];o({message:r})}error(t,e,a){return e&&(this.attachedError=e),this.addLogEntry("error",t,a)}finish(t){t?.status!==void 0&&(this.status=t.status),t?.error&&(this.attachedError=t.error),this.emit()}getData(){return this.data}getLevel(){return this.attachedError?"error":this.level}getRequestLogs(){return this.requestLogs}info(t,e){return this.addLogEntry("info",t,e)}set(t){return this.data=c(this.data,t),this}setError(t){return this.attachedError=t,this}setStatus(t){return this.status=t,this}warn(t,e){return this.addLogEntry("warn",t,e)}[Symbol.dispose](){this.autoEmit&&!this.emitted&&this.emit()}addLogEntry(t,e,a){const i={level:t,message:e,timestamp:new Date().toISOString()};return a&&(i.context=a),this.requestLogs.push(i),this.escalateLevel(t),this}escalateLevel(t){(d[t]??0)>(d[this.level]??0)&&(this.level=t)}}const y=n(s=>new p(s),"createWideEvent");export{p as WideEvent,y as createWideEvent};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@visulima/pail",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.20",
4
4
  "description": "Highly configurable Logger for Node.js, Edge and Browser.",
5
5
  "keywords": [
6
- "ansi",
7
6
  "anolilab",
7
+ "ansi",
8
8
  "browser",
9
9
  "browser-logger",
10
10
  "callsite",
@@ -27,8 +27,8 @@
27
27
  "json",
28
28
  "json-logger",
29
29
  "json-logging",
30
- "log level",
31
30
  "log",
31
+ "log level",
32
32
  "log-cleaner",
33
33
  "log-rotation",
34
34
  "log4j",
@@ -37,11 +37,10 @@
37
37
  "logger",
38
38
  "logging",
39
39
  "node",
40
- "stream",
41
- "pretty",
42
40
  "node-logger",
43
41
  "pail",
44
42
  "pino",
43
+ "pretty",
45
44
  "pretty-error",
46
45
  "pretty-log",
47
46
  "print",
@@ -49,16 +48,15 @@
49
48
  "redact",
50
49
  "rotating-log",
51
50
  "show error",
51
+ "stream",
52
52
  "timer",
53
53
  "universal",
54
54
  "visulima",
55
55
  "warning-logging",
56
56
  "winston"
57
57
  ],
58
- "homepage": "https://www.visulima.com/docs/package/pail",
59
- "bugs": {
60
- "url": "https://github.com/visulima/visulima/issues"
61
- },
58
+ "homepage": "https://visulima.com/packages/pail/",
59
+ "bugs": "https://github.com/visulima/visulima/issues",
62
60
  "repository": {
63
61
  "type": "git",
64
62
  "url": "git+https://github.com/visulima/visulima.git",
@@ -84,11 +82,11 @@
84
82
  "type": "module",
85
83
  "exports": {
86
84
  ".": {
87
- "browser": "./dist/index.browser.js",
88
85
  "import": {
89
86
  "types": "./dist/index.server.d.ts",
90
87
  "default": "./dist/index.server.js"
91
- }
88
+ },
89
+ "browser": "./dist/index.browser.js"
92
90
  },
93
91
  "./browser": {
94
92
  "types": "./dist/index.browser.d.ts",
@@ -114,6 +112,18 @@
114
112
  "types": "./dist/processor/opentelemetry-processor.d.ts",
115
113
  "default": "./dist/processor/opentelemetry-processor.js"
116
114
  },
115
+ "./processor/sampling": {
116
+ "types": "./dist/processor/sampling-processor.d.ts",
117
+ "default": "./dist/processor/sampling-processor.js"
118
+ },
119
+ "./processor/environment": {
120
+ "types": "./dist/processor/environment-processor.d.ts",
121
+ "default": "./dist/processor/environment-processor.js"
122
+ },
123
+ "./error": {
124
+ "types": "./dist/error.d.ts",
125
+ "default": "./dist/error.js"
126
+ },
117
127
  "./reporter/file": {
118
128
  "types": "./dist/reporter/file/json-file-reporter.d.ts",
119
129
  "default": "./dist/reporter/file/json-file-reporter.js"
@@ -131,11 +141,11 @@
131
141
  }
132
142
  },
133
143
  "./reporter/json": {
134
- "browser": "./dist/reporter/json/index.browser.js",
135
144
  "import": {
136
145
  "types": "./dist/reporter/json/index.d.ts",
137
146
  "default": "./dist/reporter/json/index.js"
138
- }
147
+ },
148
+ "browser": "./dist/reporter/json/index.browser.js"
139
149
  },
140
150
  "./server/reporter/pretty": {
141
151
  "import": {
@@ -150,11 +160,11 @@
150
160
  }
151
161
  },
152
162
  "./reporter/pretty": {
153
- "browser": "./dist/reporter/pretty/index.browser.js",
154
163
  "import": {
155
164
  "types": "./dist/reporter/pretty/index.d.ts",
156
165
  "default": "./dist/reporter/pretty/index.js"
157
- }
166
+ },
167
+ "browser": "./dist/reporter/pretty/index.browser.js"
158
168
  },
159
169
  "./reporter/simple": {
160
170
  "types": "./dist/reporter/simple/simple-reporter.server.d.ts",
@@ -165,6 +175,10 @@
165
175
  "default": "./dist/reporter/http/abstract-http-reporter.js"
166
176
  },
167
177
  "./reporter/http": {
178
+ "import": {
179
+ "types": "./dist/reporter/http/http-reporter.d.ts",
180
+ "default": "./dist/reporter/http/http-reporter.js"
181
+ },
168
182
  "edge-light": {
169
183
  "types": "./dist/reporter/http/http-reporter.edge-light.d.ts",
170
184
  "default": "./dist/reporter/http/http-reporter.edge-light.js"
@@ -172,28 +186,40 @@
172
186
  "browser": {
173
187
  "types": "./dist/reporter/http/http-reporter.d.ts",
174
188
  "default": "./dist/reporter/http/http-reporter.js"
175
- },
176
- "import": {
177
- "types": "./dist/reporter/http/http-reporter.d.ts",
178
- "default": "./dist/reporter/http/http-reporter.js"
179
189
  }
180
190
  },
181
- "./progress-bar": {
182
- "types": "./dist/progress-bar.d.ts",
183
- "default": "./dist/progress-bar.js"
184
- },
185
- "./spinner": {
186
- "types": "./dist/spinner.d.ts",
187
- "default": "./dist/spinner.js"
188
- },
189
- "./interactive": {
190
- "types": "./dist/interactive/index.d.ts",
191
- "default": "./dist/interactive/index.js"
192
- },
193
191
  "./object-tree": {
194
192
  "types": "./dist/object-tree.d.ts",
195
193
  "default": "./dist/object-tree.js"
196
194
  },
195
+ "./wide-event": {
196
+ "types": "./dist/wide-event.d.ts",
197
+ "default": "./dist/wide-event.js"
198
+ },
199
+ "./middleware/express": {
200
+ "types": "./dist/middleware/express.d.ts",
201
+ "default": "./dist/middleware/express.js"
202
+ },
203
+ "./middleware/fastify": {
204
+ "types": "./dist/middleware/fastify.d.ts",
205
+ "default": "./dist/middleware/fastify.js"
206
+ },
207
+ "./middleware/hono": {
208
+ "types": "./dist/middleware/hono.d.ts",
209
+ "default": "./dist/middleware/hono.js"
210
+ },
211
+ "./middleware/elysia": {
212
+ "types": "./dist/middleware/elysia.d.ts",
213
+ "default": "./dist/middleware/elysia.js"
214
+ },
215
+ "./middleware/sveltekit": {
216
+ "types": "./dist/middleware/sveltekit.d.ts",
217
+ "default": "./dist/middleware/sveltekit.js"
218
+ },
219
+ "./middleware/next": {
220
+ "types": "./dist/middleware/next/handler.d.ts",
221
+ "default": "./dist/middleware/next/handler.js"
222
+ },
197
223
  "./package.json": "./package.json"
198
224
  },
199
225
  "files": [
@@ -203,27 +229,51 @@
203
229
  "LICENSE.md"
204
230
  ],
205
231
  "dependencies": {
206
- "type-fest": "^5.3.0",
207
- "@visulima/colorize": "2.0.0-alpha.2"
232
+ "@visulima/colorize": "2.0.0-alpha.13",
233
+ "@visulima/interactive-manager": "1.0.0-alpha.4"
208
234
  },
209
235
  "peerDependencies": {
210
- "@opentelemetry/api": "^1.9",
211
- "@visulima/redact": "3.0.0-alpha.2",
212
- "rotating-file-stream": "^3.2.7"
236
+ "@opentelemetry/api": "^1.9.1",
237
+ "@sveltejs/kit": ">=2.0",
238
+ "@visulima/redact": "3.0.0-alpha.13",
239
+ "elysia": ">=1.0",
240
+ "express": ">=4.0",
241
+ "fastify": ">=4.0",
242
+ "hono": ">=4.0",
243
+ "next": ">=14.0",
244
+ "rotating-file-stream": "3.2.9"
213
245
  },
214
246
  "peerDependenciesMeta": {
215
247
  "@opentelemetry/api": {
216
248
  "optional": true
217
249
  },
250
+ "@sveltejs/kit": {
251
+ "optional": true
252
+ },
218
253
  "@visulima/redact": {
219
254
  "optional": true
220
255
  },
256
+ "elysia": {
257
+ "optional": true
258
+ },
259
+ "express": {
260
+ "optional": true
261
+ },
262
+ "fastify": {
263
+ "optional": true
264
+ },
265
+ "hono": {
266
+ "optional": true
267
+ },
268
+ "next": {
269
+ "optional": true
270
+ },
221
271
  "rotating-file-stream": {
222
272
  "optional": true
223
273
  }
224
274
  },
225
275
  "engines": {
226
- "node": ">=22.13 <=25.x"
276
+ "node": "^22.14.0 || >=24.10.0"
227
277
  },
228
278
  "os": [
229
279
  "darwin",
@@ -1,37 +0,0 @@
1
- import type { DefaultLoggerTypes } from "./types.d.ts";
2
- /**
3
- * Extended RFC 5424 Log Levels
4
- *
5
- * The log levels pail uses are those defined in the syslog protocol.
6
- * Each level is assigned a numeric priority where lower numbers indicate higher priority.
7
- * @see https://datatracker.ietf.org/doc/html/rfc5424#page-36
8
- * @example
9
- * ```typescript
10
- * import { EXTENDED_RFC_5424_LOG_LEVELS } from "@visulima/pail";
11
- *
12
- * console.log(EXTENDED_RFC_5424_LOG_LEVELS.error); // 5
13
- * ```
14
- */
15
- export declare const EXTENDED_RFC_5424_LOG_LEVELS: Record<string, number>;
16
- /**
17
- * Default Logger Types Configuration
18
- *
19
- * Predefined logger types with their associated colors, labels, and log levels.
20
- * These types provide semantic meaning to different kinds of log messages.
21
- * @example
22
- * ```typescript
23
- * import { LOG_TYPES } from "@visulima/pail";
24
- *
25
- * console.log(LOG_TYPES.error.color); // "red"
26
- * console.log(LOG_TYPES.success.label); // "success"
27
- * ```
28
- */
29
- export declare const LOG_TYPES: DefaultLoggerTypes;
30
- /**
31
- * Empty Symbol
32
- *
33
- * A unique symbol used internally to represent empty or undefined message values.
34
- * This helps distinguish between intentional empty messages and undefined values.
35
- * @internal
36
- */
37
- export declare const EMPTY_SYMBOL: symbol;
@@ -1,2 +0,0 @@
1
- export { default as InteractiveManager } from "./interactive-manager.d.ts";
2
- export { default as InteractiveStreamHook } from "./interactive-stream-hook.d.ts";
@@ -1,2 +0,0 @@
1
- export { default as InteractiveManager } from '../packem_shared/InteractiveManager-CbE7d1kY.js';
2
- export { I as InteractiveStreamHook } from '../packem_shared/interactive-stream-hook-DG4BtN12.js';
@@ -1,108 +0,0 @@
1
- import type InteractiveStreamHook from "./interactive-stream-hook.d.ts";
2
- /** Supported stream types for interactive output */
3
- type StreamType = "stderr" | "stdout";
4
- /**
5
- * Interactive Manager.
6
- *
7
- * Manages interactive terminal output by coordinating stdout and stderr streams.
8
- * Enables features like progress bars, spinners, and dynamic updates by temporarily
9
- * capturing and controlling terminal output. Supports suspending and resuming
10
- * interactive mode for external output.
11
- * @example
12
- * ```typescript
13
- * const manager = new InteractiveManager(stdoutHook, stderrHook);
14
- *
15
- * // Start interactive mode
16
- * manager.hook();
17
- *
18
- * // Update output dynamically
19
- * manager.update("stdout", ["Processing...", "50% complete"]);
20
- *
21
- * // Temporarily suspend for external output
22
- * manager.suspend("stdout");
23
- * console.log("External message");
24
- * manager.resume("stdout");
25
- *
26
- * // End interactive mode and show final output
27
- * manager.unhook();
28
- * ```
29
- */
30
- declare class InteractiveManager {
31
- #private;
32
- /**
33
- * Creates a new InteractiveManager with the given stream hooks.
34
- * @param stdout Hook for stdout stream
35
- * @param stderr Hook for stderr stream
36
- */
37
- constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
38
- /**
39
- * Last printed rows count.
40
- *
41
- * Tracks the number of rows that were last written to the terminal.
42
- * Used internally for managing cursor positioning and output updates.
43
- */
44
- get lastLength(): number;
45
- /**
46
- * Rows count outside editable area.
47
- *
48
- * Tracks the number of rows that extend beyond the current terminal height.
49
- * Used for managing scrolling and ensuring all output remains visible.
50
- */
51
- get outside(): number;
52
- /**
53
- * Hook activity status.
54
- *
55
- * Indicates whether the interactive hooks are currently active.
56
- * When true, streams are being intercepted for interactive output.
57
- */
58
- get isHooked(): boolean;
59
- /**
60
- * Suspend status for active hooks.
61
- *
62
- * Indicates whether interactive mode is temporarily suspended.
63
- * When suspended, external output can be written without interference.
64
- */
65
- get isSuspended(): boolean;
66
- /**
67
- * Removes lines from the terminal output.
68
- *
69
- * Erases the specified number of lines from the bottom of the output,
70
- * moving the cursor up and clearing the lines. Useful for removing
71
- * previous interactive output before displaying new content.
72
- * @param stream The stream to erase lines from ("stdout" or "stderr")
73
- * @param count Number of lines to remove (defaults to lastLength)
74
- * @throws {TypeError} If the specified stream is not available
75
- */
76
- erase(stream: StreamType, count?: number): void;
77
- /**
78
- * Hook stdout and stderr streams.
79
- * @returns Success status
80
- */
81
- hook(): boolean;
82
- /**
83
- * Resume suspend hooks.
84
- * @param stream Stream to resume
85
- * @param eraseRowCount erase output rows count
86
- */
87
- resume(stream: StreamType, eraseRowCount?: number): void;
88
- /**
89
- * Suspend active hooks for external output.
90
- * @param stream Stream to suspend
91
- * @param erase erase output
92
- */
93
- suspend(stream: StreamType, erase?: boolean): void;
94
- /**
95
- * Unhooks both stdout and stderr streams and print their story of logs.
96
- * @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
97
- * @returns Success status
98
- */
99
- unhook(separateHistory?: boolean): boolean;
100
- /**
101
- * Update output.
102
- * @param stream Stream to write to
103
- * @param rows Text lines to write to standard output
104
- * @param from Index of the line starting from which the contents of the terminal are being overwritten
105
- */
106
- update(stream: StreamType, rows: string[], from?: number): void;
107
- }
108
- export default InteractiveManager;
@@ -1,68 +0,0 @@
1
- /**
2
- * Interactive Stream Hook.
3
- *
4
- * A utility class that hooks into Node.js WriteStreams to capture output
5
- * for interactive terminal applications. It allows temporarily intercepting
6
- * stream writes to enable features like progress bars and dynamic updates.
7
- * @example
8
- * ```typescript
9
- * const hook = new InteractiveStreamHook(process.stdout);
10
- * hook.active(); // Start capturing output
11
- *
12
- * // Output will be stored in history instead of being written to stdout
13
- * console.log("This won't appear immediately");
14
- *
15
- * hook.inactive(); // Stop capturing and replay stored output
16
- * ```
17
- */
18
- declare class InteractiveStreamHook {
19
- #private;
20
- /** Constant indicating the stream write operation was successful */
21
- static readonly DRAIN = true;
22
- /**
23
- * Creates a new InteractiveStreamHook for the given stream.
24
- * @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
25
- */
26
- constructor(stream: NodeJS.WriteStream);
27
- /**
28
- * Activates the stream hook.
29
- *
30
- * When active, all writes to the stream are captured in history instead of
31
- * being written immediately. This allows for interactive features like
32
- * progress bars that can update dynamically.
33
- */
34
- active(): void;
35
- /**
36
- * Erases the specified number of lines from the terminal.
37
- *
38
- * Uses ANSI escape sequences to remove lines from the current cursor position
39
- * upwards, which is useful for clearing previous output in interactive applications.
40
- * @param count Number of lines to erase (including the current line)
41
- */
42
- erase(count: number): void;
43
- /**
44
- * Deactivates the stream hook and replays captured output.
45
- *
46
- * Restores normal stream operation and outputs all captured history.
47
- * Optionally adds a newline separator before replaying the history.
48
- * @param separateHistory Whether to add a newline before replaying history
49
- */
50
- inactive(separateHistory?: boolean): void;
51
- /**
52
- * Renews the stream hook state.
53
- *
54
- * Restores the original stream write method and shows the cursor.
55
- * This is typically called when temporarily suspending interactive mode.
56
- */
57
- renew(): void;
58
- /**
59
- * Writes a message directly to the underlying stream.
60
- *
61
- * Bypasses the hook mechanism and writes directly using the original
62
- * stream write method. Useful for writing control sequences or
63
- * messages that should not be captured in history.
64
- * @param message The message to write to the stream
65
- */
66
- write(message: string): void;
67
- }
68
- export default InteractiveStreamHook;