Created
April 25, 2020 14:29
-
-
Save confraria/f7e6af40c726542276275f5492d9cc44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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