Notes/src/routes/api/backend_log.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-12-05 21:25:36 +01:00
"use strict";
import { readFile } from "fs/promises";
import { join } from "path";
import dateUtils from "../../services/date_utils.js";
import dataDir from "../../services/data_dir.js";
import log from "../../services/log.js";
const { LOG_DIR } = dataDir;
2019-12-05 21:25:36 +01:00
async function getBackendLog() {
const fileName = `trilium-${dateUtils.localNowDate()}.log`
try {
const file = join(LOG_DIR, fileName);
return await readFile(file, "utf8");
2025-01-09 18:07:02 +02:00
} catch (e) {
const isErrorInstance = e instanceof Error;
// most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
if (isErrorInstance && "code" in e && e.code === "ENOENT") {
log.error(e);
return `The backend log file '${fileName}' does not exist (yet).`;
}
log.error(isErrorInstance ? e : `Reading the backend log '${fileName}' failed with an unknown error: '${e}'.`);
return `Reading the backend log '${fileName}' failed.`;
}
2019-12-05 21:25:36 +01:00
}
export default {
2019-12-05 21:25:36 +01:00
getBackendLog
2020-06-20 12:31:38 +02:00
};