Logger - log to txt file

I am trying to use this to clone console.log logs to a txt file. Any way I can do the same for the sapphire logger as well? Thanks.
import * as fs from "fs";

const filePath = `./logs/console/${new Date().toISOString().replace(/:/g, "_")}.txt`;
const logStream = fs.createWriteStream(filePath, { flags: "a" }); // Append mode

const originalLog = console.log;
console.log = function(msg) {
logStream.write(`${msg}\n`);
originalLog.apply(console, msg);
};
import * as fs from "fs";

const filePath = `./logs/console/${new Date().toISOString().replace(/:/g, "_")}.txt`;
const logStream = fs.createWriteStream(filePath, { flags: "a" }); // Append mode

const originalLog = console.log;
console.log = function(msg) {
logStream.write(`${msg}\n`);
originalLog.apply(console, msg);
};
2 Replies
kyra
kyra2mo ago
You’d do this with a plugin, and speaking of which, thanks for reminding me of adding transports there
Favna
Favna2mo ago
Also as I always say, it should be noted that if you host your bot with either pm2 or docker that those tools already sent all logs to a file so doing so manually is double logging.
Want results from more Discord servers?
Add your server