Skip to content

Instantly share code, notes, and snippets.

@confraria
Created April 25, 2020 14:29
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 confraria/f7e6af40c726542276275f5492d9cc44 to your computer and use it in GitHub Desktop.
Save confraria/f7e6af40c726542276275f5492d9cc44 to your computer and use it in GitHub Desktop.
const streams = {};
function callback(topic, message) {
const [type, cluster] = topic.split("/");
if (type === "log") {
let stream = streams[topic];
if (!stream) {
stream = streams[topic] = fs.createWriteStream(`log_${cluster}.txt`, {
flags: "a",
});
}
const ts = new Date().toISOString();
stream.write(`${ts} > ${readMessage(message)}\n`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment