From 0917fc8be171253449219cf29c0e603ac29eb26e Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 1 Feb 2022 22:25:38 +0100 Subject: [PATCH] log messages now contain script context if available --- src/services/backend_script_api.js | 2 +- src/services/log.js | 7 +++++++ src/services/notes.js | 4 ++++ src/services/script.js | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 89f90a7d2..757c067bb 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 4f2999443..0fcd98122 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 e0849f3a0..5b330efd6 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 1079fe5a1..74b404b0b 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}";