1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Doc: Auto-update documentation

Auto-updated using release-website.sh
This commit is contained in:
Joplin Bot 2023-07-14 18:17:39 +00:00
parent 05395781cc
commit 8d3f60ed1f
2 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,56 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const shim_1 = require("./shim");
class RotatingLogs {
constructor(logFilesDir, maxFileSize = null, inactiveMaxAge = null) {
this.maxFileSize = 1024 * 1024 * 100;
this.inactiveMaxAge = 90 * 24 * 60 * 60 * 1000;
this.logFilesDir = logFilesDir;
if (maxFileSize)
this.maxFileSize = maxFileSize;
if (inactiveMaxAge)
this.inactiveMaxAge = inactiveMaxAge;
}
cleanActiveLogFile() {
return __awaiter(this, void 0, void 0, function* () {
const stats = yield this.fsDriver().stat(this.logFileFullpath());
if (stats.size >= this.maxFileSize) {
const newLogFile = this.logFileFullpath(this.getNameToNonActiveLogFile());
yield this.fsDriver().move(this.logFileFullpath(), newLogFile);
}
});
}
getNameToNonActiveLogFile() {
return `log-${Date.now()}.txt`;
}
deleteNonActiveLogFiles() {
return __awaiter(this, void 0, void 0, function* () {
const files = yield this.fsDriver().readDirStats(this.logFilesDir);
for (const file of files) {
if (!file.path.match(/^log-[0-9]+.txt$/gi))
continue;
const ageOfTheFile = Date.now() - file.birthtime;
if (ageOfTheFile >= this.inactiveMaxAge) {
yield this.fsDriver().remove(this.logFileFullpath(file.path));
}
}
});
}
logFileFullpath(fileName = 'log.txt') {
return `${this.logFilesDir}/${fileName}`;
}
fsDriver() {
return shim_1.default.fsDriver();
}
}
exports.default = RotatingLogs;
//# sourceMappingURL=RotatingLogs.js.map

View File

@ -0,0 +1,56 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = require("fs-extra");
const test_utils_1 = require("./testing/test-utils");
const RotatingLogs_1 = require("./RotatingLogs");
const createTestLogFile = (dir) => __awaiter(void 0, void 0, void 0, function* () {
yield (0, fs_extra_1.writeFile)(`${dir}/log.txt`, 'some content');
});
describe('RotatingLogs', () => {
test('should rename log.txt to log-TIMESTAMP.txt', () => __awaiter(void 0, void 0, void 0, function* () {
let dir;
try {
dir = yield (0, test_utils_1.createTempDir)();
yield createTestLogFile(dir);
let files = yield (0, fs_extra_1.readdir)(dir);
expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy();
expect(files.length).toBe(1);
const rotatingLogs = new RotatingLogs_1.default(dir, 1, 1);
yield rotatingLogs.cleanActiveLogFile();
files = yield (0, fs_extra_1.readdir)(dir);
expect(files.find(file => file.match(/^log.txt$/gi))).toBeFalsy();
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeTruthy();
expect(files.length).toBe(1);
}
finally {
yield (0, fs_extra_1.remove)(dir);
}
}));
test('should delete inative log file after 1ms', () => __awaiter(void 0, void 0, void 0, function* () {
let dir;
try {
dir = yield (0, test_utils_1.createTempDir)();
yield createTestLogFile(dir);
const rotatingLogs = new RotatingLogs_1.default(dir, 1, 1);
yield rotatingLogs.cleanActiveLogFile();
yield (0, test_utils_1.msleep)(1);
yield rotatingLogs.deleteNonActiveLogFiles();
const files = yield (0, fs_extra_1.readdir)(dir);
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeFalsy();
expect(files.length).toBe(0);
}
finally {
yield (0, fs_extra_1.remove)(dir);
}
}));
});
//# sourceMappingURL=RotatingLogs.test.js.map