trilium/src/routes/api/backend_log.ts
Panagiotis Papadopoulos 06ebcc210e refactor(backend_log): use async readFile
using synchronous functions on the backend
is not recommended, as it is "blocking the event loop", i.e. no other tasks get executed/processed,
while the file is being read
2025-01-13 09:21:24 +01:00

22 lines
538 B
TypeScript

"use strict";
import { readFile } from "fs/promises";
import dateUtils from "../../services/date_utils.js";
import dataDir from "../../services/data_dir.js";
const { LOG_DIR } = dataDir;
async function getBackendLog() {
const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`;
try {
return await readFile(file, "utf8");
} catch (e) {
// most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
return "";
}
}
export default {
getBackendLog
};