mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
log messages now contain script context if available
This commit is contained in:
parent
6833959f3b
commit
0917fc8be1
@ -293,7 +293,7 @@ function BackendScriptApi(currentNote, apiParams) {
|
|||||||
*
|
*
|
||||||
* @param message
|
* @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.
|
* Returns root note of the calendar.
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const dataDir = require('./data_dir');
|
const dataDir = require('./data_dir');
|
||||||
|
const cls = require('./cls');
|
||||||
|
|
||||||
if (!fs.existsSync(dataDir.LOG_DIR)) {
|
if (!fs.existsSync(dataDir.LOG_DIR)) {
|
||||||
fs.mkdirSync(dataDir.LOG_DIR, 0o700);
|
fs.mkdirSync(dataDir.LOG_DIR, 0o700);
|
||||||
@ -49,6 +50,12 @@ function checkDate(millisSinceMidnight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function log(str) {
|
function log(str) {
|
||||||
|
const bundleNoteId = cls.get("bundleNoteId");
|
||||||
|
|
||||||
|
if (bundleNoteId) {
|
||||||
|
str = `[Script ${bundleNoteId}] ${str}`;
|
||||||
|
}
|
||||||
|
|
||||||
let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
|
let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
|
||||||
|
|
||||||
millisSinceMidnight = checkDate(millisSinceMidnight);
|
millisSinceMidnight = checkDate(millisSinceMidnight);
|
||||||
|
@ -738,6 +738,8 @@ function eraseBranches(branchIdsToErase) {
|
|||||||
sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase);
|
sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase);
|
||||||
|
|
||||||
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'branches' AND entityId 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) {
|
function eraseAttributes(attributeIdsToErase) {
|
||||||
@ -748,6 +750,8 @@ function eraseAttributes(attributeIdsToErase) {
|
|||||||
sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase);
|
sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase);
|
||||||
|
|
||||||
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'attributes' AND entityId 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) {
|
function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
|
||||||
|
@ -33,6 +33,7 @@ function executeBundle(bundle, apiParams = {}) {
|
|||||||
const originalComponentId = cls.get('componentId');
|
const originalComponentId = cls.get('componentId');
|
||||||
|
|
||||||
cls.set('componentId', 'script');
|
cls.set('componentId', 'script');
|
||||||
|
cls.set('bundleNoteId', bundle.note.noteId);
|
||||||
|
|
||||||
// last \r\n is necessary if script contains line comment on its last line
|
// last \r\n is necessary if script contains line comment on its last line
|
||||||
const script = "function() {\r\n" + bundle.script + "\r\n}";
|
const script = "function() {\r\n" + bundle.script + "\r\n}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user