log messages now contain script context if available

This commit is contained in:
zadam 2022-02-01 22:25:38 +01:00
parent 6833959f3b
commit 0917fc8be1
4 changed files with 13 additions and 1 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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) {

View file

@ -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}";