mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
Merge pull request #926 from pano9000:refactor_backend_log
refactor(backend_log): improve `getBackendLog`
This commit is contained in:
commit
8a7a607fcb
@ -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";
|
||||||
|
import log from "../../services/log.js";
|
||||||
|
import { t } from "i18next";
|
||||||
|
|
||||||
const { LOG_DIR } = dataDir;
|
const { LOG_DIR } = dataDir;
|
||||||
|
|
||||||
function getBackendLog() {
|
async function getBackendLog() {
|
||||||
const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`;
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,5 +193,9 @@
|
|||||||
"test_sync": {
|
"test_sync": {
|
||||||
"not-configured": "Der Synchronisations-Server-Host ist nicht konfiguriert. Bitte konfiguriere zuerst die Synchronisation.",
|
"not-configured": "Der Synchronisations-Server-Host ist nicht konfiguriert. Bitte konfiguriere zuerst die Synchronisation.",
|
||||||
"successful": "Die Server-Verbindung wurde erfolgreich hergestellt, die Synchronisation wurde gestartet."
|
"successful": "Die Server-Verbindung wurde erfolgreich hergestellt, die Synchronisation wurde gestartet."
|
||||||
|
},
|
||||||
|
"backend_log": {
|
||||||
|
"log-does-not-exist": "Die Backend-Log-Datei '{{ fileName }}' existiert (noch) nicht.",
|
||||||
|
"reading-log-failed": "Das Lesen der Backend-Log-Datei '{{ fileName }}' ist fehlgeschlagen."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,5 +246,9 @@
|
|||||||
"new-note": "New note",
|
"new-note": "New note",
|
||||||
"duplicate-note-suffix": "(dup)",
|
"duplicate-note-suffix": "(dup)",
|
||||||
"duplicate-note-title": "{{ noteTitle }} {{ duplicateNoteSuffix }}"
|
"duplicate-note-title": "{{ noteTitle }} {{ duplicateNoteSuffix }}"
|
||||||
|
},
|
||||||
|
"backend_log": {
|
||||||
|
"log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).",
|
||||||
|
"reading-log-failed": "Reading the backend log file '{{ fileName }}' failed."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user