fix(logger.js): recreate log directory if deleted during runtime
This commit is contained in:
parent
4a81f0411f
commit
e32a4c6abc
@ -75,13 +75,21 @@ constructor(options = {}) {
|
||||
? path.join(this.options.logDirectory, this.options.userActivityLogFile)
|
||||
: path.join(this.options.logDirectory, this.options.apiLogFile);
|
||||
|
||||
// Check if the log directory exists before writing
|
||||
try {
|
||||
// Ensure the directory exists
|
||||
if (!fs.existsSync(this.options.logDirectory)) {
|
||||
fs.mkdirSync(this.options.logDirectory, { recursive: true });
|
||||
console.log(`Log directory recreated at: ${this.options.logDirectory}`);
|
||||
}
|
||||
|
||||
// Now write the log
|
||||
fs.appendFileSync(logFile, content + '\n');
|
||||
} catch (err) {
|
||||
console.error(`Error writing to log file: ${err.message}`);
|
||||
// Optionally fall back to console logging if file writing fails
|
||||
// Fall back to console logging if file writing fails
|
||||
if (this.options.logToConsole) {
|
||||
console.error(`Failed to write to log file, logging to console instead: ${content}`);
|
||||
console.log(`Failed to write to log file, logging to console instead: ${content}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user