Skip to content

Commit

Permalink
Create TimestampTransformer and use it in EwtConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
pzich committed Apr 18, 2024
1 parent ec35b6a commit 88b69af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/ewt-console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ColoredConsole, coloredConsoleStyles } from "../util/console-color";
import { sleep } from "../util/sleep";
import { LineBreakTransformer } from "../util/line-break-transformer";
import { TimestampTransformer } from "../util/timestamp-transformer";
import { Logger } from "../const";

export class EwtConsole extends HTMLElement {
Expand Down Expand Up @@ -95,6 +96,7 @@ export class EwtConsole extends HTMLElement {
signal: abortSignal,
})
.pipeThrough(new TransformStream(new LineBreakTransformer()))
.pipeThrough(new TransformStream(new TimestampTransformer()))
.pipeTo(
new WritableStream({
write: (chunk) => {
Expand Down
12 changes: 12 additions & 0 deletions src/util/timestamp-transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class TimestampTransformer implements Transformer<string, string> {
transform(
chunk: string,
controller: TransformStreamDefaultController<string>,
) {
const date = new Date();
const h = date.getHours().toString().padStart(2, '0');
const m = date.getMinutes().toString().padStart(2, '0');
const s = date.getSeconds().toString().padStart(2, '0');
controller.enqueue(`[${h}:${m}:${s}]${chunk}`);
}
}

0 comments on commit 88b69af

Please sign in to comment.