@visulima/pail 3.1.0 → 3.2.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 +59 -0
- package/LICENSE.md +3 -407
- package/README.md +298 -0
- package/dist/constants.d.ts +37 -0
- package/dist/index.browser.d.ts +47 -12
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +65 -40
- package/dist/index.server.js +533 -2
- package/dist/interactive/index.d.ts +2 -28
- package/dist/interactive/index.js +2 -1
- package/dist/interactive/interactive-manager.d.ts +108 -0
- package/dist/interactive/interactive-stream-hook.d.ts +68 -0
- package/dist/object-tree.d.ts +65 -7
- package/dist/object-tree.js +89 -2
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-C0AXk99i.js +58 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +1427 -0
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/pail.browser.d.ts +412 -0
- package/dist/pail.server.d.ts +233 -0
- package/dist/processor/caller/caller-processor.d.ts +40 -7
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/caller/get-caller-filename.d.ts +23 -0
- package/dist/processor/message-formatter-processor.d.ts +44 -9
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +70 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +39 -8
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +75 -15
- package/dist/progress-bar.js +404 -1
- package/dist/reporter/file/json-file-reporter.d.ts +39 -20
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +48 -0
- package/dist/reporter/http/abstract-http-reporter.d.ts +215 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +39 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +40 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/http/utils/compression.d.ts +7 -0
- package/dist/reporter/http/utils/log-size-error.d.ts +30 -0
- package/dist/reporter/http/utils/retry.d.ts +27 -0
- package/dist/reporter/json/abstract-json-reporter.d.ts +61 -0
- package/dist/reporter/json/index.browser.d.ts +3 -13
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -16
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/json/json-reporter.browser.d.ts +40 -0
- package/dist/reporter/json/json-reporter.server.d.ts +50 -0
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +83 -0
- package/dist/reporter/pretty/index.browser.d.ts +2 -13
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +2 -25
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +36 -0
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +70 -0
- package/dist/reporter/raw/raw-reporter.browser.d.ts +5 -0
- package/dist/reporter/raw/raw-reporter.server.d.ts +13 -0
- package/dist/reporter/simple/simple-reporter.server.d.ts +10 -14
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/reporter/utils/default-inspector-config.d.ts +3 -0
- package/dist/reporter/utils/format-label.d.ts +3 -0
- package/dist/spinner.d.ts +170 -104
- package/dist/spinner.js +2150 -1
- package/dist/types.d.ts +241 -0
- package/dist/utils/ansi-escapes.d.ts +4 -0
- package/dist/utils/arrayify.d.ts +2 -0
- package/dist/utils/get-longest-badge.d.ts +4 -0
- package/dist/utils/get-longest-label.d.ts +4 -0
- package/dist/utils/merge-types.d.ts +4 -0
- package/dist/utils/stream/safe-stream-handler.d.ts +21 -0
- package/dist/utils/write-console-log-based-on-level.d.ts +4 -0
- package/dist/utils/write-stream.d.ts +2 -0
- package/package.json +53 -4
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
- package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-json-reporter-CPsNkpz8.d.ts +0 -22
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DB2G-qlI.d.ts +0 -28
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/index-CysYvHXs.js +0 -8
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/index.d-BR1GjZri.d.ts +0 -53
- package/dist/packem_shared/index.d-oxZvg_y7.d.ts +0 -20
- package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/pail.browser-CmWcqnn9.d.ts +0 -64
- package/dist/packem_shared/types-DVzG8TWL.d.ts +0 -95
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
package/README.md
CHANGED
|
@@ -104,6 +104,27 @@ Pail supports the logging levels described by [RFC 5424][rfc-5424].
|
|
|
104
104
|
|
|
105
105
|
- `EMERGENCY`: Emergency: system is unusable.
|
|
106
106
|
|
|
107
|
+
### Bypass Log Level Filter with Force
|
|
108
|
+
|
|
109
|
+
Normally, the logger will only output messages at or above the configured level.
|
|
110
|
+
|
|
111
|
+
However, you can force a log to be emitted regardless of the current level:
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { createPail } from "@visulima/pail";
|
|
115
|
+
|
|
116
|
+
const logger = createPail({
|
|
117
|
+
logLevel: "warn", // Only show warning and above
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
logger.info("This won't be logged"); // Filtered out
|
|
121
|
+
|
|
122
|
+
logger.force.error("Something went wrong!");
|
|
123
|
+
logger.force.info("This will show even if level is set to 'warn'");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
⚠️ **Use this with care**—force is designed for exceptional situations where logs must be guaranteed to appear.
|
|
127
|
+
|
|
107
128
|
### Reporters
|
|
108
129
|
|
|
109
130
|
Reporters are responsible for writing the log messages to the console or a file. `pail` comes with a few built-in reporters:
|
|
@@ -112,6 +133,7 @@ Reporters are responsible for writing the log messages to the console or a file.
|
|
|
112
133
|
| ---------------------------- | ------------------------- |
|
|
113
134
|
| `JsonReporter` | `JsonReporter` |
|
|
114
135
|
| `PrettyReporter` | `PrettyReporter` |
|
|
136
|
+
| `HttpReporter` | `HttpReporter` |
|
|
115
137
|
| x | `SimpleReporter` |
|
|
116
138
|
| x | `FileReporter` |
|
|
117
139
|
|
|
@@ -131,6 +153,10 @@ A processor can be added to a logger directly (and is subsequently applied to lo
|
|
|
131
153
|
> Use `npm install @visulima/redact`, `pnpm add @visulima/redact` or `yarn add @visulima/redact` to install it.
|
|
132
154
|
- `MessageFormatterProcessor` - formats the log message (Util.format-like unescaped string formatting utility) [@visulima/fmt][fmt]
|
|
133
155
|
- `ErrorProcessor` - serializes the error with cause object to a std error object that can be serialized.
|
|
156
|
+
- `OpenTelemetryProcessor` - adds OpenTelemetry trace context to log metadata
|
|
157
|
+
> The OpenTelemetry processor needs the "@opentelemetry/api" package to work.
|
|
158
|
+
> Use `npm install @opentelemetry/api`, `pnpm add @opentelemetry/api` or `yarn add @opentelemetry/api` to install it.
|
|
159
|
+
> Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span and adds them to the log context for distributed tracing correlation.
|
|
134
160
|
|
|
135
161
|
## Usage
|
|
136
162
|
|
|
@@ -249,6 +275,66 @@ foo();
|
|
|
249
275
|
|
|
250
276
|

|
|
251
277
|
|
|
278
|
+
## Child Loggers
|
|
279
|
+
|
|
280
|
+
Create child loggers that inherit settings from their parent while overriding only what you need. Child loggers are independent instances with their own state (timers, counters, etc.), but they inherit configuration like reporters, processors, types, log levels, and throttle settings.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { createPail } from "@visulima/pail";
|
|
284
|
+
import { PrettyReporter } from "@visulima/pail/reporter/pretty";
|
|
285
|
+
|
|
286
|
+
const parent = createPail({
|
|
287
|
+
logLevel: "informational",
|
|
288
|
+
types: {
|
|
289
|
+
http: {
|
|
290
|
+
label: "HTTP",
|
|
291
|
+
logLevel: "informational",
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
reporters: [new PrettyReporter()],
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// Child inherits all parent settings
|
|
298
|
+
const child = parent.child();
|
|
299
|
+
child.http("GET /api/users 200"); // Inherits http type from parent
|
|
300
|
+
child.info("Request processed"); // Inherits log level from parent
|
|
301
|
+
|
|
302
|
+
// Child can override specific settings
|
|
303
|
+
const debugChild = parent.child({ logLevel: "debug" });
|
|
304
|
+
debugChild.debug("Detailed debug info"); // Uses debug level
|
|
305
|
+
|
|
306
|
+
// Child can add new types
|
|
307
|
+
const dbChild = parent.child({
|
|
308
|
+
types: {
|
|
309
|
+
db: {
|
|
310
|
+
label: "DB",
|
|
311
|
+
logLevel: "informational",
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
dbChild.db("Query executed"); // New type available
|
|
316
|
+
dbChild.http("GET /api 200"); // Still has parent types
|
|
317
|
+
|
|
318
|
+
// Child scope extends parent scope
|
|
319
|
+
const scopedChild = parent.child({ scope: ["api"] });
|
|
320
|
+
// Logs will include both parent and child scope if parent had scope set
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### What Gets Inherited
|
|
324
|
+
|
|
325
|
+
- **Types**: Child types are merged with parent types (child can add new or override existing)
|
|
326
|
+
- **Reporters**: Child reporters are added to parent reporters (both are used)
|
|
327
|
+
- **Processors**: Child processors are added to parent processors (both are applied)
|
|
328
|
+
- **Log Levels**: Child log levels override parent log levels
|
|
329
|
+
- **Scope**: Child scope extends parent scope (combined into array)
|
|
330
|
+
- **Throttle Settings**: Child inherits parent throttle settings unless overridden
|
|
331
|
+
- **Timer Messages**: Child inherits parent timer messages unless overridden
|
|
332
|
+
|
|
333
|
+
### What's Independent
|
|
334
|
+
|
|
335
|
+
- **State**: Each child logger has its own timers, counters, and message queue
|
|
336
|
+
- **Disabled/Paused**: Child logger state is independent from parent
|
|
337
|
+
|
|
252
338
|
## Interactive Loggers (Only on if stdout and stderr is a TTY)
|
|
253
339
|
|
|
254
340
|
To initialize an interactive logger, create a new pail instance with the `interactive` attribute set to `true`.
|
|
@@ -765,6 +851,218 @@ console.log(tree);
|
|
|
765
851
|
4. **Configuration Display**: Show configuration trees in terminal applications
|
|
766
852
|
5. **Data Inspection**: Inspect deeply nested data structures
|
|
767
853
|
|
|
854
|
+
## HTTP Reporter
|
|
855
|
+
|
|
856
|
+
The HTTP Reporter sends logs to HTTP endpoints, making it perfect for centralized logging services, log aggregation platforms, or custom logging APIs. It supports batching, compression, retries, rate limiting, and Edge Runtime compatibility.
|
|
857
|
+
|
|
858
|
+
**Note:** When used in Edge Runtime environments (Next.js Edge, Cloudflare Workers, etc.), the package automatically resolves to an Edge-compatible version that disables compression and uses Edge-compatible APIs. You don't need to import a separate class - just use `HttpReporter` and the package handles the routing.
|
|
859
|
+
|
|
860
|
+
### Basic Usage
|
|
861
|
+
|
|
862
|
+
```typescript
|
|
863
|
+
import { createPail } from "@visulima/pail";
|
|
864
|
+
import { HttpReporter } from "@visulima/pail/reporter/http";
|
|
865
|
+
|
|
866
|
+
const logger = createPail({
|
|
867
|
+
reporters: [
|
|
868
|
+
new HttpReporter({
|
|
869
|
+
url: "https://api.example.com/logs",
|
|
870
|
+
method: "POST",
|
|
871
|
+
headers: {
|
|
872
|
+
Authorization: "Bearer your-token",
|
|
873
|
+
},
|
|
874
|
+
}),
|
|
875
|
+
],
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
logger.info("Application started", { version: "1.0.0" });
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
### Edge Runtime Compatibility
|
|
882
|
+
|
|
883
|
+
For Edge Runtime environments, enable Edge compatibility mode explicitly (or let the package auto-detect):
|
|
884
|
+
|
|
885
|
+
```typescript
|
|
886
|
+
import { createPail } from "@visulima/pail";
|
|
887
|
+
import { HttpReporter } from "@visulima/pail/reporter/http";
|
|
888
|
+
|
|
889
|
+
const logger = createPail({
|
|
890
|
+
reporters: [
|
|
891
|
+
new HttpReporter({
|
|
892
|
+
url: "https://api.example.com/logs",
|
|
893
|
+
edgeCompat: true, // Enable Edge compatibility (auto-enabled in Edge environments)
|
|
894
|
+
headers: {
|
|
895
|
+
Authorization: "Bearer your-token",
|
|
896
|
+
},
|
|
897
|
+
}),
|
|
898
|
+
],
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
logger.info("Edge function executed");
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
When `edgeCompat` is enabled (or automatically enabled in Edge environments), compression is disabled and Edge-compatible APIs are used.
|
|
905
|
+
|
|
906
|
+
### Batching
|
|
907
|
+
|
|
908
|
+
HTTP Reporter supports automatic batching to reduce network requests:
|
|
909
|
+
|
|
910
|
+
```typescript
|
|
911
|
+
const logger = createPail({
|
|
912
|
+
reporters: [
|
|
913
|
+
new HttpReporter({
|
|
914
|
+
url: "https://api.example.com/logs",
|
|
915
|
+
enableBatchSend: true,
|
|
916
|
+
batchSize: 100, // Send when 100 logs are queued
|
|
917
|
+
batchSendTimeout: 5000, // Or send after 5 seconds
|
|
918
|
+
batchMode: "delimiter", // Options: "delimiter", "array", "field"
|
|
919
|
+
batchSendDelimiter: "\n", // Delimiter for batch entries
|
|
920
|
+
}),
|
|
921
|
+
],
|
|
922
|
+
});
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
**Batch Modes:**
|
|
926
|
+
|
|
927
|
+
- `delimiter` (default): Join entries with a delimiter (e.g., newline-delimited JSON)
|
|
928
|
+
- `array`: Send entries as a JSON array
|
|
929
|
+
- `field`: Wrap entries in an object with a field name (requires `batchFieldName`)
|
|
930
|
+
|
|
931
|
+
```typescript
|
|
932
|
+
// Field mode example (e.g., for Logflare)
|
|
933
|
+
new HttpReporter({
|
|
934
|
+
url: "https://api.logflare.app/logs",
|
|
935
|
+
batchMode: "field",
|
|
936
|
+
batchFieldName: "batch", // Wraps entries in { batch: [...] }
|
|
937
|
+
});
|
|
938
|
+
```
|
|
939
|
+
|
|
940
|
+
### Compression
|
|
941
|
+
|
|
942
|
+
Enable gzip compression to reduce payload size:
|
|
943
|
+
|
|
944
|
+
```typescript
|
|
945
|
+
const logger = createPail({
|
|
946
|
+
reporters: [
|
|
947
|
+
new HttpReporter({
|
|
948
|
+
url: "https://api.example.com/logs",
|
|
949
|
+
compression: true, // Enable gzip compression
|
|
950
|
+
}),
|
|
951
|
+
],
|
|
952
|
+
});
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
**Note:** Compression is automatically disabled when Edge compatibility mode is enabled (either via `edgeCompat: true` or automatically in Edge Runtime environments).
|
|
956
|
+
|
|
957
|
+
### Retry Logic
|
|
958
|
+
|
|
959
|
+
Configure retry behavior for failed requests:
|
|
960
|
+
|
|
961
|
+
```typescript
|
|
962
|
+
const logger = createPail({
|
|
963
|
+
reporters: [
|
|
964
|
+
new HttpReporter({
|
|
965
|
+
url: "https://api.example.com/logs",
|
|
966
|
+
maxRetries: 3, // Retry up to 3 times
|
|
967
|
+
retryDelay: 1000, // Base delay: 1 second
|
|
968
|
+
respectRateLimit: true, // Wait on 429 responses
|
|
969
|
+
}),
|
|
970
|
+
],
|
|
971
|
+
});
|
|
972
|
+
```
|
|
973
|
+
|
|
974
|
+
### Error Handling
|
|
975
|
+
|
|
976
|
+
Handle errors with custom callbacks:
|
|
977
|
+
|
|
978
|
+
```typescript
|
|
979
|
+
const logger = createPail({
|
|
980
|
+
reporters: [
|
|
981
|
+
new HttpReporter({
|
|
982
|
+
url: "https://api.example.com/logs",
|
|
983
|
+
onError: (error) => {
|
|
984
|
+
console.error("Failed to send log:", error);
|
|
985
|
+
// Send to fallback service, alert, etc.
|
|
986
|
+
},
|
|
987
|
+
onDebug: (entry) => {
|
|
988
|
+
console.log("Sending log entry:", entry);
|
|
989
|
+
},
|
|
990
|
+
onDebugRequestResponse: ({ req, res }) => {
|
|
991
|
+
console.log("Request:", req.method, req.url);
|
|
992
|
+
console.log("Response:", res.status, res.statusText);
|
|
993
|
+
},
|
|
994
|
+
}),
|
|
995
|
+
],
|
|
996
|
+
});
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
### Payload Customization
|
|
1000
|
+
|
|
1001
|
+
Customize the payload format with a template function:
|
|
1002
|
+
|
|
1003
|
+
```typescript
|
|
1004
|
+
const logger = createPail({
|
|
1005
|
+
reporters: [
|
|
1006
|
+
new HttpReporter({
|
|
1007
|
+
url: "https://api.example.com/logs",
|
|
1008
|
+
payloadTemplate: ({ data, logLevel, message }) => {
|
|
1009
|
+
return JSON.stringify({
|
|
1010
|
+
timestamp: new Date().toISOString(),
|
|
1011
|
+
level: logLevel,
|
|
1012
|
+
message,
|
|
1013
|
+
metadata: data,
|
|
1014
|
+
});
|
|
1015
|
+
},
|
|
1016
|
+
}),
|
|
1017
|
+
],
|
|
1018
|
+
});
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
### Size Limits
|
|
1022
|
+
|
|
1023
|
+
Configure maximum sizes to prevent oversized payloads:
|
|
1024
|
+
|
|
1025
|
+
```typescript
|
|
1026
|
+
const logger = createPail({
|
|
1027
|
+
reporters: [
|
|
1028
|
+
new HttpReporter({
|
|
1029
|
+
url: "https://api.example.com/logs",
|
|
1030
|
+
maxLogSize: 1_048_576, // 1MB per log entry
|
|
1031
|
+
maxPayloadSize: 5_242_880, // 5MB per batch payload
|
|
1032
|
+
}),
|
|
1033
|
+
],
|
|
1034
|
+
});
|
|
1035
|
+
```
|
|
1036
|
+
|
|
1037
|
+
When a log entry exceeds `maxLogSize`, a `LogSizeError` is thrown. When a batch exceeds `maxPayloadSize`, it's automatically split into smaller batches.
|
|
1038
|
+
|
|
1039
|
+
### Configuration Options
|
|
1040
|
+
|
|
1041
|
+
| Option | Type | Default | Description |
|
|
1042
|
+
| ------------------------ | ------------------------------------------ | -------------------- | --------------------------------------------- |
|
|
1043
|
+
| `url` | `string` | **required** | HTTP endpoint URL |
|
|
1044
|
+
| `method` | `string` | `"POST"` | HTTP method |
|
|
1045
|
+
| `headers` | `Record<string, string> \| (() => ...)` | `{}` | Request headers (object or function) |
|
|
1046
|
+
| `contentType` | `string` | `"application/json"` | Content type for single requests |
|
|
1047
|
+
| `batchContentType` | `string` | `"application/json"` | Content type for batch requests |
|
|
1048
|
+
| `enableBatchSend` | `boolean` | `true` | Enable automatic batching |
|
|
1049
|
+
| `batchSize` | `number` | `100` | Number of logs to batch before sending |
|
|
1050
|
+
| `batchSendTimeout` | `number` | `5000` | Timeout (ms) to send batch regardless of size |
|
|
1051
|
+
| `batchMode` | `"delimiter" \| "array" \| "field"` | `"delimiter"` | Batch format mode |
|
|
1052
|
+
| `batchSendDelimiter` | `string` | `"\n"` | Delimiter for batch entries |
|
|
1053
|
+
| `batchFieldName` | `string` | `undefined` | Field name for "field" batch mode |
|
|
1054
|
+
| `compression` | `boolean` | `false` | Enable gzip compression |
|
|
1055
|
+
| `maxRetries` | `number` | `3` | Maximum retry attempts |
|
|
1056
|
+
| `retryDelay` | `number` | `1000` | Base delay between retries (ms) |
|
|
1057
|
+
| `respectRateLimit` | `boolean` | `true` | Wait on 429 rate limit responses |
|
|
1058
|
+
| `maxLogSize` | `number` | `1048576` | Maximum size per log entry (bytes) |
|
|
1059
|
+
| `maxPayloadSize` | `number` | `5242880` | Maximum size per payload (bytes) |
|
|
1060
|
+
| `edgeCompat` | `boolean` | `false` | Enable Edge Runtime compatibility |
|
|
1061
|
+
| `onError` | `(error: Error) => void` | `undefined` | Error callback |
|
|
1062
|
+
| `onDebug` | `(entry: Record<string, unknown>) => void` | `undefined` | Debug callback for log entries |
|
|
1063
|
+
| `onDebugRequestResponse` | `(reqRes: {...}) => void` | `undefined` | Debug callback for HTTP requests/responses |
|
|
1064
|
+
| `payloadTemplate` | `(data: {...}) => string` | `undefined` | Custom payload formatter |
|
|
1065
|
+
|
|
768
1066
|
## Integrations
|
|
769
1067
|
|
|
770
1068
|
### Use with @visulima/boxen
|
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,12 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { PailBrowserType } from "./pail.d.ts";
|
|
2
|
+
import type { ConstructorOptions } from "./types.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Pail logger instance configured for browser environments.
|
|
5
|
+
*
|
|
6
|
+
* This factory function creates a browser-compatible logger with default processors
|
|
7
|
+
* and reporters suitable for client-side logging.
|
|
8
|
+
* @template T - Custom logger types
|
|
9
|
+
* @template L - Log level types
|
|
10
|
+
* @param options Configuration options for the logger
|
|
11
|
+
* @returns A new PailBrowser instance
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createPail } from "@visulima/pail";
|
|
15
|
+
*
|
|
16
|
+
* const logger = createPail({
|
|
17
|
+
* logLevel: "debug",
|
|
18
|
+
* types: {
|
|
19
|
+
* custom: {
|
|
20
|
+
* color: "blue",
|
|
21
|
+
* label: "CUSTOM",
|
|
22
|
+
* logLevel: "info"
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* logger.info("Hello world!");
|
|
28
|
+
* logger.custom("Custom message");
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const createPail: <T extends string = string, L extends string = string>(options?: ConstructorOptions<T, L>) => PailBrowserType<T, L>;
|
|
32
|
+
/**
|
|
33
|
+
* Default Pail logger instance for browser environments.
|
|
34
|
+
*
|
|
35
|
+
* A pre-configured logger instance ready for immediate use in browser environments.
|
|
36
|
+
* Uses default configuration with JSON reporter and message formatter processor.
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { pail } from "@visulima/pail";
|
|
40
|
+
*
|
|
41
|
+
* pail.info("Application started");
|
|
42
|
+
* pail.error("Something went wrong", new Error("Test error"));
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const pail: PailBrowserType<string, string>;
|
|
46
|
+
export type { PailBrowserType as Pail } from "./pail.d.ts";
|
|
47
|
+
export type { ConstructorOptions, DefaultLoggerTypes, DefaultLogTypes, ExtendedRfc5424LogLevels, LoggerConfiguration, LoggerFunction, LoggerTypesAwareReporter, LoggerTypesConfig, Processor, Reporter, StreamAwareReporter, } from "./types.d.ts";
|
package/dist/index.browser.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { P as PailBrowser } from './packem_shared/pail.browser-CPjQrsyy.js';
|
|
2
|
+
import MessageFormatterProcessor from './processor/message-formatter-processor.js';
|
|
3
|
+
import JsonReporter from './packem_shared/JsonReporter-DcM2LBX9.js';
|
|
4
|
+
|
|
5
|
+
const createPail = (options) => new PailBrowser({
|
|
6
|
+
processors: [new MessageFormatterProcessor()],
|
|
7
|
+
reporters: [new JsonReporter()],
|
|
8
|
+
...options
|
|
9
|
+
});
|
|
10
|
+
const pail = createPail();
|
|
11
|
+
|
|
12
|
+
export { createPail, pail };
|
package/dist/index.server.d.ts
CHANGED
|
@@ -1,40 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import type { PailServerType } from "./pail.d.ts";
|
|
2
|
+
import type { ServerConstructorOptions } from "./types.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Pail logger instance configured for server environments.
|
|
5
|
+
*
|
|
6
|
+
* This factory function creates a server-compatible logger with default processors
|
|
7
|
+
* and reporters suitable for Node.js environments. It automatically configures
|
|
8
|
+
* log levels based on environment variables and sets up pretty printing.
|
|
9
|
+
* @template T - Custom logger types
|
|
10
|
+
* @template L - Log level types
|
|
11
|
+
* @param options Configuration options for the logger
|
|
12
|
+
* @returns A new PailServer instance
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { createPail } from "@visulima/pail";
|
|
16
|
+
*
|
|
17
|
+
* const logger = createPail({
|
|
18
|
+
* logLevel: "debug",
|
|
19
|
+
* types: {
|
|
20
|
+
* http: {
|
|
21
|
+
* color: "blue",
|
|
22
|
+
* label: "HTTP",
|
|
23
|
+
* logLevel: "info"
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* logger.info("Server started on port 3000");
|
|
29
|
+
* logger.http("GET /api/users 200");
|
|
30
|
+
* ```
|
|
31
|
+
* @example
|
|
32
|
+
* ```bash
|
|
33
|
+
* # Control log level via environment variable
|
|
34
|
+
* PAIL_LOG_LEVEL=debug node app.js
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const createPail: <T extends string = string, L extends string = string>(options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;
|
|
38
|
+
/**
|
|
39
|
+
* Default Pail logger instance for server environments.
|
|
40
|
+
*
|
|
41
|
+
* A pre-configured logger instance ready for immediate use in Node.js environments.
|
|
42
|
+
* Uses default configuration with pretty reporter, message formatter processor,
|
|
43
|
+
* and automatic log level detection based on environment variables.
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { pail } from "@visulima/pail";
|
|
47
|
+
*
|
|
48
|
+
* pail.info("Server listening on port 3000");
|
|
49
|
+
* pail.error("Database connection failed", error);
|
|
50
|
+
* pail.success("Migration completed successfully");
|
|
51
|
+
* ```
|
|
52
|
+
* @example
|
|
53
|
+
* ```bash
|
|
54
|
+
* # Set log level via environment
|
|
55
|
+
* NODE_ENV=production node app.js
|
|
56
|
+
* PAIL_LOG_LEVEL=debug node app.js
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const pail: PailServerType<string, string>;
|
|
60
|
+
export type { PailServerType as Pail } from "./pail.d.ts";
|
|
61
|
+
export type { MultiBarOptions, ProgressBarOptions, ProgressBarPayload, ProgressBarStyle, SingleBarOptions } from "./progress-bar.d.ts";
|
|
62
|
+
export { getBarChar, MultiProgressBar, ProgressBar } from "./progress-bar.d.ts";
|
|
63
|
+
export type { SpinnerIcons, SpinnerOptions, SpinnerStartOptions, SpinnerStyle } from "./spinner.d.ts";
|
|
64
|
+
export { MultiSpinner, Spinner } from "./spinner.d.ts";
|
|
65
|
+
export type { ConstructorOptions, DefaultLoggerTypes, DefaultLogTypes, ExtendedRfc5424LogLevels, LoggerConfiguration, LoggerFunction, LoggerTypesAwareReporter, LoggerTypesConfig, Processor, Reporter, StreamAwareReporter, } from "./types.d.ts";
|