Skip to content

Instantly share code, notes, and snippets.

@maxwofford
Created October 31, 2022 16:00
Show Gist options
  • 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/[email protected]/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