Skip to content

Instantly share code, notes, and snippets.

@maxwofford
Created October 31, 2022 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxwofford/a7858fb027200c2ec0873d42a7113ae1 to your computer and use it in GitHub Desktop.
Save maxwofford/a7858fb027200c2ec0873d42a7113ae1 to your computer and use it in GitHub Desktop.
import { readLines } from "https://deno.land/std@0.161.0/io/buffer.ts";
async function main() {
for await (const line of readLines(Deno.stdin)) {
let parts = line.split(" ");
if (parts.length == 14) {
let timestamp = new Date(parts[0]).getTime() / 1000;
let ip = parts[7].replace("fwd=", "").replace(/"/g, "");
let request = parts[4].replace("path=", "").replace(/"/g, "");
let host = parts[5].replace("host=", "").replace(/"/g, "");
let dyno = parts[8].replace("dyno=", "").replace(/"/g, "");
let status = parts[11].replace("status=", "");
let size = parts[12].replace("bytes=", "");
console.log(
`${timestamp}|${ip}|${request}|${status}|${size}|||||${host}|${dyno}`,
);
}
}
}
console.log("reading lines from stdin");
main();
// heroku logs --tail --ps router -a api2-hackclub | deno run ./heroku-to-clf.js | logstalgia - --sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment