Skip to content

Build your personal knowledge base with Trilium Notes

log messages now contain script context if available

zadam0917fc8be171
diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js
index 89f90a7d28..757c067bbb 100644
--- a/src/services/backend_script_api.js
+++ b/src/services/backend_script_api.js
@@ -293,7 +293,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @param message
*/
- this.log = message => log.info(`Script "${currentNote.title}" (${currentNote.noteId}): ${message}`);
+ this.log = message => log.info(message);
/**
* Returns root note of the calendar.
diff --git a/src/services/log.js b/src/services/log.js
index 4f29994434..0fcd981221 100644
--- a/src/services/log.js
+++ b/src/services/log.js
@@ -2,6 +2,7 @@
const fs = require('fs');
const dataDir = require('./data_dir');
+const cls = require('./cls');
if (!fs.existsSync(dataDir.LOG_DIR)) {
fs.mkdirSync(dataDir.LOG_DIR, 0o700);
@@ -49,6 +50,12 @@ function checkDate(millisSinceMidnight) {
}
function log(str) {
+ const bundleNoteId = cls.get("bundleNoteId");
+
+ if (bundleNoteId) {
+ str = `[Script ${bundleNoteId}] ${str}`;
+ }
+
let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
millisSinceMidnight = checkDate(millisSinceMidnight);
diff --git a/src/services/notes.js b/src/services/notes.js
index e0849f3a06..5b330efd6d 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -738,6 +738,8 @@ function eraseBranches(branchIdsToErase) {
sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase);
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'branches' AND entityId IN (???)`, branchIdsToErase));
+
+ log.info(`Erased branches: ${JSON.stringify(branchIdsToErase)}`);
}
function eraseAttributes(attributeIdsToErase) {
@@ -748,6 +750,8 @@ function eraseAttributes(attributeIdsToErase) {
sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase);
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase));
+
+ log.info(`Erased attributes: ${JSON.stringify(attributeIdsToErase)}`);
}
function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
diff --git a/src/services/script.js b/src/services/script.js
index 1079fe5a1c..74b404b0bc 100644
--- a/src/services/script.js
+++ b/src/services/script.js
@@ -33,6 +33,7 @@ function executeBundle(bundle, apiParams = {}) {
const originalComponentId = cls.get('componentId');
cls.set('componentId', 'script');
+ cls.set('bundleNoteId', bundle.note.noteId);
// last \r\n is necessary if script contains line comment on its last line
const script = "function() {\r\n" + bundle.script + "\r\n}";