fix(debug): Make log file not crash the entire instance if it can't be created

This commit is contained in:
tecc 2022-11-09 08:02:30 +01:00
parent ad1d7888ba
commit 96ac878294
No known key found for this signature in database
GPG Key ID: 400AAD881FCC028B

View File

@ -58,15 +58,20 @@ function getLogFile(name: string) {
}
const loggerTransport: Parameters<typeof pino.multistream>[0] = [
{
stream: fs.createWriteStream(getLogFile('debug'), { flags: 'a' }),
level: "debug"
},
{
stream: pinoPretty(),
level: "info"
}
];
try {
loggerTransport.push({
stream: fs.createWriteStream(getLogFile('debug'), { flags: 'a' }),
level: "debug"
});
} catch (e) {
// well, whoops!
console.warn("No file logs: %O", e);
}
const multistream = pino.multistream(loggerTransport);