mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
parent
ce8470ee7c
commit
ae8f32e6b4
@ -12,7 +12,7 @@ describe('RotatingLogs', () => {
|
|||||||
try {
|
try {
|
||||||
dir = await createTempDir();
|
dir = await createTempDir();
|
||||||
await createTestLogFile(dir);
|
await createTestLogFile(dir);
|
||||||
let files: string[] = await readdir(dir);
|
let files = await readdir(dir);
|
||||||
expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy();
|
expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy();
|
||||||
expect(files.length).toBe(1);
|
expect(files.length).toBe(1);
|
||||||
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 1);
|
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 1);
|
||||||
@ -26,7 +26,7 @@ describe('RotatingLogs', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should delete inative log file after 1ms', async () => {
|
test('should delete inactive log file after 1ms', async () => {
|
||||||
let dir: string;
|
let dir: string;
|
||||||
try {
|
try {
|
||||||
dir = await createTempDir();
|
dir = await createTempDir();
|
||||||
@ -42,4 +42,21 @@ describe('RotatingLogs', () => {
|
|||||||
await remove(dir);
|
await remove(dir);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not delete the log-timestamp.txt right after its be created', async () => {
|
||||||
|
let dir: string;
|
||||||
|
try {
|
||||||
|
dir = await createTempDir();
|
||||||
|
await createTestLogFile(dir);
|
||||||
|
await msleep(100);
|
||||||
|
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 100);
|
||||||
|
await rotatingLogs.cleanActiveLogFile();
|
||||||
|
await rotatingLogs.deleteNonActiveLogFiles();
|
||||||
|
const files = await readdir(dir);
|
||||||
|
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeTruthy();
|
||||||
|
expect(files.length).toBe(1);
|
||||||
|
} finally {
|
||||||
|
await remove(dir);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,8 @@ export default class RotatingLogs {
|
|||||||
const files: Stat[] = await this.fsDriver().readDirStats(this.logFilesDir);
|
const files: Stat[] = await this.fsDriver().readDirStats(this.logFilesDir);
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (!file.path.match(/^log-[0-9]+.txt$/gi)) continue;
|
if (!file.path.match(/^log-[0-9]+.txt$/gi)) continue;
|
||||||
const ageOfTheFile: number = Date.now() - file.birthtime;
|
const timestamp: number = parseInt(file.path.match(/[0-9]+/g)[0], 10);
|
||||||
|
const ageOfTheFile: number = Date.now() - timestamp;
|
||||||
if (ageOfTheFile >= this.inactiveMaxAge) {
|
if (ageOfTheFile >= this.inactiveMaxAge) {
|
||||||
await this.fsDriver().remove(this.logFileFullpath(file.path));
|
await this.fsDriver().remove(this.logFileFullpath(file.path));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user