|
|
|
@ -1,18 +1,30 @@
|
|
|
|
"use strict";
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
import fs from "fs";
|
|
|
|
import { readFile } from "fs/promises";
|
|
|
|
|
|
|
|
import { join } from "path";
|
|
|
|
import dateUtils from "../../services/date_utils.js";
|
|
|
|
import dateUtils from "../../services/date_utils.js";
|
|
|
|
import dataDir from "../../services/data_dir.js";
|
|
|
|
import dataDir from "../../services/data_dir.js";
|
|
|
|
const { LOG_DIR } = dataDir;
|
|
|
|
import log from "../../services/log.js";
|
|
|
|
|
|
|
|
import { t } from "i18next";
|
|
|
|
|
|
|
|
|
|
|
|
function getBackendLog() {
|
|
|
|
const { LOG_DIR } = dataDir;
|
|
|
|
const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getBackendLog() {
|
|
|
|
|
|
|
|
const fileName = `trilium-${dateUtils.localNowDate()}.log`;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return fs.readFileSync(file, "utf8");
|
|
|
|
const file = join(LOG_DIR, fileName);
|
|
|
|
|
|
|
|
return await readFile(file, "utf8");
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
const isErrorInstance = e instanceof Error;
|
|
|
|
|
|
|
|
|
|
|
|
// most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
|
|
|
|
// most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
|
|
|
|
return "";
|
|
|
|
if (isErrorInstance && "code" in e && e.code === "ENOENT") {
|
|
|
|
|
|
|
|
log.error(e);
|
|
|
|
|
|
|
|
return t("backend_log.log-does-not-exist", { fileName });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.error(isErrorInstance ? e : `Reading the backend log '${fileName}' failed with an unknown error: '${e}'.`);
|
|
|
|
|
|
|
|
return t("backend_log.reading-log-failed", { fileName });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|