2019-12-05 21:25:36 +01:00
|
|
|
"use strict";
|
|
|
|
|
2025-01-11 00:54:10 +01:00
|
|
|
import { readFile } from "fs/promises";
|
2025-01-11 01:06:13 +01:00
|
|
|
import { join } from "path";
|
2024-07-18 21:35:17 +03:00
|
|
|
import dateUtils from "../../services/date_utils.js";
|
|
|
|
import dataDir from "../../services/data_dir.js";
|
2025-01-11 01:14:16 +01:00
|
|
|
import log from "../../services/log.js";
|
2025-01-11 13:41:32 +01:00
|
|
|
import { t } from "i18next";
|
2025-01-11 01:14:16 +01:00
|
|
|
|
2024-04-05 20:28:19 +03:00
|
|
|
const { LOG_DIR } = dataDir;
|
2019-12-05 21:25:36 +01:00
|
|
|
|
2025-01-11 00:54:10 +01:00
|
|
|
async function getBackendLog() {
|
2025-01-11 01:45:53 +01:00
|
|
|
const fileName = `trilium-${dateUtils.localNowDate()}.log`
|
2021-05-25 21:03:00 +02:00
|
|
|
try {
|
2025-01-11 01:45:53 +01:00
|
|
|
const file = join(LOG_DIR, fileName);
|
2025-01-11 00:54:10 +01:00
|
|
|
return await readFile(file, "utf8");
|
2025-01-09 18:07:02 +02:00
|
|
|
} catch (e) {
|
2025-01-11 13:30:39 +01:00
|
|
|
const isErrorInstance = e instanceof Error;
|
2025-01-11 01:14:16 +01:00
|
|
|
|
2021-05-25 21:03:00 +02:00
|
|
|
// most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
|
2025-01-11 13:30:39 +01:00
|
|
|
if (isErrorInstance && "code" in e && e.code === "ENOENT") {
|
|
|
|
log.error(e);
|
2025-01-11 13:41:32 +01:00
|
|
|
return t("backend_log.log-does-not-exist", { fileName });
|
2025-01-11 13:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
log.error(isErrorInstance ? e : `Reading the backend log '${fileName}' failed with an unknown error: '${e}'.`);
|
2025-01-11 13:41:32 +01:00
|
|
|
return t("backend_log.reading-log-failed", { fileName });
|
2021-05-25 21:03:00 +02:00
|
|
|
}
|
2019-12-05 21:25:36 +01:00
|
|
|
}
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2019-12-05 21:25:36 +01:00
|
|
|
getBackendLog
|
2020-06-20 12:31:38 +02:00
|
|
|
};
|