@visulima/pail 4.0.2 → 4.1.1
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.
- package/CHANGELOG.md +23 -0
- package/LICENSE.md +346 -0
- package/README.md +17 -0
- package/dist/error.d.ts +69 -69
- package/dist/index.browser.d.ts +446 -445
- package/dist/index.browser.js +17 -17
- package/dist/index.server.d.ts +582 -582
- package/dist/index.server.js +27 -27
- package/dist/middleware/elysia.d.ts +44 -42
- package/dist/middleware/elysia.js +1 -1
- package/dist/middleware/express.d.ts +58 -59
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +55 -56
- package/dist/middleware/fastify.js +1 -1
- package/dist/middleware/hono.d.ts +56 -57
- package/dist/middleware/hono.js +1 -1
- package/dist/middleware/next/handler.d.ts +67 -68
- package/dist/middleware/next/handler.js +1 -1
- package/dist/middleware/sveltekit.d.ts +72 -73
- package/dist/middleware/sveltekit.js +1 -1
- package/dist/object-tree.d.ts +44 -44
- package/dist/packem_shared/AbstractJsonReporter-BpWRnN0L.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-DxZwImm5.js +1 -0
- package/dist/packem_shared/JsonReporter-9IcELa1m.js +2 -0
- package/dist/packem_shared/JsonReporter-Dd3kuj8X.js +1 -0
- package/dist/packem_shared/{PrettyReporter-DsHfKOU7.js → PrettyReporter-BUWNEg3_.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-CcDdPQSt.js → PrettyReporter-DbgD89ck.js} +56 -30
- package/dist/packem_shared/abstract-json-reporter.d-B6NoO-hG.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-DrLBJ6ds.js → abstract-pretty-reporter-CyfTvmKf.js} +41 -39
- package/dist/packem_shared/create-middleware-logger.d-BRkkBMlk.d.ts +47 -0
- package/dist/packem_shared/headers-DI58djdG.js +1 -0
- package/dist/packem_shared/index-CbkPnylC.js +1 -0
- package/dist/packem_shared/serializeError-52C4oiKx-CrnRcq9R.js +1 -0
- package/dist/packem_shared/storage-DVcJumyk.js +1 -0
- package/dist/packem_shared/types.d-4ge_rME4.d.ts +246 -0
- package/dist/packem_shared/{types.d-Cz9S7jZh.d.ts → types.d-BW8kAXUv.d.ts} +95 -95
- package/dist/packem_shared/types.d-DGHeA2iJ.d.ts +194 -0
- package/dist/packem_shared/useLogger-7p55yvvc.js +1 -0
- package/dist/packem_shared/wide-event.d-BMLastMR.d.ts +716 -0
- package/dist/packem_shared/write-stream-ytl_vhg_.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +32 -33
- package/dist/processor/environment-processor.d.ts +83 -84
- package/dist/processor/message-formatter-processor.d.ts +40 -45
- package/dist/processor/message-formatter-processor.js +1 -1
- package/dist/processor/opentelemetry-processor.d.ts +51 -52
- package/dist/processor/redact-processor.d.ts +57 -65
- package/dist/processor/sampling-processor.d.ts +90 -91
- package/dist/reporter/file/json-file-reporter.d.ts +77 -78
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +125 -121
- package/dist/reporter/http/abstract-http-reporter.js +2 -2
- package/dist/reporter/http/http-reporter.d.ts +33 -34
- package/dist/reporter/http/http-reporter.edge-light.d.ts +235 -230
- package/dist/reporter/http/http-reporter.edge-light.js +2 -2
- package/dist/reporter/json/index.browser.d.ts +62 -61
- package/dist/reporter/json/index.browser.js +1 -1
- package/dist/reporter/json/index.d.ts +36 -37
- package/dist/reporter/json/index.js +1 -1
- package/dist/reporter/pretty/index.browser.d.ts +57 -56
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +133 -133
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +91 -90
- package/dist/reporter/simple/simple-reporter.server.js +7 -7
- package/dist/wide-event.d.ts +2 -3
- package/dist/wide-event.js +1 -1
- package/package.json +58 -37
- package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +0 -1
- package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +0 -1
- package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +0 -2
- package/dist/packem_shared/JsonReporter-bmem9lcg.js +0 -1
- package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +0 -62
- package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +0 -25
- package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +0 -47
- package/dist/packem_shared/headers-DH0H2s8W.js +0 -1
- package/dist/packem_shared/index-Q1764hvO.js +0 -1
- package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +0 -1
- package/dist/packem_shared/storage-DaXAlpiO.js +0 -1
- package/dist/packem_shared/types.d-bWnqHJKL.d.ts +0 -211
- package/dist/packem_shared/types.d-xxE3FOD3.d.ts +0 -229
- package/dist/packem_shared/useLogger-DB34CuU5.js +0 -1
- package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +0 -717
- package/dist/packem_shared/write-stream-C7jxLxIT.js +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { P as PailBrowserImpl } from "./wide-event.d-BMLastMR.js";
|
|
2
|
+
import { D as DefaultLogTypes, b as LoggerFunction } from "./types.d-4ge_rME4.js";
|
|
3
|
+
/**
|
|
4
|
+
* Route configuration for a specific path pattern.
|
|
5
|
+
*/
|
|
6
|
+
interface RouteConfig {
|
|
7
|
+
/** Override the service name for requests matching this route. */
|
|
8
|
+
service?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A pail instance with dynamically generated log methods.
|
|
12
|
+
*/
|
|
13
|
+
type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
|
|
14
|
+
/**
|
|
15
|
+
* Base options shared by all framework middleware adapters.
|
|
16
|
+
* @template T - Custom logger type names from the pail instance
|
|
17
|
+
*/
|
|
18
|
+
interface PailMiddlewareOptions<T extends string = string> {
|
|
19
|
+
/**
|
|
20
|
+
* Glob patterns for paths to exclude from logging.
|
|
21
|
+
* Exclusions take precedence over inclusions.
|
|
22
|
+
* @example ["/health", "/api/_internal/**"]
|
|
23
|
+
*/
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Glob patterns for paths to include in logging.
|
|
27
|
+
* If not set, all non-excluded paths are logged.
|
|
28
|
+
* @example ["/api/**"]
|
|
29
|
+
*/
|
|
30
|
+
include?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* The pail logger instance to use for wide event emission.
|
|
33
|
+
*/
|
|
34
|
+
pail: PailLike<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Route-specific configuration. Maps glob patterns to config.
|
|
37
|
+
* First matching route wins.
|
|
38
|
+
* @example { "/api/auth/**": { service: "auth-service" } }
|
|
39
|
+
*/
|
|
40
|
+
routes?: Record<string, RouteConfig>;
|
|
41
|
+
/**
|
|
42
|
+
* Default service name for all wide events.
|
|
43
|
+
* Can be overridden per-route via `routes`.
|
|
44
|
+
*/
|
|
45
|
+
service?: string;
|
|
46
|
+
}
|
|
47
|
+
export { PailMiddlewareOptions as P };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WideEvent as u}from"../wide-event.js";const k=r=>{let e="^",t=0;for(;t<r.length;){const s=r[t];if(s==="*"&&r[t+1]==="*")t+=2,r[t]==="/"&&(t+=1),t>=r.length&&e.endsWith("/")?e=`${e.slice(0,-1)}(/.*)?`:t>=r.length?e+=".*":e+="(.*/)?";else switch(s){case"*":{e+="[^/]*",t+=1;break}case".":{e+=String.raw`\.`,t+=1;break}case"?":{e+="[^/]",t+=1;break}default:e+=s.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),t+=1}}return e+="$",new RegExp(e)},g=new Map,$=r=>{let e=g.get(r);return e===void 0&&(e=k(r),g.set(r,e)),e},h=(r,e)=>$(e).test(r),x=(r,e,t)=>t?.some(s=>h(r,s))?!1:e?.length?e.some(s=>h(r,s)):!0,v=(r,e)=>{if(!e)return;const t=Object.entries(e);for(let s=0;s<t.length;s+=1){const[a,o]=t[s];if(h(r,a))return o.service}},S=(r,e)=>{const{exclude:t,include:s,pail:a,routes:o,service:p}=r,{headers:d,method:i,path:n,requestId:w}=e;if(!x(n,s,t)){const l=new u({autoEmit:!1,name:`${i} ${n}`,pail:a});return{finish:()=>{},logger:l,skipped:!0}}const m=v(n,o)??p,c=new u({name:`${i} ${n}`,pail:a,service:m});return c.set({method:i,path:n,requestId:w,...d?{headers:d}:{}}),{finish:l=>{c.finish(l)},logger:c,skipped:!1}},f=new Set(["authorization","cookie","proxy-authorization","set-cookie","x-api-key","x-auth-token"]),b=r=>{const e={};return r.forEach((t,s)=>{f.has(s.toLowerCase())||(e[s.toLowerCase()]=t)}),e},y=r=>{const e={},t=Object.entries(r);for(let s=0;s<t.length;s+=1){const[a,o]=t[s];!f.has(a.toLowerCase())&&o!==void 0&&(e[a.toLowerCase()]=Array.isArray(o)?o.join(", "):o)}return e};export{y as a,S as c,b as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const O=e=>{const t=Object.keys(e).map(o=>e[o].label??"");return t.length===0?"":t.reduce((o,i)=>o.length>i.length?o:i,"")};let h;const B=()=>(h!==void 0||(h=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"]])),h),$=/^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i,A=/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i,v=/^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,S=/^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,x=()=>({__proto__:null,backgroundColor:null,color:null,fontStyle:null,fontWeight:null,textDecorationColor:null,textDecorationLine:[]}),y=/\s+/,m=e=>{const t=B();t.has(e)&&(e=t.get(e));const o=$.exec(e);if(o)return[Number.parseInt(o[1],16),Number.parseInt(o[2],16),Number.parseInt(o[3],16)];const i=A.exec(e);if(i)return[Number.parseInt(`${i[1]}${i[1]}`,16),Number.parseInt(`${i[2]}${i[2]}`,16),Number.parseInt(`${i[3]}${i[3]}`,16)];const f=v.exec(e);if(f)return[Math.round(Math.max(0,Math.min(255,Number(f[1])))),Math.round(Math.max(0,Math.min(255,Number(f[2])))),Math.round(Math.max(0,Math.min(255,Number(f[3]))))];const r=S.exec(e);if(r){let a=Number(r[1])%360;a<0&&(a+=360);const l=Math.max(0,Math.min(100,Number(r[2])))/100,d=Math.max(0,Math.min(100,Number(r[3])))/100,u=(1-Math.abs(2*d-1))*l,b=u*(1-Math.abs(a/60%2-1)),n=d-u/2;let s,c,g;return a<60?{0:s,1:c,2:g}=[u,b,0]:a<120?{0:s,1:c,2:g}=[b,u,0]:a<180?{0:s,1:c,2:g}=[0,u,b]:a<240?{0:s,1:c,2:g}=[0,b,u]:a<300?{0:s,1:c,2:g}=[b,0,u]:{0:s,1:c,2:g}=[u,0,b],[Math.round((s+n)*255),Math.round((c+n)*255),Math.round((g+n)*255)]}return null},k=(e,t)=>typeof e=="string"||typeof t=="string"?e===t:e?.[0]===t?.[0]&&e?.[1]===t?.[1]&&e?.[2]===t?.[2],D=e=>{if(typeof e!="string")return x();const t=x(),o=[];let i=!1,f=null,r=0,a="";for(const l of e){if(l==="(")r+=1;else if(r>0)l===")"&&(r-=1);else if(i){if(l===";"){const d=a.trim();d!==""&&o.push([f,d]),f=null,a="",i=!1;continue}}else if(l===":"){f=a.trim(),a="",i=!0;continue}a+=l}if(i&&r===0){const l=a.trim();l!==""&&o.push([f,l]),f=null,a=""}for(const{0:l,1:d}of o)switch(l){case"background-color":{d!=null&&(t.backgroundColor=d);break}case"color":{d!=null&&(t.color=d);break}case"font-style":{["italic","oblique","oblique 14deg"].includes(d)&&(t.fontStyle="italic");break}case"font-weight":{d==="bold"&&(t.fontWeight=d);break}case"text-decoration":{t.textDecorationColor=null,t.textDecorationLine=[];const u=d.split(y);for(const b of u){const n=m(b);n!=null?t.textDecorationColor=n:["line-through","overline","underline"].includes(b)&&t.textDecorationLine.push(b)}break}case"text-decoration-color":{const u=m(d);u!=null&&(t.textDecorationColor=u);break}case"text-decoration-line":{t.textDecorationLine=[];const u=d.split(y);for(const b of u)["line-through","overline","underline"].includes(b)&&t.textDecorationLine.push(b);break}}return t},M=(e,t)=>{t=t??x();let o="";if(!k(e.backgroundColor,t.backgroundColor))if(e.backgroundColor==null)o+="\x1B[49m";else switch(e.backgroundColor){case"black":{o+="\x1B[40m";break}case"blue":{o+="\x1B[44m";break}case"cyan":{o+="\x1B[46m";break}case"green":{o+="\x1B[42m";break}case"magenta":{o+="\x1B[45m";break}case"red":{o+="\x1B[41m";break}case"white":{o+="\x1B[47m";break}case"yellow":{o+="\x1B[43m";break}default:if(Array.isArray(e.backgroundColor)){const{0:i,1:f,2:r}=e.backgroundColor;o+=`\x1B[48;2;${String(i)};${String(f)};${String(r)}m`}else{const i=m(e.backgroundColor);if(i===null)o+="\x1B[49m";else{const{0:f,1:r,2:a}=i;o+=`\x1B[48;2;${String(f)};${String(r)};${String(a)}m`}}}if(!k(e.color,t.color))if(e.color==null)o+="\x1B[39m";else switch(e.color){case"black":{o+="\x1B[30m";break}case"blue":{o+="\x1B[34m";break}case"cyan":{o+="\x1B[36m";break}case"green":{o+="\x1B[32m";break}case"magenta":{o+="\x1B[35m";break}case"red":{o+="\x1B[31m";break}case"white":{o+="\x1B[37m";break}case"yellow":{o+="\x1B[33m";break}default:if(Array.isArray(e.color)){const{0:i,1:f,2:r}=e.color;o+=`\x1B[38;2;${String(i)};${String(f)};${String(r)}m`}else{const i=m(e.color);if(i===null)o+="\x1B[39m";else{const{0:f,1:r,2:a}=i;o+=`\x1B[38;2;${String(f)};${String(r)};${String(a)}m`}}}if(e.fontWeight!==t.fontWeight&&(o+=e.fontWeight==="bold"?"\x1B[1m":"\x1B[22m"),e.fontStyle!==t.fontStyle&&(o+=e.fontStyle==="italic"?"\x1B[3m":"\x1B[23m"),!k(e.textDecorationColor,t.textDecorationColor))if(e.textDecorationColor==null)o+="\x1B[59m";else{const{0:i,1:f,2:r}=e.textDecorationColor;o+=`\x1B[58;2;${String(i)};${String(f)};${String(r)}m`}return e.textDecorationLine.includes("line-through")!==t.textDecorationLine.includes("line-through")&&(o+=e.textDecorationLine.includes("line-through")?"\x1B[9m":"\x1B[29m"),e.textDecorationLine.includes("overline")!==t.textDecorationLine.includes("overline")&&(o+=e.textDecorationLine.includes("overline")?"\x1B[53m":"\x1B[55m"),e.textDecorationLine.includes("underline")!==t.textDecorationLine.includes("underline")&&(o+=e.textDecorationLine.includes("underline")?"\x1B[4m":"\x1B[24m"),o},N=e=>{try{return JSON.stringify(e)}catch{return'"[Circular]"'}},p="%".codePointAt(0),C="s".codePointAt(0),L="d".codePointAt(0),F="f".codePointAt(0),P="i".codePointAt(0),j="O".codePointAt(0),q="o".codePointAt(0),E="j".codePointAt(0),I="c".codePointAt(0),w=(e,t=[],o={})=>{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=o.stringify??N,f=1;if(typeof e=="object"){const n=t.length+f;if(n===1)return"{}";const s=Array.from({length:n});s[0]=i(e);for(let c=1;c<n;c+=1)s[c]=i(t[c-f]);return s.join(" ")}if(t.length===0)return e;let r="",a=1-f,l=-1,d=!1,u;const b=o.colors??globalThis.window===void 0;for(let n=0;n<e.length;){if(e.codePointAt(n)===p&&n+1<e.length){l=l>-1?l:0;const s=e.codePointAt(n+1);switch(s){case I:{if(l<n&&(r+=e.slice(l,n)),b){const c=D(t[a]),g=M(c,u);r+=g,g!==""&&(d=!0,u=c)}l=n+2,n+=1;break}case L:case F:{const c=t[a];if(a>=t.length||c==null)break;l<n&&(r+=e.slice(l,n)),r+=(typeof c=="symbol"?Number.NaN:Number(c)).toString(),l=n+2,n+=1;break}case P:{const c=t[a];if(a>=t.length||c==null)break;l<n&&(r+=e.slice(l,n)),r+=Math.floor(typeof c=="symbol"?Number.NaN:Number(c)).toString(),l=n+2,n+=1;break}case E:case j:case q:{if(a>=t.length||t[a]===void 0)break;l<n&&(r+=e.slice(l,n));const c=t[a],g=typeof c;if(g==="string"){r+=`'${c}'`,l=n+2,n+=1;break}if(g==="function"){r+=c.name?`[Function: ${c.name}]`:"[Function: <anonymous>]",l=n+2,n+=1;break}r+=i(c),l=n+2,n+=1;break}case p:{l<n&&(r+=e.slice(l,n)),r+="%",l=n+2,n+=1,a-=1;break}case C:{if(a>=t.length)break;l<n&&(r+=e.slice(l,n));const c=t[a];r+=typeof c=="object"&&c!==null?i(c):String(c),l=n+2,n+=1;break}default:typeof o.formatters?.[s]=="function"?(l<n&&(r+=e.slice(l,n)),r+=o.formatters[s](t[a]),l=n+2,n+=1):a-=1}a+=1}n+=1}if(l===-1&&!(o.appendExtraArguments&&a<t.length))return e;if(l===-1?r=e:l<e.length&&(r+=e.slice(l)),l!==-1&&d&&(r+="\x1B[0m"),o.appendExtraArguments&&a<t.length)for(let n=Math.max(a,0);n<t.length;n+=1){const s=t[n];r+=` ${typeof s=="object"&&s!==null?i(s):String(s)}`}return r},W=(e={})=>{const t={};typeof e.formatters=="object"&&Object.entries(e.formatters).forEach(([f,r])=>{if(f.length===0)throw new Error(`Formatter %${f} has no characters`);if(f.length>1)throw new Error(`Formatter %${f} has more than one character`);if(typeof r!="function")throw new TypeError(`Formatter for %${f} is not a function`);const a=f.codePointAt(0);if(a===void 0)throw new Error(`${f}.codePointAt(0) failed to return a value, please report this issue`);t[a]=r});const o={...e};delete o.formatters;const i=Object.freeze({...o,formatters:t});return(f,r=[],a)=>a===void 0?w(f,r,i):w(f,r,{...o,...a,formatters:t})};export{W as O,O as g,w as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const p=Object.create({},{cause:{enumerable:!1,value:void 0,writable:!0},code:{enumerable:!0,value:void 0,writable:!0},errors:{enumerable:!1,value:void 0,writable:!0},message:{enumerable:!1,value:void 0,writable:!0},name:{enumerable:!1,value:void 0,writable:!0},stack:{enumerable:!1,value:void 0,writable:!0}}),m=e=>{if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype||Object.getPrototypeOf(r)===null},f=new WeakSet,y=e=>{if(Object.hasOwn(e,"name")&&typeof e.name=="string"&&e.name!=="")return e.name;const r=e.constructor?.name;return typeof r=="string"&&r!==""?r:e.name},s=e=>{const r=Object.getOwnPropertyNames(e);for(const n of r){const t=Object.getOwnPropertyDescriptor(e,n);t&&(t.enumerable||Object.defineProperty(e,n,{...t,enumerable:!0}),t.value&&typeof t.value=="object"&&!Array.isArray(t.value)&&(Object.getPrototypeOf(t.value)===Object.prototype||Object.getPrototypeOf(t.value)===null)&&s(t.value))}},O=e=>{f.add(e);const r=e.toJSON();return f.delete(e),Object.isExtensible(r)&&s(r),r},c=(e,r,n,t,a=new Set)=>{if(e&&e instanceof Uint8Array&&e.constructor.name==="Buffer")return"[object Buffer]";if(e!==null&&typeof e=="object"&&"pipe"in e&&typeof e.pipe=="function")return"[object Stream]";if(e instanceof Error)return r.has(e)?"[Circular]":(n+=1,l(e,t,r,n));if(t.useToJSON&&e!==null&&typeof e=="object"&&"toJSON"in e&&typeof e.toJSON=="function")return e.toJSON();if(e instanceof Date)return e.toISOString();if(e instanceof RegExp)return e.toString();if(typeof URL<"u"&&e instanceof URL)return e.href;if(e instanceof Map){const o=[];for(const[u,i]of e.entries())o.push([c(u,r,n,t,a),c(i,r,n,t,a)]);return{__dataType:"Map",value:o}}if(e instanceof Set){const o=[];for(const u of e.values())o.push(c(u,r,n,t,a));return{__dataType:"Set",value:o}}if(typeof e=="function")return`[Function: ${e.name||"anonymous"}]`;if(typeof e=="bigint")return`${String(e)}n`;if(m(e)){if(a.has(e))return"[Circular]";if(t.maxDepth!==void 0&&t.maxDepth!==Number.POSITIVE_INFINITY&&n+1>=t.maxDepth)return{};n+=1,a.add(e);const o={};for(const u in e)o[u]=c(e[u],r,n,t,a);return a.delete(e),o}try{return e}catch{return"[Not Available]"}},l=(e,r,n,t)=>{if(n.add(e),r.maxDepth===0)return{};if(r.useToJSON&&typeof e.toJSON=="function"&&!f.has(e))return O(e);const a=Object.create(p);if(Object.defineProperty(a,"name",{configurable:!0,enumerable:!0,value:y(e),writable:!0}),Object.defineProperty(a,"message",{configurable:!0,enumerable:!0,value:e.message,writable:!0}),Object.defineProperty(a,"stack",{configurable:!0,enumerable:!0,value:e.stack,writable:!0}),Array.isArray(e.errors)){const u=[];for(const i of e.errors){if(!(i instanceof Error))throw new TypeError("All errors in the 'errors' property must be instances of Error");if(n.has(i))return Object.defineProperty(a,"errors",{configurable:!0,enumerable:!0,value:[],writable:!0}),a;u.push(l(i,r,n,t))}Object.defineProperty(a,"errors",{configurable:!0,enumerable:!0,value:u,writable:!0})}const o=e.cause;if(o!=null)if(o instanceof Error)n.has(o)?Object.defineProperty(a,"cause",{configurable:!0,enumerable:!0,value:"[Circular]",writable:!0}):Object.defineProperty(a,"cause",{configurable:!0,enumerable:!0,value:l(o,r,n,t),writable:!0});else{const u=c(o,n,t,r);Object.defineProperty(a,"cause",{configurable:!0,enumerable:!0,value:u,writable:!0})}for(const u in e){if(u==="name"||u==="message"||u==="stack"||u==="cause"||u==="errors")continue;const i=e[u],b=c(i,n,t,r);Object.defineProperty(a,u,{configurable:!0,enumerable:!0,value:b,writable:!0})}if(Array.isArray(r.exclude)&&r.exclude.length>0)for(const u of r.exclude)try{delete a[u]}catch{}return a},d=(e,r={})=>l(e,{exclude:r.exclude??[],maxDepth:r.maxDepth??Number.POSITIVE_INFINITY,useToJSON:r.useToJSON??!1},new Set,0);export{d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as t}from"node:module";let n;const c=e=>(n??=t(import.meta.url))(e),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,i=e=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[o,r]=s.versions.node.split(".").map(Number);if(o>22||o===22&&r>=3||o===20&&r>=16)return s.getBuiltinModule(e)}return c(e)},{AsyncLocalStorage:u}=i("node:async_hooks"),g=e=>{const o=new u;return{storage:o,useLogger:()=>{const r=o.getStore();if(!r)throw new Error(`[pail] useLogger() called outside of ${e}`);return r}}};export{g as c};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { AnsiColors } from '@visulima/colorize';
|
|
2
|
+
import { InteractiveManager } from '@visulima/interactive-manager';
|
|
3
|
+
/**
|
|
4
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
5
|
+
|
|
6
|
+
@category Type
|
|
7
|
+
*/
|
|
8
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
9
|
+
/**
|
|
10
|
+
Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
11
|
+
|
|
12
|
+
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
13
|
+
|
|
14
|
+
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
15
|
+
|
|
16
|
+
@example
|
|
17
|
+
```
|
|
18
|
+
import type {LiteralUnion} from 'type-fest';
|
|
19
|
+
|
|
20
|
+
// Before
|
|
21
|
+
|
|
22
|
+
type Pet = 'dog' | 'cat' | string;
|
|
23
|
+
|
|
24
|
+
const petWithoutAutocomplete: Pet = '';
|
|
25
|
+
// Start typing in your TypeScript-enabled IDE.
|
|
26
|
+
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
27
|
+
|
|
28
|
+
// After
|
|
29
|
+
|
|
30
|
+
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
31
|
+
|
|
32
|
+
const petWithAutoComplete: Pet2 = '';
|
|
33
|
+
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
@category Type
|
|
37
|
+
*/
|
|
38
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
39
|
+
/**
|
|
40
|
+
* Global namespace for extending Pail's metadata interface.
|
|
41
|
+
*
|
|
42
|
+
* This global declaration allows other packages and applications to extend
|
|
43
|
+
* the Meta interface with custom properties by declaring additional properties
|
|
44
|
+
* in the VisulimaPail.CustomMeta interface.
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* declare global {
|
|
48
|
+
* namespace VisulimaPail {
|
|
49
|
+
* interface CustomMeta<L> {
|
|
50
|
+
* userId?: string;
|
|
51
|
+
* requestId?: string;
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare global {
|
|
58
|
+
namespace VisulimaPail {
|
|
59
|
+
interface CustomMeta<L> {}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Metadata object containing all information about a log entry.
|
|
64
|
+
*
|
|
65
|
+
* This interface defines the structure of metadata that is passed to reporters
|
|
66
|
+
* and processors. It contains all the contextual information about a log message
|
|
67
|
+
* including the message itself, timing information, error details, and more.
|
|
68
|
+
* @template L - The log level type
|
|
69
|
+
*/
|
|
70
|
+
interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
71
|
+
badge: string | undefined;
|
|
72
|
+
context: any[] | undefined;
|
|
73
|
+
date: Date | string;
|
|
74
|
+
error: Error | undefined;
|
|
75
|
+
groups: string[];
|
|
76
|
+
label: string | undefined;
|
|
77
|
+
message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
|
|
78
|
+
prefix: string | undefined;
|
|
79
|
+
repeated?: number;
|
|
80
|
+
scope: string[] | undefined;
|
|
81
|
+
suffix: string | undefined;
|
|
82
|
+
traceError: Error | undefined;
|
|
83
|
+
type: {
|
|
84
|
+
level: ExtendedRfc5424LogLevels | L;
|
|
85
|
+
name: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extended RFC 5424 Log Levels.
|
|
90
|
+
*
|
|
91
|
+
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
92
|
+
* levels commonly used in modern applications. Each level has a numeric
|
|
93
|
+
* priority where lower numbers indicate higher severity.
|
|
94
|
+
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
95
|
+
*/
|
|
96
|
+
type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
|
|
97
|
+
/**
|
|
98
|
+
* Default Log Types.
|
|
99
|
+
*
|
|
100
|
+
* Predefined semantic log types that provide meaningful categorization
|
|
101
|
+
* for different kinds of log messages. Each type has associated styling
|
|
102
|
+
* and log level configuration.
|
|
103
|
+
*/
|
|
104
|
+
type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
|
|
105
|
+
/**
|
|
106
|
+
* Logger Function Type.
|
|
107
|
+
*
|
|
108
|
+
* Represents a logging function that can accept either a structured Message object
|
|
109
|
+
* or multiple arguments in the traditional console.log style.
|
|
110
|
+
*/
|
|
111
|
+
interface LoggerFunction {
|
|
112
|
+
(message: Message): void;
|
|
113
|
+
(...message: any[]): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Logger Configuration.
|
|
117
|
+
*
|
|
118
|
+
* Configuration object that defines how a specific logger type should behave,
|
|
119
|
+
* including its visual appearance and log level.
|
|
120
|
+
* @template L - The log level type
|
|
121
|
+
*/
|
|
122
|
+
interface LoggerConfiguration<L extends string> {
|
|
123
|
+
badge?: string;
|
|
124
|
+
color?: AnsiColors;
|
|
125
|
+
label: string;
|
|
126
|
+
logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Logger Types Configuration.
|
|
130
|
+
*
|
|
131
|
+
* A record mapping logger type names to their configurations.
|
|
132
|
+
* @template T - Custom logger type names
|
|
133
|
+
* @template L - Log level types
|
|
134
|
+
*/
|
|
135
|
+
type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
|
|
136
|
+
/**
|
|
137
|
+
* Read-only Metadata.
|
|
138
|
+
*
|
|
139
|
+
* Immutable version of the Meta interface for use in reporters.
|
|
140
|
+
* @template L - The log level type
|
|
141
|
+
*/
|
|
142
|
+
type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
|
|
143
|
+
/**
|
|
144
|
+
* Reporter Interface.
|
|
145
|
+
*
|
|
146
|
+
* Base interface for all reporters. Reporters are responsible for
|
|
147
|
+
* outputting log messages to various destinations (console, files, etc.).
|
|
148
|
+
* @template L - The log level type
|
|
149
|
+
*/
|
|
150
|
+
interface Reporter<L extends string> {
|
|
151
|
+
log: (meta: ReadonlyMeta<L>) => void;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Stream-Aware Reporter Interface.
|
|
155
|
+
*
|
|
156
|
+
* Extends Reporter with the ability to work with Node.js streams.
|
|
157
|
+
* Used for server-side reporters that need to write to stdout/stderr.
|
|
158
|
+
* @template L - The log level type
|
|
159
|
+
*/
|
|
160
|
+
interface StreamAwareReporter<L extends string> extends Reporter<L> {
|
|
161
|
+
/** Set the stderr stream for error output */
|
|
162
|
+
setStderr: (stderr: NodeJS.WriteStream) => void;
|
|
163
|
+
/** Set the stdout stream for standard output */
|
|
164
|
+
setStdout: (stdout: NodeJS.WriteStream) => void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Logger Types Aware Reporter Interface.
|
|
168
|
+
*
|
|
169
|
+
* Extends Reporter with the ability to receive logger type configurations.
|
|
170
|
+
* Allows reporters to customize their output based on logger types.
|
|
171
|
+
* @template T - Custom logger type names
|
|
172
|
+
* @template L - The log level type
|
|
173
|
+
*/
|
|
174
|
+
interface LoggerTypesAwareReporter<T extends string, L extends string> extends Reporter<L> {
|
|
175
|
+
/** Set the logger types configuration */
|
|
176
|
+
setLoggerTypes: (types: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>) => void;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Stringify-Aware Reporter Interface.
|
|
180
|
+
*
|
|
181
|
+
* Extends Reporter with the ability to receive a custom stringify function.
|
|
182
|
+
* Useful for reporters that need to serialize complex objects.
|
|
183
|
+
* @template L - The log level type
|
|
184
|
+
*/
|
|
185
|
+
interface StringifyAwareReporter<L extends string> extends Reporter<L> {
|
|
186
|
+
/** Set the stringify function for object serialization */
|
|
187
|
+
setStringify: (stringify: any) => void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Interactive Stream Reporter Interface.
|
|
191
|
+
*
|
|
192
|
+
* Extends StreamAwareReporter with interactive capabilities for terminal UIs.
|
|
193
|
+
* Supports features like progress bars and dynamic updates.
|
|
194
|
+
* @template L - The log level type
|
|
195
|
+
*/
|
|
196
|
+
interface InteractiveStreamReporter<L extends string> extends StreamAwareReporter<L> {
|
|
197
|
+
/** Set the interactive manager for handling interactive output */
|
|
198
|
+
setInteractiveManager: (manager?: InteractiveManager) => void;
|
|
199
|
+
/** Enable or disable interactive mode */
|
|
200
|
+
setIsInteractive: (interactive: boolean) => void;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Processor Interface.
|
|
204
|
+
*
|
|
205
|
+
* Base interface for all processors. Processors can modify or enhance
|
|
206
|
+
* log metadata before it reaches reporters.
|
|
207
|
+
* @template L - The log level type
|
|
208
|
+
*/
|
|
209
|
+
interface Processor<L extends string> {
|
|
210
|
+
/** Process the log metadata */
|
|
211
|
+
process: (meta: Meta<L>) => Meta<L>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Stringify-Aware Processor Interface.
|
|
215
|
+
*
|
|
216
|
+
* Extends Processor with the ability to receive a custom stringify function.
|
|
217
|
+
* Useful for processors that need to serialize complex objects.
|
|
218
|
+
* @template L - The log level type
|
|
219
|
+
*/
|
|
220
|
+
interface StringifyAwareProcessor<L extends string> extends Processor<L> {
|
|
221
|
+
/** Set the stringify function for object serialization */
|
|
222
|
+
setStringify: (stringify: typeof JSON.stringify) => void;
|
|
223
|
+
}
|
|
224
|
+
interface ConstructorOptions<T extends string, L extends string> {
|
|
225
|
+
disabled?: boolean;
|
|
226
|
+
logLevel?: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
227
|
+
logLevels?: Partial<Record<ExtendedRfc5424LogLevels, number>> & Record<L, number>;
|
|
228
|
+
messages?: {
|
|
229
|
+
timerEnd?: string;
|
|
230
|
+
timerStart?: string;
|
|
231
|
+
};
|
|
232
|
+
processors?: Processor<L>[];
|
|
233
|
+
rawReporter?: Reporter<L>;
|
|
234
|
+
reporters?: Reporter<L>[];
|
|
235
|
+
scope?: string[] | string;
|
|
236
|
+
throttle?: number;
|
|
237
|
+
throttleMin?: number;
|
|
238
|
+
types?: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>;
|
|
239
|
+
}
|
|
240
|
+
type Message = {
|
|
241
|
+
context?: any[];
|
|
242
|
+
message: any;
|
|
243
|
+
prefix?: string;
|
|
244
|
+
suffix?: string;
|
|
245
|
+
};
|
|
246
|
+
export { ConstructorOptions as C, DefaultLogTypes as D, ExtendedRfc5424LogLevels as E, InteractiveStreamReporter as I, LiteralUnion as L, Meta as M, Processor as P, ReadonlyMeta as R, StringifyAwareReporter as S, StreamAwareReporter as a, LoggerFunction as b, StringifyAwareProcessor as c, LoggerTypesConfig as d, Reporter as e, LoggerTypesAwareReporter as f };
|
|
@@ -2,36 +2,36 @@ import { AnsiColors } from '@visulima/colorize';
|
|
|
2
2
|
import { InteractiveManager } from '@visulima/interactive-manager';
|
|
3
3
|
import { LiteralUnion, Primitive } from 'type-fest';
|
|
4
4
|
/**
|
|
5
|
-
* Global namespace for extending Pail's metadata interface.
|
|
6
|
-
*
|
|
7
|
-
* This global declaration allows other packages and applications to extend
|
|
8
|
-
* the Meta interface with custom properties by declaring additional properties
|
|
9
|
-
* in the VisulimaPail.CustomMeta interface.
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* declare global {
|
|
13
|
-
* namespace VisulimaPail {
|
|
14
|
-
* interface CustomMeta<L> {
|
|
15
|
-
* userId?: string;
|
|
16
|
-
* requestId?: string;
|
|
17
|
-
* }
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
5
|
+
* Global namespace for extending Pail's metadata interface.
|
|
6
|
+
*
|
|
7
|
+
* This global declaration allows other packages and applications to extend
|
|
8
|
+
* the Meta interface with custom properties by declaring additional properties
|
|
9
|
+
* in the VisulimaPail.CustomMeta interface.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* declare global {
|
|
13
|
+
* namespace VisulimaPail {
|
|
14
|
+
* interface CustomMeta<L> {
|
|
15
|
+
* userId?: string;
|
|
16
|
+
* requestId?: string;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
22
|
declare global {
|
|
23
23
|
namespace VisulimaPail {
|
|
24
24
|
interface CustomMeta<L> {}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Metadata object containing all information about a log entry.
|
|
29
|
-
*
|
|
30
|
-
* This interface defines the structure of metadata that is passed to reporters
|
|
31
|
-
* and processors. It contains all the contextual information about a log message
|
|
32
|
-
* including the message itself, timing information, error details, and more.
|
|
33
|
-
* @template L - The log level type
|
|
34
|
-
*/
|
|
28
|
+
* Metadata object containing all information about a log entry.
|
|
29
|
+
*
|
|
30
|
+
* This interface defines the structure of metadata that is passed to reporters
|
|
31
|
+
* and processors. It contains all the contextual information about a log message
|
|
32
|
+
* including the message itself, timing information, error details, and more.
|
|
33
|
+
* @template L - The log level type
|
|
34
|
+
*/
|
|
35
35
|
interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
36
36
|
badge: string | undefined;
|
|
37
37
|
context: any[] | undefined;
|
|
@@ -51,39 +51,39 @@ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Extended RFC 5424 Log Levels.
|
|
55
|
-
*
|
|
56
|
-
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
57
|
-
* levels commonly used in modern applications. Each level has a numeric
|
|
58
|
-
* priority where lower numbers indicate higher severity.
|
|
59
|
-
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
60
|
-
*/
|
|
54
|
+
* Extended RFC 5424 Log Levels.
|
|
55
|
+
*
|
|
56
|
+
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
57
|
+
* levels commonly used in modern applications. Each level has a numeric
|
|
58
|
+
* priority where lower numbers indicate higher severity.
|
|
59
|
+
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
60
|
+
*/
|
|
61
61
|
type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
|
|
62
62
|
/**
|
|
63
|
-
* Default Log Types.
|
|
64
|
-
*
|
|
65
|
-
* Predefined semantic log types that provide meaningful categorization
|
|
66
|
-
* for different kinds of log messages. Each type has associated styling
|
|
67
|
-
* and log level configuration.
|
|
68
|
-
*/
|
|
63
|
+
* Default Log Types.
|
|
64
|
+
*
|
|
65
|
+
* Predefined semantic log types that provide meaningful categorization
|
|
66
|
+
* for different kinds of log messages. Each type has associated styling
|
|
67
|
+
* and log level configuration.
|
|
68
|
+
*/
|
|
69
69
|
type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
|
|
70
70
|
/**
|
|
71
|
-
* Logger Function Type.
|
|
72
|
-
*
|
|
73
|
-
* Represents a logging function that can accept either a structured Message object
|
|
74
|
-
* or multiple arguments in the traditional console.log style.
|
|
75
|
-
*/
|
|
71
|
+
* Logger Function Type.
|
|
72
|
+
*
|
|
73
|
+
* Represents a logging function that can accept either a structured Message object
|
|
74
|
+
* or multiple arguments in the traditional console.log style.
|
|
75
|
+
*/
|
|
76
76
|
interface LoggerFunction {
|
|
77
77
|
(message: Message): void;
|
|
78
78
|
(...message: any[]): void;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Logger Configuration.
|
|
82
|
-
*
|
|
83
|
-
* Configuration object that defines how a specific logger type should behave,
|
|
84
|
-
* including its visual appearance and log level.
|
|
85
|
-
* @template L - The log level type
|
|
86
|
-
*/
|
|
81
|
+
* Logger Configuration.
|
|
82
|
+
*
|
|
83
|
+
* Configuration object that defines how a specific logger type should behave,
|
|
84
|
+
* including its visual appearance and log level.
|
|
85
|
+
* @template L - The log level type
|
|
86
|
+
*/
|
|
87
87
|
interface LoggerConfiguration<L extends string> {
|
|
88
88
|
badge?: string;
|
|
89
89
|
color?: AnsiColors;
|
|
@@ -91,44 +91,44 @@ interface LoggerConfiguration<L extends string> {
|
|
|
91
91
|
logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Logger Types Configuration.
|
|
95
|
-
*
|
|
96
|
-
* A record mapping logger type names to their configurations.
|
|
97
|
-
* @template T - Custom logger type names
|
|
98
|
-
* @template L - Log level types
|
|
99
|
-
*/
|
|
94
|
+
* Logger Types Configuration.
|
|
95
|
+
*
|
|
96
|
+
* A record mapping logger type names to their configurations.
|
|
97
|
+
* @template T - Custom logger type names
|
|
98
|
+
* @template L - Log level types
|
|
99
|
+
*/
|
|
100
100
|
type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
|
|
101
101
|
/**
|
|
102
|
-
* Default Logger Types Configuration.
|
|
103
|
-
*
|
|
104
|
-
* A complete mapping of all default log types to their full configurations.
|
|
105
|
-
* @template L - Log level types
|
|
106
|
-
*/
|
|
102
|
+
* Default Logger Types Configuration.
|
|
103
|
+
*
|
|
104
|
+
* A complete mapping of all default log types to their full configurations.
|
|
105
|
+
* @template L - Log level types
|
|
106
|
+
*/
|
|
107
107
|
type DefaultLoggerTypes<L extends string = string> = Record<DefaultLogTypes, LoggerConfiguration<L>>;
|
|
108
108
|
/**
|
|
109
|
-
* Read-only Metadata.
|
|
110
|
-
*
|
|
111
|
-
* Immutable version of the Meta interface for use in reporters.
|
|
112
|
-
* @template L - The log level type
|
|
113
|
-
*/
|
|
109
|
+
* Read-only Metadata.
|
|
110
|
+
*
|
|
111
|
+
* Immutable version of the Meta interface for use in reporters.
|
|
112
|
+
* @template L - The log level type
|
|
113
|
+
*/
|
|
114
114
|
type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
|
|
115
115
|
/**
|
|
116
|
-
* Reporter Interface.
|
|
117
|
-
*
|
|
118
|
-
* Base interface for all reporters. Reporters are responsible for
|
|
119
|
-
* outputting log messages to various destinations (console, files, etc.).
|
|
120
|
-
* @template L - The log level type
|
|
121
|
-
*/
|
|
116
|
+
* Reporter Interface.
|
|
117
|
+
*
|
|
118
|
+
* Base interface for all reporters. Reporters are responsible for
|
|
119
|
+
* outputting log messages to various destinations (console, files, etc.).
|
|
120
|
+
* @template L - The log level type
|
|
121
|
+
*/
|
|
122
122
|
interface Reporter<L extends string> {
|
|
123
123
|
log: (meta: ReadonlyMeta<L>) => void;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* Stream-Aware Reporter Interface.
|
|
127
|
-
*
|
|
128
|
-
* Extends Reporter with the ability to work with Node.js streams.
|
|
129
|
-
* Used for server-side reporters that need to write to stdout/stderr.
|
|
130
|
-
* @template L - The log level type
|
|
131
|
-
*/
|
|
126
|
+
* Stream-Aware Reporter Interface.
|
|
127
|
+
*
|
|
128
|
+
* Extends Reporter with the ability to work with Node.js streams.
|
|
129
|
+
* Used for server-side reporters that need to write to stdout/stderr.
|
|
130
|
+
* @template L - The log level type
|
|
131
|
+
*/
|
|
132
132
|
interface StreamAwareReporter<L extends string> extends Reporter<L> {
|
|
133
133
|
/** Set the stderr stream for error output */
|
|
134
134
|
setStderr: (stderr: NodeJS.WriteStream) => void;
|
|
@@ -136,24 +136,24 @@ interface StreamAwareReporter<L extends string> extends Reporter<L> {
|
|
|
136
136
|
setStdout: (stdout: NodeJS.WriteStream) => void;
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
|
-
* Logger Types Aware Reporter Interface.
|
|
140
|
-
*
|
|
141
|
-
* Extends Reporter with the ability to receive logger type configurations.
|
|
142
|
-
* Allows reporters to customize their output based on logger types.
|
|
143
|
-
* @template T - Custom logger type names
|
|
144
|
-
* @template L - The log level type
|
|
145
|
-
*/
|
|
139
|
+
* Logger Types Aware Reporter Interface.
|
|
140
|
+
*
|
|
141
|
+
* Extends Reporter with the ability to receive logger type configurations.
|
|
142
|
+
* Allows reporters to customize their output based on logger types.
|
|
143
|
+
* @template T - Custom logger type names
|
|
144
|
+
* @template L - The log level type
|
|
145
|
+
*/
|
|
146
146
|
interface LoggerTypesAwareReporter<T extends string, L extends string> extends Reporter<L> {
|
|
147
147
|
/** Set the logger types configuration */
|
|
148
148
|
setLoggerTypes: (types: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>) => void;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
-
* Interactive Stream Reporter Interface.
|
|
152
|
-
*
|
|
153
|
-
* Extends StreamAwareReporter with interactive capabilities for terminal UIs.
|
|
154
|
-
* Supports features like progress bars and dynamic updates.
|
|
155
|
-
* @template L - The log level type
|
|
156
|
-
*/
|
|
151
|
+
* Interactive Stream Reporter Interface.
|
|
152
|
+
*
|
|
153
|
+
* Extends StreamAwareReporter with interactive capabilities for terminal UIs.
|
|
154
|
+
* Supports features like progress bars and dynamic updates.
|
|
155
|
+
* @template L - The log level type
|
|
156
|
+
*/
|
|
157
157
|
interface InteractiveStreamReporter<L extends string> extends StreamAwareReporter<L> {
|
|
158
158
|
/** Set the interactive manager for handling interactive output */
|
|
159
159
|
setInteractiveManager: (manager?: InteractiveManager) => void;
|
|
@@ -161,12 +161,12 @@ interface InteractiveStreamReporter<L extends string> extends StreamAwareReporte
|
|
|
161
161
|
setIsInteractive: (interactive: boolean) => void;
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Processor Interface.
|
|
165
|
-
*
|
|
166
|
-
* Base interface for all processors. Processors can modify or enhance
|
|
167
|
-
* log metadata before it reaches reporters.
|
|
168
|
-
* @template L - The log level type
|
|
169
|
-
*/
|
|
164
|
+
* Processor Interface.
|
|
165
|
+
*
|
|
166
|
+
* Base interface for all processors. Processors can modify or enhance
|
|
167
|
+
* log metadata before it reaches reporters.
|
|
168
|
+
* @template L - The log level type
|
|
169
|
+
*/
|
|
170
170
|
interface Processor<L extends string> {
|
|
171
171
|
/** Process the log metadata */
|
|
172
172
|
process: (meta: Meta<L>) => Meta<L>;
|