canary-log-viewer.ts 646 B

1234567891011121314151617181920212223242526272829
  1. import readline from "readline";
  2. import fs from "fs";
  3. import * as Rx from "rxjs";
  4. import { map, pluck, takeUntil } from "rxjs/operators";
  5. type LogLine = {
  6. log: string;
  7. stream: string;
  8. time: string;
  9. };
  10. const rl = readline.createInterface({
  11. input: fs.createReadStream("testdata/user.log")
  12. });
  13. Rx.fromEvent<string>(rl, "line")
  14. .pipe(
  15. takeUntil(Rx.fromEvent(rl, "close")),
  16. map<string, LogLine>(line => JSON.parse(line)),
  17. pluck("log"),
  18. map(log => log.replace(/\n$/, ""))
  19. )
  20. .subscribe({
  21. next: console.log,
  22. error: console.error,
  23. complete: () => rl.close()
  24. });