-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.js
25 lines (20 loc) · 833 Bytes
/
json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Ensure Bun compatibility. [It currently lacks support for TextEncoderStream](https://github.com/oven-sh/bun/issues/5648)
import "@denosaurs/log/transforms/text_encoder_stream";
import { ConsoleReadableStream } from "@denosaurs/log";
import { StdoutWritableStream } from "@denosaurs/log/writables/std";
import { JsonStringifyStream } from "@std/json";
// Capture logs from the console
const stream = new ConsoleReadableStream();
stream
// Stringify the logs to JSON
.pipeThrough(new JsonStringifyStream())
// Encode the output to an UTF-8 byte stream
.pipeThrough(new TextEncoderStream())
// Pipe the output to stdout
.pipeTo(new StdoutWritableStream());
// Log some messages
console.log("Hello, world!");
console.group("Group 1");
console.debug("Debug message");
console.groupEnd();
console.info("Info message");