spooder 5.1.2 → 5.1.3
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/README.md +21 -4
- package/package.json +1 -1
- package/src/api.ts +3 -3
package/README.md
CHANGED
|
@@ -474,8 +474,8 @@ In addition to the information provided by the developer, `spooder` also include
|
|
|
474
474
|
|
|
475
475
|
```ts
|
|
476
476
|
// logging
|
|
477
|
-
log(message: string);
|
|
478
|
-
log_error(message: string);
|
|
477
|
+
log(message: string, ...params: any[]);
|
|
478
|
+
log_error(message: string, ...params: any[]);
|
|
479
479
|
log_create_logger(prefix: string, color: ColorInput);
|
|
480
480
|
log_list(input: any[], delimiter = ', ');
|
|
481
481
|
|
|
@@ -595,7 +595,7 @@ HTTP_STATUS_CODE: { OK_200: 200, NotFound_404: 404, ... };
|
|
|
595
595
|
<a id="api-logging"></a>
|
|
596
596
|
## API > Logging
|
|
597
597
|
|
|
598
|
-
### 🔧 `log(message: string)`
|
|
598
|
+
### 🔧 `log(message: string, ...params: any[])`
|
|
599
599
|
Print a message to the console using the default logger. Wrapping text segments in curly braces will highlight those segments with colour.
|
|
600
600
|
|
|
601
601
|
```ts
|
|
@@ -603,7 +603,24 @@ log('Hello, {world}!');
|
|
|
603
603
|
// > [info] Hello, world!
|
|
604
604
|
```
|
|
605
605
|
|
|
606
|
-
|
|
606
|
+
Formatting parameters are supported using standard console logging formatters.
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
log('My object: %o', { foo: 'bar' });
|
|
610
|
+
// > [info] My object: { foo: 'bar' }
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
| Specifier | Description |
|
|
614
|
+
|-----------|-------------|
|
|
615
|
+
| `%s` | String |
|
|
616
|
+
| `%d` | Integer |
|
|
617
|
+
| `%i` | Integer (same as %d) |
|
|
618
|
+
| `%f` | Floating point |
|
|
619
|
+
| `%o` | Object (pretty-printed) |
|
|
620
|
+
| `%O` | Object (expanded/detailed) |
|
|
621
|
+
| `%j` | JSON string |
|
|
622
|
+
|
|
623
|
+
### 🔧 `log_error(message: string, ...params: any[])`
|
|
607
624
|
Print an error message to the console. Wrapping text segments in curly braces will highlight those segments. This works the same as `log()` except it's red, so you know it's bad.
|
|
608
625
|
|
|
609
626
|
```ts
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -106,8 +106,8 @@ export function log_create_logger(label: string, color: ColorInput = 'blue') {
|
|
|
106
106
|
const ansi = Bun.color(color, 'ansi-256') ?? '\x1b[38;5;6m';
|
|
107
107
|
const prefix = `[${ansi}${label}\x1b[0m] `;
|
|
108
108
|
|
|
109
|
-
return (message: string) => {
|
|
110
|
-
|
|
109
|
+
return (message: string, ...params: any[]) => {
|
|
110
|
+
console.log(prefix + message.replace(/\{([^}]+)\}/g, `${ansi}$1\x1b[0m`), ...params);
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -366,7 +366,7 @@ async function handle_error(prefix: string, err_message_or_obj: string | object,
|
|
|
366
366
|
if (process.env.SPOODER_ENV === 'dev') {
|
|
367
367
|
log_spooder(`[{dev}] dispatch_report ${prefix + error_message}`);
|
|
368
368
|
log_spooder('[{dev}] without {--dev}, this would raise a canary report');
|
|
369
|
-
log_spooder(
|
|
369
|
+
log_spooder('[{dev}] %O', final_err);
|
|
370
370
|
} else {
|
|
371
371
|
await dispatch_report(prefix + error_message, final_err);
|
|
372
372
|
}
|