@visulima/pail 4.0.0-alpha.21 → 4.0.0-alpha.22
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 +46 -0
- package/LICENSE.md +841 -6
- package/README.md +53 -24
- package/dist/index.browser.d.ts +16 -5
- package/dist/index.browser.js +19 -19
- package/dist/index.server.d.ts +30 -5
- package/dist/index.server.js +28 -27
- package/dist/middleware/elysia.d.ts +5 -4
- package/dist/middleware/elysia.js +1 -1
- package/dist/middleware/express.d.ts +5 -4
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +5 -4
- package/dist/middleware/fastify.js +1 -1
- package/dist/middleware/hono.d.ts +5 -4
- package/dist/middleware/hono.js +1 -1
- package/dist/middleware/next/handler.d.ts +5 -4
- package/dist/middleware/next/handler.js +1 -1
- package/dist/middleware/sveltekit.d.ts +5 -4
- package/dist/middleware/sveltekit.js +1 -1
- package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-C6iu_u9-.js +1 -0
- package/dist/packem_shared/JsonReporter-BXktpC__.js +2 -0
- package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
- package/dist/packem_shared/PrettyReporter-DNNseeLK.js +44 -0
- package/dist/packem_shared/{PrettyReporter-D75CJT0C.js → PrettyReporter-DsHfKOU7.js} +3 -3
- package/dist/packem_shared/{abstract-json-reporter.d-Boj5w068.d.ts → abstract-json-reporter.d-wfESoEa-.d.ts} +3 -2
- package/dist/packem_shared/abstract-pretty-reporter-Bczvp2Zh.js +57 -0
- package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-f9no2VNI.js +25 -0
- package/dist/packem_shared/{create-middleware-logger.d-MK7moe4r.d.ts → create-middleware-logger.d-B-JmQ1Sl.d.ts} +2 -2
- package/dist/packem_shared/{headers-D-K_EnkH.js → headers-DH0H2s8W.js} +1 -1
- package/dist/packem_shared/index-Q1764hvO.js +1 -0
- package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
- package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
- package/dist/packem_shared/{types.d-Ck_RSjLg.d.ts → types.d-bWnqHJKL.d.ts} +2 -37
- package/dist/packem_shared/{wide-event.d-DkYD7YVK.d.ts → wide-event.d-D3ATYpoK.d.ts} +17 -5
- package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
- package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +2 -1
- package/dist/processor/environment-processor.d.ts +2 -1
- package/dist/processor/message-formatter-processor.d.ts +9 -1
- package/dist/processor/message-formatter-processor.js +1 -1
- package/dist/processor/opentelemetry-processor.d.ts +2 -1
- package/dist/processor/redact-processor.d.ts +41 -2
- package/dist/processor/sampling-processor.d.ts +2 -1
- package/dist/reporter/file/json-file-reporter.d.ts +21 -3
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +46 -3
- package/dist/reporter/http/abstract-http-reporter.js +2 -2
- package/dist/reporter/http/http-reporter.d.ts +4 -3
- package/dist/reporter/http/http-reporter.edge-light.d.ts +57 -1
- package/dist/reporter/http/http-reporter.edge-light.js +2 -2
- package/dist/reporter/json/index.browser.d.ts +1 -1
- package/dist/reporter/json/index.browser.js +1 -1
- package/dist/reporter/json/index.d.ts +6 -4
- package/dist/reporter/json/index.js +1 -1
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +93 -6
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +87 -5
- package/dist/reporter/simple/simple-reporter.server.js +8 -8
- package/dist/wide-event.d.ts +4 -3
- package/dist/wide-event.js +1 -1
- package/package.json +4 -4
- package/dist/packem_shared/AbstractJsonReporter-CF0KKdQS.js +0 -1
- package/dist/packem_shared/AbstractJsonReporter-CVwjgboT.js +0 -1
- package/dist/packem_shared/JsonReporter-BJFnahby.js +0 -1
- package/dist/packem_shared/JsonReporter-CnLM-d0U.js +0 -2
- package/dist/packem_shared/PrettyReporter-D9aBMmxI.js +0 -45
- package/dist/packem_shared/abstract-pretty-reporter-zijeSUgy.js +0 -34
- package/dist/packem_shared/index-COQEZODZ.js +0 -1
- package/dist/packem_shared/write-console-log-based-on-level-DDSKGBKj.js +0 -1
- package/dist/packem_shared/write-stream-B6BXco86.js +0 -1
- /package/dist/packem_shared/{createPailError-CbU1Ogfa.js → PailError-CbU1Ogfa.js} +0 -0
package/README.md
CHANGED
|
@@ -1041,30 +1041,59 @@ When a log entry exceeds `maxLogSize`, a `LogSizeError` is thrown. When a batch
|
|
|
1041
1041
|
|
|
1042
1042
|
### Configuration Options
|
|
1043
1043
|
|
|
1044
|
-
| Option | Type | Default | Description
|
|
1045
|
-
| ------------------------ | ------------------------------------------ | -------------------- |
|
|
1046
|
-
| `url` | `string` | **required** | HTTP endpoint URL
|
|
1047
|
-
| `method` | `string` | `"POST"` | HTTP method
|
|
1048
|
-
| `headers` | `Record<string, string> \| (() => ...)` | `{}` | Request headers (object or function)
|
|
1049
|
-
| `contentType` | `string` | `"application/json"` | Content type for single requests
|
|
1050
|
-
| `batchContentType` | `string` | `"application/json"` | Content type for batch requests
|
|
1051
|
-
| `enableBatchSend` | `boolean` | `true` | Enable automatic batching
|
|
1052
|
-
| `batchSize` | `number` | `100` | Number of logs to batch before sending
|
|
1053
|
-
| `batchSendTimeout` | `number` | `5000` | Timeout (ms) to send batch regardless of size
|
|
1054
|
-
| `batchMode` | `"delimiter" \| "array" \| "field"` | `"delimiter"` | Batch format mode
|
|
1055
|
-
| `batchSendDelimiter` | `string` | `"\n"` | Delimiter for batch entries
|
|
1056
|
-
| `batchFieldName` | `string` | `undefined` | Field name for "field" batch mode
|
|
1057
|
-
| `compression` | `boolean` | `false` | Enable gzip compression
|
|
1058
|
-
| `maxRetries` | `number` | `3` | Maximum retry attempts
|
|
1059
|
-
| `retryDelay` | `number` | `1000` | Base delay between retries (ms)
|
|
1060
|
-
| `respectRateLimit` | `boolean` | `true` | Wait on 429 rate limit responses
|
|
1061
|
-
| `maxLogSize` | `number` | `1048576` | Maximum size per log entry (bytes)
|
|
1062
|
-
| `maxPayloadSize` | `number` | `5242880` | Maximum size per payload (bytes)
|
|
1063
|
-
| `
|
|
1064
|
-
| `
|
|
1065
|
-
| `
|
|
1066
|
-
| `
|
|
1067
|
-
| `
|
|
1044
|
+
| Option | Type | Default | Description |
|
|
1045
|
+
| ------------------------ | ------------------------------------------ | -------------------- | ---------------------------------------------- |
|
|
1046
|
+
| `url` | `string` | **required** | HTTP endpoint URL |
|
|
1047
|
+
| `method` | `string` | `"POST"` | HTTP method |
|
|
1048
|
+
| `headers` | `Record<string, string> \| (() => ...)` | `{}` | Request headers (object or function) |
|
|
1049
|
+
| `contentType` | `string` | `"application/json"` | Content type for single requests |
|
|
1050
|
+
| `batchContentType` | `string` | `"application/json"` | Content type for batch requests |
|
|
1051
|
+
| `enableBatchSend` | `boolean` | `true` | Enable automatic batching |
|
|
1052
|
+
| `batchSize` | `number` | `100` | Number of logs to batch before sending |
|
|
1053
|
+
| `batchSendTimeout` | `number` | `5000` | Timeout (ms) to send batch regardless of size |
|
|
1054
|
+
| `batchMode` | `"delimiter" \| "array" \| "field"` | `"delimiter"` | Batch format mode |
|
|
1055
|
+
| `batchSendDelimiter` | `string` | `"\n"` | Delimiter for batch entries |
|
|
1056
|
+
| `batchFieldName` | `string` | `undefined` | Field name for "field" batch mode |
|
|
1057
|
+
| `compression` | `boolean` | `false` | Enable gzip compression |
|
|
1058
|
+
| `maxRetries` | `number` | `3` | Maximum retry attempts |
|
|
1059
|
+
| `retryDelay` | `number` | `1000` | Base delay between retries (ms) |
|
|
1060
|
+
| `respectRateLimit` | `boolean` | `true` | Wait on 429 rate limit responses |
|
|
1061
|
+
| `maxLogSize` | `number` | `1048576` | Maximum size per log entry (bytes) |
|
|
1062
|
+
| `maxPayloadSize` | `number` | `5242880` | Maximum size per payload (bytes) |
|
|
1063
|
+
| `maxQueueSize` | `number` | `10000` | Max queued entries before drop-oldest kicks in |
|
|
1064
|
+
| `edgeCompat` | `boolean` | `false` | Enable Edge Runtime compatibility |
|
|
1065
|
+
| `onError` | `(error: Error) => void` | `undefined` | Error callback |
|
|
1066
|
+
| `onDrop` | `(droppedCount: number) => void` | `undefined` | Called when queued entries are dropped |
|
|
1067
|
+
| `onDebug` | `(entry: Record<string, unknown>) => void` | `undefined` | Debug callback for log entries |
|
|
1068
|
+
| `onDebugRequestResponse` | `(reqRes: {...}) => void` | `undefined` | Debug callback for HTTP requests/responses |
|
|
1069
|
+
| `payloadTemplate` | `(data: {...}) => string` | `undefined` | Custom payload formatter |
|
|
1070
|
+
|
|
1071
|
+
### Flushing & Shutdown
|
|
1072
|
+
|
|
1073
|
+
`HttpReporter` batches entries (up to `batchSize`, or every `batchSendTimeout` ms). Before a
|
|
1074
|
+
short-lived or serverless process exits, call `flush()` (or `close()` / `dispose()`) so the
|
|
1075
|
+
tail of the batch is shipped rather than lost:
|
|
1076
|
+
|
|
1077
|
+
```typescript
|
|
1078
|
+
const reporter = new HttpReporter({ url: "https://logs.example.com" });
|
|
1079
|
+
|
|
1080
|
+
// ... log ...
|
|
1081
|
+
|
|
1082
|
+
// Drain the queue before exit
|
|
1083
|
+
await reporter.flush();
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
If the endpoint is unavailable, the queue is capped at `maxQueueSize` entries using a
|
|
1087
|
+
drop-oldest policy, so a sustained outage cannot grow memory without bound. Provide `onDrop`
|
|
1088
|
+
to be notified when entries are dropped.
|
|
1089
|
+
|
|
1090
|
+
`JsonFileReporter` likewise exposes `close()` / `dispose()` to end its rotating-file stream:
|
|
1091
|
+
|
|
1092
|
+
```typescript
|
|
1093
|
+
process.on("beforeExit", () => {
|
|
1094
|
+
fileReporter.close();
|
|
1095
|
+
});
|
|
1096
|
+
```
|
|
1068
1097
|
|
|
1069
1098
|
## Wide Events
|
|
1070
1099
|
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { stringify } from
|
|
1
|
+
import { s as stringify } from "./packem_shared/index.d-T71KjNAr.js";
|
|
2
2
|
import { C as ConstructorOptions, M as Meta, D as DefaultLogTypes, L as LiteralUnion, a as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, c as Reporter, d as LoggerFunction } from "./packem_shared/types.d-xxE3FOD3.js";
|
|
3
|
-
export {
|
|
3
|
+
export type { e as DefaultLoggerTypes, f as LoggerConfiguration, b as LoggerTypesAwareReporter, g as StreamAwareReporter } from "./packem_shared/types.d-xxE3FOD3.js";
|
|
4
4
|
import '@visulima/colorize';
|
|
5
5
|
import '@visulima/interactive-manager';
|
|
6
6
|
/**
|
|
@@ -28,9 +28,6 @@ import '@visulima/interactive-manager';
|
|
|
28
28
|
*/
|
|
29
29
|
declare class PailBrowserImpl<T extends string = string, L extends string = string> {
|
|
30
30
|
#private;
|
|
31
|
-
protected timersMap: Map<string, number>;
|
|
32
|
-
protected countMap: Map<string, number>;
|
|
33
|
-
protected seqTimers: Set<string>;
|
|
34
31
|
protected readonly lastLog: {
|
|
35
32
|
count?: number;
|
|
36
33
|
object?: Meta<L>;
|
|
@@ -119,6 +116,20 @@ declare class PailBrowserImpl<T extends string = string, L extends string = stri
|
|
|
119
116
|
*/
|
|
120
117
|
wrapException(): void;
|
|
121
118
|
/**
|
|
119
|
+
* Removes the global exception/rejection handlers installed by {@link wrapException}.
|
|
120
|
+
*
|
|
121
|
+
* Counterpart to `wrapException()` (mirrors `wrapConsole()`/`restoreConsole()`).
|
|
122
|
+
* Safe to call when no handlers are installed.
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const logger = createPail();
|
|
126
|
+
* logger.wrapException();
|
|
127
|
+
* // ... later ...
|
|
128
|
+
* logger.restoreException(); // global handlers removed
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
restoreException(): void;
|
|
132
|
+
/**
|
|
122
133
|
* Disables all logging output.
|
|
123
134
|
*
|
|
124
135
|
* When disabled, all log calls will be silently ignored and no output
|
package/dist/index.browser.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import{a as se,E as re,L as ie}from"./packem_shared/constants-DKfCaSUR.js";import{
|
|
2
|
-
${p}`,
|
|
3
|
-
${p}`);const j=Math.min(l.length,b);let _=0;for(;_<j-1;_++){const
|
|
4
|
-
${
|
|
5
|
-
${p}`,d=" ");const
|
|
6
|
-
${p}${
|
|
7
|
-
${
|
|
8
|
-
${p}`,
|
|
9
|
-
${p}`);const
|
|
10
|
-
${l}`),n.pop(),`[${
|
|
11
|
-
${p}`,
|
|
12
|
-
${p}${
|
|
13
|
-
${l}`),n.pop(),`{${
|
|
14
|
-
${
|
|
15
|
-
${
|
|
16
|
-
${p}`,n.pop(),`[${d}]`}let l=Object.keys(t);const
|
|
17
|
-
${
|
|
18
|
-
${
|
|
19
|
-
${p}`),n.pop(),`{${v}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(t);default:return o?o(t):void 0}}function I(T,t,n){switch(typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(T),typeof t!="object")return I(T,t,n);if(t===null)return"null"}if(n.indexOf(t)!==-1)return u;let f="";const c=t.length!==void 0;if(c&&Array.isArray(t)){if(t.length===0)return"[]";if(F<n.length+1)return'"[Array]"';n.push(t);const v=Math.min(t.length,b);let m=0;for(;m<v-1;m++){const d=I(String(m),t[m],n);f+=d!==void 0?d:"null",f+=","}const S=I(String(m),t[m],n);if(f+=S!==void 0?S:"null",t.length-1>b){const d=t.length-b-1;f+=`,"... ${C(d)} not stringified"`}return n.pop(),`[${f}]`}let p=Object.keys(t);const l=p.length;if(l===0)return"{}";if(F<n.length+1)return'"[Object]"';let g="",w=Math.min(l,b);c&&L(t)&&(f+=N(t,",",b),p=p.slice(t.length),w-=t.length,g=","),x&&(p=M(p,q)),n.push(t);for(let v=0;v<w;v++){const m=p[v],S=I(m,t[m],n);S!==void 0&&(f+=`${g}${y(m)}:${S}`,g=",")}if(l>b){const v=l-b;f+=`${g}"...":"${C(v)} not stringified"`}return n.pop(),`{${f}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(A)return String(t);default:return o?o(t):void 0}}function te(T,t,n){if(arguments.length>1){let f="";if(typeof n=="number"?f=" ".repeat(Math.min(n,10)):typeof n=="string"&&(f=n.slice(0,10)),t!=null){if(typeof t=="function")return B("",{"":T},[],t,f,"");if(Array.isArray(t))return k("",T,[],Z(t),f,"")}if(f.length!==0)return V("",T,[],f,"")}return I("",T,[])}return te}})(Q,Q.exports)),Q.exports}var ge=ce();const ue=ae(ge),fe=ue.configure;class he{log(e){const{context:s=[],message:r,type:a}=e;oe(a.level)(r,...s)}}const H=$=>$===void 0?[]:Array.isArray($)?$:[$],K=($,e)=>{const s={...$};return Object.keys(e).forEach(r=>{s[r]={...s[r],...e[r]}}),s},pe=$=>{let e=!1;return function(...s){if(!e){e=!0;try{const r=$.apply(this,s);return e=!1,r}catch(r){throw e=!1,r}}}};class Y{timersMap;countMap;seqTimers;lastLog;logLevels;disabled;paused;messageQueue;scopeName;types;longestLabel;processors;generalLogLevel;reporters;throttle;throttleMin;stringify;groups;startTimerMessage;endTimerMessage;rawReporter;force={};constructor(e){this.throttle=e.throttle??1e3,this.throttleMin=e.throttleMin??5;const s=e.parentLongestLabel,r=e.parentTypes,a=e.parentStringify,y=e.parentLogLevels;this.stringify=a??fe({strict:!0}),this.startTimerMessage=e.messages?.timerStart??"Initialized timer...",this.endTimerMessage=e.messages?.timerEnd??"Timer run for:",r&&s?(this.types=r,this.longestLabel=s):(this.types=K(ie,e.types??{}),this.longestLabel=W(this.types)),this.logLevels=y&&!e.logLevels?y:{...se,...e.logLevels},this.generalLogLevel=this.#e(e.logLevel),this.reporters=new Set,this.processors=new Set,this.disabled=e.disabled??!1,this.paused=!1,this.messageQueue=[],this.scopeName=H(e.scope).filter(Boolean),this.timersMap=new Map,this.countMap=new Map,this.groups=[],this.seqTimers=new Set,this.lastLog={},this.logger=pe(this.logger.bind(this)),this.#t(),Array.isArray(e.reporters)&&this.registerReporters(e.reporters),this.rawReporter=this.extendReporter(e.rawReporter??new he),Array.isArray(e.processors)&&this.registerProcessors(e.processors)}#t(){for(const e in this.types)this[e]=this.logger.bind(this,e,!1,!1);for(const e in this.types)this.force[e]=this.logger.bind(this,e,!1,!0);this.raw=this.raw.bind(this)}wrapConsole(){for(const e in this.types)console[`__${e}`]||(console[`__${e}`]=console[e]),console[e]=this[e]}restoreConsole(){for(const e in this.types)console[`__${e}`]&&(console[e]=console[`__${e}`],delete console[`__${e}`])}wrapException(){process.on("uncaughtException",e=>{this.error(e)}),process.on("unhandledRejection",e=>{this.error(e)})}disable(){this.disabled=!0}enable(){this.disabled=!1}isEnabled(){return!this.disabled}pause(){this.paused=!0}resume(){this.paused=!1;const e=this.messageQueue.splice(0);for(let s=0;s<e.length;s+=1){const{messageObject:r,raw:a,type:y}=e[s];this.logger(y,a,!1,...r)}}scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.scopeName=e.flat(),this}unscope(){this.scopeName=[]}child(e){const s=e?.types!==void 0,r=s?K(this.types,e.types):this.types,a=e?.reporters??[],y=a.length>0?[...this.reporters,...a]:[...this.reporters],M=e?.processors??[],h=M.length>0?[...this.processors,...M]:[...this.processors],L=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let N;if(e?.scope){const J=H(e.scope).filter(Boolean);N=this.scopeName.length>0?[...this.scopeName,...J]:J}else N=this.scopeName.length>0?this.scopeName:[];const D=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},E={disabled:e?.disabled??this.disabled,logLevel:e?.logLevel??this.generalLogLevel,logLevels:L,messages:D,processors:h,rawReporter:e?.rawReporter??this.rawReporter,reporters:y,scope:N,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return s?(E.parentTypes=r,E.parentLongestLabel=W(r)):(E.parentTypes=this.types,E.parentLongestLabel=this.longestLabel),e?.logLevels||(E.parentLogLevels=this.logLevels),e?.messages||(E.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),E.parentStringify=this.stringify,new Y(E)}time(e="default"){this.seqTimers.has(e)?this.logger("warn",!1,!1,{message:`Timer '${e}' already exists`,prefix:e}):(this.seqTimers.add(e),this.timersMap.set(e,Date.now()),this.logger("start",!1,!1,{message:this.startTimerMessage,prefix:e}))}timeLog(e,...s){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const r=Date.now()-this.timersMap.get(e);this.logger("info",!1,!1,{context:s,message:r<1e3?`${String(r)} ms`:`${(r/1e3).toFixed(2)} s`,prefix:e})}else this.logger("warn",!1,!1,{context:s,message:"Timer not found",prefix:e})}timeEnd(e){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const s=Date.now()-this.timersMap.get(e);this.timersMap.delete(e),this.logger("stop",!1,!1,{message:`${this.endTimerMessage} ${s<1e3?`${String(s)} ms`:`${(s/1e3).toFixed(2)} s`}`,prefix:e})}else this.logger("warn",!1,!1,{message:"Timer not found",prefix:e})}group(e="console.group"){globalThis.window===void 0?this.groups.push(e):console.group(e)}groupEnd(){globalThis.window===void 0?this.groups.pop():console.groupEnd()}count(e="default"){const s=this.countMap.get(e)??0;this.countMap.set(e,s+1),this.logger("log",!1,!1,{message:`${e}: ${String(s+1)}`,prefix:e})}countReset(e="default"){this.countMap.has(e)?this.countMap.delete(e):this.logger("warn",!1,!1,{message:`Count for ${e} does not exist`,prefix:e})}clear(){console.clear()}raw(e,...s){this.disabled||this.logger("log",!0,!1,{context:s,message:e})}extendReporter(e){return typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),e}registerReporters(e){for(let s=0;s<e.length;s+=1)this.reporters.add(this.extendReporter(e[s]))}registerProcessors(e){for(let s=0;s<e.length;s+=1){const r=e[s];typeof r.setStringify=="function"&&r.setStringify(this.stringify),this.processors.add(r)}}#s(e,s){if(s)this.rawReporter.log(Object.freeze(e));else for(const r of this.reporters)r.log(Object.freeze(e))}#e(e){return e&&this.logLevels[e]?e:"debug"}#r(e,s,...r){const a={badge:void 0,context:void 0,error:void 0,label:void 0,message:re,prefix:void 0,repeated:void 0,scope:void 0,suffix:void 0};if(a.type={level:s.logLevel,name:e},a.groups=this.groups,a.scope=this.scopeName,a.date=new Date,r.length>0&&r[0]instanceof Error)a.error=r[0],r.length>1&&(a.context=r.slice(1));else if(r.length>0&&typeof r[0]=="object"&&r[0]!==null&&"message"in r[0]){const{context:y,message:M,prefix:h,suffix:L}=r[0];if(y&&(a.context=y),h&&(a.prefix=h),L&&(a.suffix=L),a.message=M,r.length>1){const N=r.slice(1);a.context?a.context=Array.isArray(a.context)?[...a.context,...N]:[a.context,...N]:a.context=N}}else r.length>1?(a.message=r[0],a.context=r.slice(1)):r.length===1?a.message=r[0]:a.message=void 0;return s.logLevel==="trace"&&(a.traceError=new Error("Trace")),s.badge&&(a.badge=s.badge),s.label&&(a.label=s.label),a}logger(e,s,r,...a){if(this.disabled)return;if(this.paused){this.messageQueue.push({messageObject:a,raw:s,type:e});return}const y=this.types[e],M=this.#e(y.logLevel);if(r||this.logLevels[M]>=this.logLevels[this.generalLogLevel]){let h=this.#r(e,y,...a);const L=(D=!1)=>{const E=(this.lastLog.count??0)-this.throttleMin;if(this.lastLog.object&&E>0){const J={...this.lastLog.object};E>1&&(J.repeated=E),this.#s(J,s),this.lastLog.count=1}if(D){for(const J of this.processors)h={...J.process(h)};if(h.dropped===!0)return;this.lastLog.object=h;try{this.lastLog.signature=JSON.stringify([h.label,h.scope,h.type,h.message,h.prefix,h.suffix,h.context])}catch{this.lastLog.signature=void 0}this.#s(h,s)}};clearTimeout(this.lastLog.timeout);const N=this.lastLog.time&&h.date?new Date(h.date).getTime()-this.lastLog.time.getTime():0;if(this.lastLog.time=new Date(h.date),N<this.throttle)try{const D=JSON.stringify([h.label,h.scope,h.type,h.message,h.prefix,h.suffix,h.context]);if(this.lastLog.object&&D===this.lastLog.signature&&(this.lastLog.count=(this.lastLog.count??0)+1,this.lastLog.count>this.throttleMin)){this.lastLog.timeout=setTimeout(L,this.throttle);return}}catch{}L(!0)}}}const de=Y;class me{#t;#s;#e;constructor(e={}){this.#s=e.formatters}setStringify(e){this.#t=e}process(e){this.#e===void 0&&(this.#e=ne({formatters:this.#s,stringify:r=>this.#t?this.#t(r):JSON.stringify(r)}));const s=this.#e;return e.message!==void 0&&(e.message=this.#r(s,e.message,e.context??[])),e}#r(e,s,r=[]){if(typeof s=="string")return e(s,r);if(typeof s=="object"&&s!==null){const a=s,y=Object.keys(a);for(let M=0;M<y.length;M+=1){const h=y[M],L=a[h];(typeof L=="string"||Array.isArray(L)||typeof L=="object")&&(a[h]=this.#r(e,L,r))}}return s}}const ye=$=>new de({processors:[new me],reporters:[new le],...$}),Se=ye();export{xe as PailError,ye as createPail,Oe as createPailError,Se as pail};
|
|
1
|
+
import{a as se,E as re,L as ie}from"./packem_shared/constants-DKfCaSUR.js";import{t as oe}from"./packem_shared/write-console-log-based-on-level-BqjxV016.js";import{g as X,O as ne}from"./packem_shared/index-Q1764hvO.js";import le from"./packem_shared/JsonReporter-bmem9lcg.js";import{PailError as xe,createPailError as Te}from"./packem_shared/PailError-CbU1Ogfa.js";var Y={exports:{}},H;function ae(){return H||(H=1,(function(x,e){const{hasOwnProperty:s}=Object.prototype,r=U();r.configure=U,r.stringify=r,r.default=r,e.stringify=r,e.configure=U,x.exports=r;const a=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;function y(i){return i.length<5e3&&!a.test(i)?`"${i}"`:JSON.stringify(i)}function S(i,o){if(i.length>200||o)return i.sort(o);for(let h=1;h<i.length;h++){const N=i[h];let E=h;for(;E!==0&&i[E-1]>N;)i[E]=i[E-1],E--;i[E]=N}return i}const c=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function $(i){return c.call(i)!==void 0&&i.length!==0}function T(i,o,h){i.length<h&&(h=i.length);const N=o===","?"":" ";let E=`"0":${N}${i[0]}`;for(let D=1;D<h;D++)E+=`${o}"${D}":${N}${i[D]}`;return E}function k(i){if(s.call(i,"circularValue")){const o=i.circularValue;if(typeof o=="string")return`"${o}"`;if(o==null)return o;if(o===Error||o===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function A(i){let o;if(s.call(i,"deterministic")&&(o=i.deterministic,typeof o!="boolean"&&typeof o!="function"))throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');return o===void 0?!0:o}function F(i,o){let h;if(s.call(i,o)&&(h=i[o],typeof h!="boolean"))throw new TypeError(`The "${o}" argument must be of type boolean`);return h===void 0?!0:h}function C(i,o){let h;if(s.call(i,o)){if(h=i[o],typeof h!="number")throw new TypeError(`The "${o}" argument must be of type number`);if(!Number.isInteger(h))throw new TypeError(`The "${o}" argument must be an integer`);if(h<1)throw new RangeError(`The "${o}" argument must be >= 1`)}return h===void 0?1/0:h}function R(i){return i===1?"1 item":`${i} items`}function I(i){const o=new Set;for(const h of i)(typeof h=="string"||typeof h=="number")&&o.add(String(h));return o}function ee(i){if(s.call(i,"strict")){const o=i.strict;if(typeof o!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(o)return h=>{let N=`Object can not safely be stringified. Received type ${typeof h}`;throw typeof h!="function"&&(N+=` (${h.toString()})`),new Error(N)}}}function U(i){i={...i};const o=ee(i);o&&(i.bigint===void 0&&(i.bigint=!1),"circularValue"in i||(i.circularValue=Error));const h=k(i),N=F(i,"bigint"),E=A(i),D=typeof E=="function"?E:void 0,V=C(i,"maximumDepth"),b=C(i,"maximumBreadth");function q(O,t,n,f,g,p){let l=t[O];switch(typeof l=="object"&&l!==null&&typeof l.toJSON=="function"&&(l=l.toJSON(O)),l=f.call(t,O,l),typeof l){case"string":return y(l);case"object":{if(l===null)return"null";if(n.indexOf(l)!==-1)return h;let u="",v=",";const w=p;if(Array.isArray(l)){if(l.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(l),g!==""&&(p+=g,u+=`
|
|
2
|
+
${p}`,v=`,
|
|
3
|
+
${p}`);const j=Math.min(l.length,b);let _=0;for(;_<j-1;_++){const G=q(String(_),l,n,f,g,p);u+=G!==void 0?G:"null",u+=v}const J=q(String(_),l,n,f,g,p);if(u+=J!==void 0?J:"null",l.length-1>b){const G=l.length-b-1;u+=`${v}"... ${R(G)} not stringified"`}return g!==""&&(u+=`
|
|
4
|
+
${w}`),n.pop(),`[${u}]`}let m=Object.keys(l);const L=m.length;if(L===0)return"{}";if(V<n.length+1)return'"[Object]"';let d="",M="";g!==""&&(p+=g,v=`,
|
|
5
|
+
${p}`,d=" ");const P=Math.min(L,b);E&&!$(l)&&(m=S(m,D)),n.push(l);for(let j=0;j<P;j++){const _=m[j],J=q(_,l,n,f,g,p);J!==void 0&&(u+=`${M}${y(_)}:${d}${J}`,M=v)}if(L>b){const j=L-b;u+=`${M}"...":${d}"${R(j)} not stringified"`,M=v}return g!==""&&M.length>1&&(u=`
|
|
6
|
+
${p}${u}
|
|
7
|
+
${w}`),n.pop(),`{${u}}`}case"number":return isFinite(l)?String(l):o?o(l):"null";case"boolean":return l===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(l);default:return o?o(l):void 0}}function Q(O,t,n,f,g,p){switch(typeof t=="object"&&t!==null&&typeof t.toJSON=="function"&&(t=t.toJSON(O)),typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(n.indexOf(t)!==-1)return h;const l=p;let u="",v=",";if(Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t),g!==""&&(p+=g,u+=`
|
|
8
|
+
${p}`,v=`,
|
|
9
|
+
${p}`);const L=Math.min(t.length,b);let d=0;for(;d<L-1;d++){const P=Q(String(d),t[d],n,f,g,p);u+=P!==void 0?P:"null",u+=v}const M=Q(String(d),t[d],n,f,g,p);if(u+=M!==void 0?M:"null",t.length-1>b){const P=t.length-b-1;u+=`${v}"... ${R(P)} not stringified"`}return g!==""&&(u+=`
|
|
10
|
+
${l}`),n.pop(),`[${u}]`}n.push(t);let w="";g!==""&&(p+=g,v=`,
|
|
11
|
+
${p}`,w=" ");let m="";for(const L of f){const d=Q(L,t[L],n,f,g,p);d!==void 0&&(u+=`${m}${y(L)}:${w}${d}`,m=v)}return g!==""&&m.length>1&&(u=`
|
|
12
|
+
${p}${u}
|
|
13
|
+
${l}`),n.pop(),`{${u}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function z(O,t,n,f,g){switch(typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(O),typeof t!="object")return z(O,t,n,f,g);if(t===null)return"null"}if(n.indexOf(t)!==-1)return h;const p=g;if(Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t),g+=f;let d=`
|
|
14
|
+
${g}`;const M=`,
|
|
15
|
+
${g}`,P=Math.min(t.length,b);let j=0;for(;j<P-1;j++){const J=z(String(j),t[j],n,f,g);d+=J!==void 0?J:"null",d+=M}const _=z(String(j),t[j],n,f,g);if(d+=_!==void 0?_:"null",t.length-1>b){const J=t.length-b-1;d+=`${M}"... ${R(J)} not stringified"`}return d+=`
|
|
16
|
+
${p}`,n.pop(),`[${d}]`}let l=Object.keys(t);const u=l.length;if(u===0)return"{}";if(V<n.length+1)return'"[Object]"';g+=f;const v=`,
|
|
17
|
+
${g}`;let w="",m="",L=Math.min(u,b);$(t)&&(w+=T(t,v,b),l=l.slice(t.length),L-=t.length,m=v),E&&(l=S(l,D)),n.push(t);for(let d=0;d<L;d++){const M=l[d],P=z(M,t[M],n,f,g);P!==void 0&&(w+=`${m}${y(M)}: ${P}`,m=v)}if(u>b){const d=u-b;w+=`${m}"...": "${R(d)} not stringified"`,m=v}return m!==""&&(w=`
|
|
18
|
+
${g}${w}
|
|
19
|
+
${p}`),n.pop(),`{${w}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function B(O,t,n){switch(typeof t){case"string":return y(t);case"object":{if(t===null)return"null";if(typeof t.toJSON=="function"){if(t=t.toJSON(O),typeof t!="object")return B(O,t,n);if(t===null)return"null"}if(n.indexOf(t)!==-1)return h;let f="";const g=t.length!==void 0;if(g&&Array.isArray(t)){if(t.length===0)return"[]";if(V<n.length+1)return'"[Array]"';n.push(t);const w=Math.min(t.length,b);let m=0;for(;m<w-1;m++){const d=B(String(m),t[m],n);f+=d!==void 0?d:"null",f+=","}const L=B(String(m),t[m],n);if(f+=L!==void 0?L:"null",t.length-1>b){const d=t.length-b-1;f+=`,"... ${R(d)} not stringified"`}return n.pop(),`[${f}]`}let p=Object.keys(t);const l=p.length;if(l===0)return"{}";if(V<n.length+1)return'"[Object]"';let u="",v=Math.min(l,b);g&&$(t)&&(f+=T(t,",",b),p=p.slice(t.length),v-=t.length,u=","),E&&(p=S(p,D)),n.push(t);for(let w=0;w<v;w++){const m=p[w],L=B(m,t[m],n);L!==void 0&&(f+=`${u}${y(m)}:${L}`,u=",")}if(l>b){const w=l-b;f+=`${u}"...":"${R(w)} not stringified"`}return n.pop(),`{${f}}`}case"number":return isFinite(t)?String(t):o?o(t):"null";case"boolean":return t===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(t);default:return o?o(t):void 0}}function te(O,t,n){if(arguments.length>1){let f="";if(typeof n=="number"?f=" ".repeat(Math.min(n,10)):typeof n=="string"&&(f=n.slice(0,10)),t!=null){if(typeof t=="function")return q("",{"":O},[],t,f,"");if(Array.isArray(t))return Q("",O,[],I(t),f,"")}if(f.length!==0)return z("",O,[],f,"")}return B("",O,[])}return te}})(Y,Y.exports)),Y.exports}var ce=ae();class ge{#t=new Map;#e;constructor(e){this.#e=e}count(e="default"){const s=this.#t.get(e)??0;this.#t.set(e,s+1),this.#e("log",!1,!1,{message:`${e}: ${String(s+1)}`,prefix:e})}countReset(e="default"){this.#t.has(e)?this.#t.delete(e):this.#e("warn",!1,!1,{message:`Count for ${e} does not exist`,prefix:e})}}class ue{log(e){const{context:s=[],message:r,type:a}=e;oe(a.level)(r,...s)}}class he{#t=new Map;#e=new Set;#s;#i;#r;constructor(e,s,r){this.#r=e,this.#s=s,this.#i=r}time(e="default"){this.#e.has(e)?this.#r("warn",!1,!1,{message:`Timer '${e}' already exists`,prefix:e}):(this.#e.add(e),this.#t.set(e,Date.now()),this.#r("start",!1,!1,{message:this.#s,prefix:e}))}timeLog(e,...s){if(!e&&this.#e.size>0&&(e=[...this.#e].pop()),e&&this.#t.has(e)){const r=Date.now()-this.#t.get(e);this.#r("info",!1,!1,{context:s,message:r<1e3?`${String(r)} ms`:`${(r/1e3).toFixed(2)} s`,prefix:e})}else this.#r("warn",!1,!1,{context:s,message:"Timer not found",prefix:e})}timeEnd(e){if(!e&&this.#e.size>0&&(e=[...this.#e].pop()),e&&this.#t.has(e)){const s=Date.now()-this.#t.get(e);this.#t.delete(e),this.#r("stop",!1,!1,{message:`${this.#i} ${s<1e3?`${String(s)} ms`:`${(s/1e3).toFixed(2)} s`}`,prefix:e})}else this.#r("warn",!1,!1,{message:"Timer not found",prefix:e})}}const K=x=>x===void 0?[]:Array.isArray(x)?x:[x],Z=(x,e)=>{const s={...x};return Object.keys(e).forEach(r=>{s[r]={...s[r],...e[r]}}),s},fe=x=>{let e=!1;return function(...s){if(!e){e=!0;try{const r=x.apply(this,s);return e=!1,r}catch(r){throw e=!1,r}}}};class W{timerManager;counterManager;lastLog;logLevels;disabled;paused;messageQueue;scopeName;types;longestLabel;processors;generalLogLevel;reporters;throttle;throttleMin;stringify;groups;startTimerMessage;endTimerMessage;rawReporter;force={};#t=new Set;#e;#s;constructor(e){this.throttle=e.throttle??1e3,this.throttleMin=e.throttleMin??5;const s=e.parentLongestLabel,r=e.parentTypes,a=e.parentStringify,y=e.parentLogLevels;this.stringify=a??ce.configure({strict:!0}),this.startTimerMessage=e.messages?.timerStart??"Initialized timer...",this.endTimerMessage=e.messages?.timerEnd??"Timer run for:",r&&s?(this.types=r,this.longestLabel=s):(this.types=Z(ie,e.types??{}),this.longestLabel=X(this.types)),this.logLevels=y&&!e.logLevels?y:{...se,...e.logLevels},this.generalLogLevel=this.#o(e.logLevel),this.reporters=new Set,this.processors=new Set,this.disabled=e.disabled??!1,this.paused=!1,this.messageQueue=[],this.scopeName=K(e.scope).filter(Boolean),this.timerManager=new he((S,c,$,...T)=>{this.logger(S,c,$,...T)},this.startTimerMessage,this.endTimerMessage),this.counterManager=new ge((S,c,$,...T)=>{this.logger(S,c,$,...T)}),this.groups=[],this.lastLog={},this.logger=fe(this.logger.bind(this)),this.#i(),Array.isArray(e.reporters)&&this.registerReporters(e.reporters),this.rawReporter=this.extendReporter(e.rawReporter??new ue),Array.isArray(e.processors)&&this.registerProcessors(e.processors)}#i(){for(const e in this.types)this[e]=this.logger.bind(this,e,!1,!1);for(const e in this.types)this.force[e]=this.logger.bind(this,e,!1,!0);this.raw=this.raw.bind(this)}wrapConsole(){for(const e in this.types)console[`__${e}`]||(console[`__${e}`]=console[e]),console[e]=this[e]}restoreConsole(){for(const e in this.types)console[`__${e}`]&&(console[e]=console[`__${e}`],delete console[`__${e}`])}wrapException(){this.#e||this.#s||(this.#e=e=>{this.error(e)},this.#s=e=>{this.error(e)},process.on("uncaughtException",this.#e),process.on("unhandledRejection",this.#s))}restoreException(){this.#e&&(process.off("uncaughtException",this.#e),this.#e=void 0),this.#s&&(process.off("unhandledRejection",this.#s),this.#s=void 0)}disable(){this.disabled=!0}enable(){this.disabled=!1}isEnabled(){return!this.disabled}pause(){this.paused=!0}resume(){this.paused=!1;const e=this.messageQueue.splice(0);for(let s=0;s<e.length;s+=1){const{messageObject:r,raw:a,type:y}=e[s];this.logger(y,a,!1,...r)}}scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.child({scope:e})}unscope(){this.scopeName=[]}child(e){const s=e?.types!==void 0,r=s?Z(this.types,e.types):this.types,a=e?.reporters??[],y=a.length>0?[...this.reporters,...a]:[...this.reporters],S=e?.processors??[],c=S.length>0?[...this.processors,...S]:[...this.processors],$=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let T;if(e?.scope){const F=K(e.scope).filter(Boolean);T=this.scopeName.length>0?[...this.scopeName,...F]:F}else T=this.scopeName.length>0?this.scopeName:[];const k=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},A={disabled:e?.disabled??this.disabled,logLevel:e?.logLevel??this.generalLogLevel,logLevels:$,messages:k,processors:c,rawReporter:e?.rawReporter??this.rawReporter,reporters:y,scope:T,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return s?(A.parentTypes=r,A.parentLongestLabel=X(r)):(A.parentTypes=this.types,A.parentLongestLabel=this.longestLabel),e?.logLevels||(A.parentLogLevels=this.logLevels),e?.messages||(A.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),A.parentStringify=this.stringify,new W(A)}time(e="default"){this.timerManager.time(e)}timeLog(e,...s){this.timerManager.timeLog(e,...s)}timeEnd(e){this.timerManager.timeEnd(e)}group(e="console.group"){globalThis.window===void 0?this.groups.push(e):console.group(e)}groupEnd(){globalThis.window===void 0?this.groups.pop():console.groupEnd()}count(e="default"){this.counterManager.count(e)}countReset(e="default"){this.counterManager.countReset(e)}clear(){console.clear()}raw(e,...s){this.disabled||this.logger("log",!0,!1,{context:s,message:e})}extendReporter(e){return typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),e}registerReporters(e){for(let s=0;s<e.length;s+=1)this.reporters.add(this.extendReporter(e[s]))}registerProcessors(e){for(let s=0;s<e.length;s+=1){const r=e[s];typeof r.setStringify=="function"&&r.setStringify(this.stringify),this.processors.add(r)}}#r(e,s){if(s)this.rawReporter.log(Object.freeze(e));else for(const r of this.reporters)r.log(Object.freeze(e))}#o(e){let s="debug";return e!==void 0&&Object.hasOwn(this.logLevels,e)?s=e:e!==void 0&&!this.#t.has(e)&&(this.#t.add(e),console.warn(`[pail] Unknown log level "${String(e)}". Valid levels: ${Object.keys(this.logLevels).join(", ")}. Falling back to "debug".`)),s}#n(e,s,...r){const a={badge:void 0,context:void 0,error:void 0,label:void 0,message:re,prefix:void 0,repeated:void 0,scope:void 0,suffix:void 0};if(a.type={level:s.logLevel,name:e},a.groups=this.groups,a.scope=this.scopeName,a.date=new Date,r.length>0&&r[0]instanceof Error)a.error=r[0],r.length>1&&(a.context=r.slice(1));else if(r.length>0&&typeof r[0]=="object"&&r[0]!==null&&"message"in r[0]){const{context:y,message:S,prefix:c,suffix:$}=r[0];if(y&&(a.context=y),c&&(a.prefix=c),$&&(a.suffix=$),a.message=S,r.length>1){const T=r.slice(1);a.context?a.context=Array.isArray(a.context)?[...a.context,...T]:[a.context,...T]:a.context=T}}else r.length>1?(a.message=r[0],a.context=r.slice(1)):r.length===1?a.message=r[0]:a.message=void 0;return s.logLevel==="trace"&&(a.traceError=new Error("Trace")),s.badge&&(a.badge=s.badge),s.label&&(a.label=s.label),a}logger(e,s,r,...a){if(this.disabled)return;if(this.paused){this.messageQueue.push({messageObject:a,raw:s,type:e});return}const y=this.types[e],S=this.#o(y.logLevel);if(r||this.logLevels[S]>=this.logLevels[this.generalLogLevel]){let c=this.#n(e,y,...a),$;try{$=JSON.stringify([c.label,c.scope,c.type,c.message,c.prefix,c.suffix,c.context])}catch{$=void 0}const T=this.processors.size>0,k=(C=!1)=>{const R=(this.lastLog.count??0)-this.throttleMin;if(this.lastLog.object&&R>0){const I={...this.lastLog.object};R>1&&(I.repeated=R),this.#r(I,s),this.lastLog.count=1}if(C){for(const I of this.processors)c=I.process(c);if(c.dropped===!0)return;if(this.lastLog.object=c,T)try{this.lastLog.signature=JSON.stringify([c.label,c.scope,c.type,c.message,c.prefix,c.suffix,c.context])}catch{this.lastLog.signature=void 0}else this.lastLog.signature=$;this.#r(c,s)}};clearTimeout(this.lastLog.timeout);const A=c.date instanceof Date?c.date:new Date(c.date),F=this.lastLog.time?A.getTime()-this.lastLog.time.getTime():0;if(this.lastLog.time=A,F<this.throttle)try{const C=$;if(this.lastLog.object&&C!==void 0&&C===this.lastLog.signature&&(this.lastLog.count=(this.lastLog.count??0)+1,this.lastLog.count>this.throttleMin)){this.lastLog.timeout=setTimeout(k,this.throttle);return}}catch{}k(!0)}}}const pe=W;class de{#t;#e;#s;constructor(e={}){this.#e=e.formatters}setStringify(e){this.#t=e}process(e){this.#s===void 0&&(this.#s=ne({formatters:this.#e}));const s=this.#s;return e.message!==void 0&&(e.message=this.#i(s,e.message,e.context??[])),e}#i(e,s,r=[]){if(typeof s=="string")return e(s,r);if(typeof s=="object"&&s!==null){const a=s,y=Object.keys(a);for(let S=0;S<y.length;S+=1){const c=y[S],$=a[c];(typeof $=="string"||Array.isArray($)||typeof $=="object")&&(a[c]=this.#i(e,$,r))}}return s}}const me=x=>new pe({processors:[new de],reporters:[new le],...x}),we=me();export{xe as PailError,me as createPail,Te as createPailError,we as pail};
|
package/dist/index.server.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { InteractiveManager } from '@visulima/interactive-manager';
|
|
2
|
-
import { stringify } from 'safe-stable-stringify';
|
|
3
2
|
import { LiteralUnion } from 'type-fest';
|
|
4
3
|
import { M as Meta, D as DefaultLogTypes, L as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter, a as LoggerFunction, C as ConstructorOptions, S as ServerConstructorOptions } from "./packem_shared/types.d-Cz9S7jZh.js";
|
|
5
|
-
export {
|
|
4
|
+
export type { b as DefaultLoggerTypes, c as LoggerConfiguration, d as LoggerTypesAwareReporter, e as StreamAwareReporter } from "./packem_shared/types.d-Cz9S7jZh.js";
|
|
6
5
|
import '@visulima/colorize';
|
|
6
|
+
type Replacer = (number | string)[] | null | undefined | ((key: string, value: unknown) => string | number | boolean | null | object);
|
|
7
|
+
declare function stringify(value: undefined | symbol | ((...args: unknown[]) => unknown), replacer?: Replacer, space?: string | number): undefined;
|
|
8
|
+
declare function stringify(value: string | number | unknown[] | null | boolean | object, replacer?: Replacer, space?: string | number): string;
|
|
9
|
+
declare function stringify(value: unknown, replacer?: ((key: string, value: unknown) => unknown) | (number | string)[] | null | undefined, space?: string | number): string | undefined;
|
|
10
|
+
declare namespace stringify {
|
|
11
|
+
export function configure(options: StringifyOptions): typeof stringify;
|
|
12
|
+
}
|
|
13
|
+
interface StringifyOptions {
|
|
14
|
+
bigint?: boolean;
|
|
15
|
+
circularValue?: string | null | TypeErrorConstructor | ErrorConstructor;
|
|
16
|
+
deterministic?: boolean | ((a: string, b: string) => number);
|
|
17
|
+
maximumBreadth?: number;
|
|
18
|
+
maximumDepth?: number;
|
|
19
|
+
strict?: boolean;
|
|
20
|
+
}
|
|
7
21
|
/**
|
|
8
22
|
* Pail Browser Implementation.
|
|
9
23
|
*
|
|
@@ -29,9 +43,6 @@ import '@visulima/colorize';
|
|
|
29
43
|
*/
|
|
30
44
|
declare class PailBrowserImpl<T extends string = string, L extends string = string> {
|
|
31
45
|
#private;
|
|
32
|
-
protected timersMap: Map<string, number>;
|
|
33
|
-
protected countMap: Map<string, number>;
|
|
34
|
-
protected seqTimers: Set<string>;
|
|
35
46
|
protected readonly lastLog: {
|
|
36
47
|
count?: number;
|
|
37
48
|
object?: Meta<L>;
|
|
@@ -120,6 +131,20 @@ declare class PailBrowserImpl<T extends string = string, L extends string = stri
|
|
|
120
131
|
*/
|
|
121
132
|
wrapException(): void;
|
|
122
133
|
/**
|
|
134
|
+
* Removes the global exception/rejection handlers installed by {@link wrapException}.
|
|
135
|
+
*
|
|
136
|
+
* Counterpart to `wrapException()` (mirrors `wrapConsole()`/`restoreConsole()`).
|
|
137
|
+
* Safe to call when no handlers are installed.
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const logger = createPail();
|
|
141
|
+
* logger.wrapException();
|
|
142
|
+
* // ... later ...
|
|
143
|
+
* logger.restoreException(); // global handlers removed
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
restoreException(): void;
|
|
147
|
+
/**
|
|
123
148
|
* Disables all logging output.
|
|
124
149
|
*
|
|
125
150
|
* When disabled, all log calls will be silently ignored and no output
|