clv.ts 631 B

1234567891011121314151617181920212223242526
  1. import { readLines } from "https://deno.land/std@0.83.0/io/mod.ts";
  2. interface LogEntry {
  3. log: string;
  4. stream: "stdout";
  5. time: Date;
  6. }
  7. const encoder = new TextEncoder();
  8. const filenames = Deno.args;
  9. for (const filename of filenames) {
  10. const file = await Deno.open(filename);
  11. for await (const line of readLines(file)) {
  12. if (line) {
  13. const parsedLine = JSON.parse(
  14. line,
  15. (key, value) => key === "time" ? new Date(value) : value,
  16. ) as LogEntry;
  17. await Deno.stdout.write(
  18. encoder.encode(`${parsedLine.time.toISOString()} ${parsedLine.log}`),
  19. );
  20. }
  21. }
  22. file.close();
  23. }