Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename old log file
  • Loading branch information
msujew committed Feb 10, 2025
commit f62f2382a301487f19b3a07162bcd8b3aea92120
10 changes: 10 additions & 0 deletions packages/core/src/node/logger-cli-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ export class LogLevelCliContribution implements CliContribution {
let filename: string = args['log-file'] as string;
try {
filename = path.resolve(filename);
try {
const stat = await fs.stat(filename);
if (stat && stat.isFile()) {
// Rename the previous log file to avoid overwriting it
const oldFilename = `${filename}.${stat.ctime.toISOString().replace(/:/g, '-')}.old`;
await fs.rename(filename, oldFilename);
}
} catch (err) {
// File does not exist, just continue to create it
}
await fs.writeFile(filename, '');
this._logFile = filename;
} catch (e) {
Expand Down
Loading